Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

Commit 20eed03

Browse files
author
Oleg Gurov
committed
merge with master
1 parent cf7be4a commit 20eed03

File tree

6 files changed

+141
-66
lines changed

6 files changed

+141
-66
lines changed

pghrep/src/fmtutils/utils.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fmtutils
22

33
import (
4+
"bytes"
45
"strings"
56
"strconv"
67
"math"
@@ -118,4 +119,64 @@ func GetUnit(unit string) int64 {
118119
}
119120
value = intval * factor
120121
return value
122+
}
123+
124+
func RawIntFormat(v int64) string {
125+
sign := ""
126+
127+
// Min int64 can't be negated to a usable value, so it has to be special cased.
128+
if v == math.MinInt64 {
129+
return "-9,223,372,036,854,775,808"
130+
}
131+
132+
if v < 0 {
133+
sign = "-"
134+
v = 0 - v
135+
}
136+
137+
parts := []string{"", "", "", "", "", "", ""}
138+
j := len(parts) - 1
139+
140+
for v > 999 {
141+
parts[j] = strconv.FormatInt(v%1000, 10)
142+
switch len(parts[j]) {
143+
case 2:
144+
parts[j] = "0" + parts[j]
145+
case 1:
146+
parts[j] = "00" + parts[j]
147+
}
148+
v = v / 1000
149+
j--
150+
}
151+
parts[j] = strconv.Itoa(int(v))
152+
return sign + strings.Join(parts[j:], ",")
153+
}
154+
155+
func RawFloatFormat(v float64, precision int) string {
156+
buf := &bytes.Buffer{}
157+
if v < 0 {
158+
buf.Write([]byte{'-'})
159+
v = 0 - v
160+
}
161+
162+
comma := []byte{','}
163+
164+
parts := strings.Split(strconv.FormatFloat(v, 'f', precision, 64), ".")
165+
pos := 0
166+
if len(parts[0])%3 != 0 {
167+
pos += len(parts[0]) % 3
168+
buf.WriteString(parts[0][:pos])
169+
buf.Write(comma)
170+
}
171+
for ; pos < len(parts[0]); pos += 3 {
172+
buf.WriteString(parts[0][pos : pos+3])
173+
buf.Write(comma)
174+
}
175+
buf.Truncate(buf.Len() - 1)
176+
177+
if len(parts) > 1 {
178+
buf.Write([]byte{'.'})
179+
buf.WriteString(parts[1])
180+
}
181+
return buf.String()
121182
}

pghrep/src/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ func loadTemplates() *template.Template {
165165
tplFuncMap["NumFormat"] = NumFormat
166166
tplFuncMap["MsFormat"] = MsFormat
167167
tplFuncMap["DtFormat"] = DtFormat
168+
tplFuncMap["RawIntFormat"] = RawIntFormat
169+
tplFuncMap["RawFloatFormat"] = RawFloatFormat
170+
168171
templates, err = template.New("").Funcs(tplFuncMap).ParseFiles(allFiles...)
169172
if err != nil {
170173
log.Fatal("Can't load templates", err)

pghrep/src/reportutils.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,15 @@ func DtFormat(value interface{}) string {
149149
return t.String()
150150
}
151151
return val
152+
}
153+
154+
func RawIntFormat(value interface{}) string {
155+
val := pyraconv.ToInt64(value)
156+
return fmtutils.RawIntFormat(val)
157+
}
158+
159+
func RawFloatFormat(value interface{}, places interface{}) string {
160+
val := pyraconv.ToFloat64(value)
161+
pl := pyraconv.ToInt64(places)
162+
return fmtutils.RawFloatFormat(val, int(pl))
152163
}

pghrep/templates/K001.tpl

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ Calls | Total&nbsp;time | Rows | shared_blks_hit | shared_blks_read | shared_blk
1515
-------|------------|------|-----------------|------------------|---------------------|---------------------|---------------|----------------|--------------|---------------|---------------------|--------------------
1616
{{ range $i, $key := (index (index (index (index .results .hosts.master) "data") "aggregated") "_keys") }}
1717
{{- $value := (index (index (index (index $.results $.hosts.master) "data") "aggregated") $key) -}}
18-
{{- NumFormat $value.diff_calls 2 }}<br/>{{ NumFormat $value.per_sec_calls 2 }}/sec<br/>{{ NumFormat $value.per_call_calls 2 }}/call<br/>{{ NumFormat $value.ratio_calls 2 }}% |
19-
{{- MsFormat $value.diff_total_time }}<br/>{{ MsFormat $value.per_sec_total_time }}/sec<br/>{{ MsFormat $value.per_call_total_time }}/call<br/>{{ NumFormat $value.ratio_total_time 2 }}% |
20-
{{- NumFormat $value.diff_rows 2 }}<br/>{{ NumFormat $value.per_sec_rows 2 }}/sec<br/>{{ NumFormat $value.per_call_rows 2 }}/call<br/>{{ NumFormat $value.ratio_rows 2 }}% |
21-
{{- NumFormat $value.diff_shared_blks_hit 2 }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_hit 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_hit 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_hit 2 }}% |
22-
{{- NumFormat $value.diff_shared_blks_read 2 }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_read 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_read 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_read 2 }}% |
23-
{{- NumFormat $value.diff_shared_blks_dirtied 2 }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_dirtied 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_dirtied 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_dirtied 2 }}% |
24-
{{- NumFormat $value.diff_shared_blks_written 2 }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_written 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_written 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_written 2 }}% |
25-
{{- MsFormat $value.diff_blk_read_time }}<br/>{{ MsFormat $value.per_sec_blk_read_time }}/sec<br/>{{ MsFormat $value.per_call_blk_read_time }}/call<br/>{{ NumFormat $value.ratio_blk_read_time 2 }}% |
26-
{{- MsFormat $value.diff_blk_write_time }}<br/>{{ MsFormat $value.per_sec_blk_write_time }}/sec<br/>{{ MsFormat $value.per_call_blk_write_time }}/call<br/>{{ MsFormat $value.per_call_blk_write_time }}/call<br/>{{ NumFormat $value.ratio_blk_write_time 2 }}% |
18+
{{- RawIntFormat $value.diff_calls }}<br/>{{ NumFormat $value.per_sec_calls 2 }}/sec<br/>{{ NumFormat $value.per_call_calls 2 }}/call<br/>{{ NumFormat $value.ratio_calls 2 }}% |
19+
{{- RawFloatFormat $value.diff_total_time 2 }}&nbsp;ms<br/>{{ MsFormat $value.per_sec_total_time }}/sec<br/>{{ MsFormat $value.per_call_total_time }}/call<br/>{{ NumFormat $value.ratio_total_time 2 }}% |
20+
{{- RawIntFormat $value.diff_rows }}<br/>{{ NumFormat $value.per_sec_rows 2 }}/sec<br/>{{ NumFormat $value.per_call_rows 2 }}/call<br/>{{ NumFormat $value.ratio_rows 2 }}% |
21+
{{- RawIntFormat $value.diff_shared_blks_hit }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_hit 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_hit 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_hit 2 }}% |
22+
{{- RawIntFormat $value.diff_shared_blks_read }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_read 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_read 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_read 2 }}% |
23+
{{- RawIntFormat $value.diff_shared_blks_dirtied }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_dirtied 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_dirtied 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_dirtied 2 }}% |
24+
{{- RawIntFormat $value.diff_shared_blks_written }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_written 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_written 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_written 2 }}% |
25+
{{- RawFloatFormat $value.diff_blk_read_time 2 }}nbsp;ms<br/>{{ MsFormat $value.per_sec_blk_read_time }}/sec<br/>{{ MsFormat $value.per_call_blk_read_time }}/call<br/>{{ NumFormat $value.ratio_blk_read_time 2 }}% |
26+
{{- RawFloatFormat $value.diff_blk_write_time 2 }}nbsp;ms<br/>{{ MsFormat $value.per_sec_blk_write_time }}/sec<br/>{{ MsFormat $value.per_call_blk_write_time }}/call<br/>{{ MsFormat $value.per_call_blk_write_time }}/call<br/>{{ NumFormat $value.ratio_blk_write_time 2 }}% |
2727
{{- NumFormat $value.diff_kcache_reads 2 }}&nbsp;bytes<br/>{{ NumFormat $value.per_sec_kcache_reads 2 }}&nbsp;bytes/sec<br/>{{ NumFormat $value.per_call_kcache_reads 2 }}&nbsp;bytes/call<br/>{{ NumFormat $value.ratio_kcache_reads 2 }}% |
2828
{{- NumFormat $value.diff_kcache_writes 2 }}&nbsp;bytes<br/>{{ NumFormat $value.per_sec_kcache_writes 2 }}&nbsp;bytes/sec<br/>{{ NumFormat $value.per_call_kcache_writes 2 }}&nbsp;bytes/call<br/>{{ NumFormat $value.ratio_kcache_writes 2 }}% |
29-
{{- MsFormat $value.diff_kcache_user_time_ms }}<br/>{{ MsFormat $value.per_sec_kcache_user_time_ms }}/sec<br/>{{ MsFormat $value.per_call_kcache_user_time_ms }}/call<br/>{{ NumFormat $value.ratio_kcache_user_time_ms 2 }}% |
30-
{{- MsFormat $value.diff_kcache_system_time_ms }}<br/>{{ MsFormat $value.per_sec_kcache_system_time_ms }}/sec<br/>{{ MsFormat $value.per_call_kcache_system_time_ms }}/call<br/>{{ NumFormat $value.ratio_kcache_system_time_ms 2 }}%
29+
{{- RawFloatFormat $value.diff_kcache_user_time_ms 2 }}&nbsp;ms<br/>{{ MsFormat $value.per_sec_kcache_user_time_ms }}/sec<br/>{{ MsFormat $value.per_call_kcache_user_time_ms }}/call<br/>{{ NumFormat $value.ratio_kcache_user_time_ms 2 }}% |
30+
{{- RawFloatFormat $value.diff_kcache_system_time_ms 2 }}&nbsp;ms<br/>{{ MsFormat $value.per_sec_kcache_system_time_ms }}/sec<br/>{{ MsFormat $value.per_call_kcache_system_time_ms }}/call<br/>{{ NumFormat $value.ratio_kcache_system_time_ms 2 }}%
3131
{{ end }}{{/* range */}}
3232
{{ else }}{{/* if .host.master*/}}
3333
No data
@@ -47,19 +47,19 @@ Calls | Total&nbsp;time | Rows | shared_blks_hit | shared_blks_read | shared_blk
4747
-------|------------|------|-----------------|------------------|---------------------|---------------------|---------------|----------------|--------------|---------------|---------------------|--------------------
4848
{{ range $i, $key := (index (index (index (index $.results $host) "data") "aggregated") "_keys") }}
4949
{{- $value := (index (index (index (index $.results $host) "data") "aggregated") $key) -}}
50-
{{- NumFormat $value.diff_calls 2 }}<br/>{{ NumFormat $value.per_sec_calls 2 }}/sec<br/>{{ NumFormat $value.per_call_calls 2 }}/call<br/>{{ NumFormat $value.ratio_calls 2 }}% |
51-
{{- MsFormat $value.diff_total_time }}<br/>{{ MsFormat $value.per_sec_total_time }}/sec<br/>{{ MsFormat $value.per_call_total_time }}/call<br/>{{ NumFormat $value.ratio_total_time 2 }}% |
52-
{{- NumFormat $value.diff_rows 2 }}<br/>{{ NumFormat $value.per_sec_rows 2 }}/sec<br/>{{ NumFormat $value.per_call_rows 2 }}/call<br/>{{ NumFormat $value.ratio_rows 2 }}% |
53-
{{- NumFormat $value.diff_shared_blks_hit 2 }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_hit 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_hit 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_hit 2 }}% |
54-
{{- NumFormat $value.diff_shared_blks_read 2 }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_read 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_read 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_read 2 }}% |
55-
{{- NumFormat $value.diff_shared_blks_dirtied 2 }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_dirtied 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_dirtied 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_dirtied 2 }}% |
56-
{{- NumFormat $value.diff_shared_blks_written 2 }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_written 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_written 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_written 2 }}% |
57-
{{- MsFormat $value.diff_blk_read_time }}<br/>{{ MsFormat $value.per_sec_blk_read_time }}/sec<br/>{{ MsFormat $value.per_call_blk_read_time }}/call<br/>{{ NumFormat $value.ratio_blk_read_time 2 }}% |
58-
{{- MsFormat $value.diff_blk_write_time }}<br/>{{ MsFormat $value.per_sec_blk_write_time }}/sec<br/>{{ MsFormat $value.per_call_blk_write_time }}/call<br/>{{ MsFormat $value.per_call_blk_write_time }}/call<br/>{{ NumFormat $value.ratio_blk_write_time 2 }}% |
50+
{{- RawIntFormat $value.diff_calls }}<br/>{{ NumFormat $value.per_sec_calls 2 }}/sec<br/>{{ NumFormat $value.per_call_calls 2 }}/call<br/>{{ NumFormat $value.ratio_calls 2 }}% |
51+
{{- RawFloatFormat $value.diff_total_time 2 }}&nbsp;ms<br/>{{ MsFormat $value.per_sec_total_time }}/sec<br/>{{ MsFormat $value.per_call_total_time }}/call<br/>{{ NumFormat $value.ratio_total_time 2 }}% |
52+
{{- RawIntFormat $value.diff_rows }}<br/>{{ NumFormat $value.per_sec_rows 2 }}/sec<br/>{{ NumFormat $value.per_call_rows 2 }}/call<br/>{{ NumFormat $value.ratio_rows 2 }}% |
53+
{{- RawIntFormat $value.diff_shared_blks_hit }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_hit 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_hit 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_hit 2 }}% |
54+
{{- RawIntFormat $value.diff_shared_blks_read }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_read 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_read 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_read 2 }}% |
55+
{{- RawIntFormat $value.diff_shared_blks_dirtied }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_dirtied 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_dirtied 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_dirtied 2 }}% |
56+
{{- RawIntFormat $value.diff_shared_blks_written }}&nbsp;blks<br/>{{ NumFormat $value.per_sec_shared_blks_written 2 }}&nbsp;blks/sec<br/>{{ NumFormat $value.per_call_shared_blks_written 2 }}&nbsp;blks/call<br/>{{ NumFormat $value.ratio_shared_blks_written 2 }}% |
57+
{{- RawFloatFormat $value.diff_blk_read_time 2 }}nbsp;ms<br/>{{ MsFormat $value.per_sec_blk_read_time }}/sec<br/>{{ MsFormat $value.per_call_blk_read_time }}/call<br/>{{ NumFormat $value.ratio_blk_read_time 2 }}% |
58+
{{- RawFloatFormat $value.diff_blk_write_time 2 }}nbsp;ms<br/>{{ MsFormat $value.per_sec_blk_write_time }}/sec<br/>{{ MsFormat $value.per_call_blk_write_time }}/call<br/>{{ MsFormat $value.per_call_blk_write_time }}/call<br/>{{ NumFormat $value.ratio_blk_write_time 2 }}% |
5959
{{- NumFormat $value.diff_kcache_reads 2 }}&nbsp;bytes<br/>{{ NumFormat $value.per_sec_kcache_reads 2 }}&nbsp;bytes/sec<br/>{{ NumFormat $value.per_call_kcache_reads 2 }}&nbsp;bytes/call<br/>{{ NumFormat $value.ratio_kcache_reads 2 }}% |
6060
{{- NumFormat $value.diff_kcache_writes 2 }}&nbsp;bytes<br/>{{ NumFormat $value.per_sec_kcache_writes 2 }}&nbsp;bytes/sec<br/>{{ NumFormat $value.per_call_kcache_writes 2 }}&nbsp;bytes/call<br/>{{ NumFormat $value.ratio_kcache_writes 2 }}% |
61-
{{- MsFormat $value.diff_kcache_user_time_ms }}<br/>{{ MsFormat $value.per_sec_kcache_user_time_ms }}/sec<br/>{{ MsFormat $value.per_call_kcache_user_time_ms }}/call<br/>{{ NumFormat $value.ratio_kcache_user_time_ms 2 }}% |
62-
{{- MsFormat $value.diff_kcache_system_time_ms }}<br/>{{ MsFormat $value.per_sec_kcache_system_time_ms }}/sec<br/>{{ MsFormat $value.per_call_kcache_system_time_ms }}/call<br/>{{ NumFormat $value.ratio_kcache_system_time_ms 2 }}%
61+
{{- RawFloatFormat $value.diff_kcache_user_time_ms 2 }}&nbsp;ms<br/>{{ MsFormat $value.per_sec_kcache_user_time_ms }}/sec<br/>{{ MsFormat $value.per_call_kcache_user_time_ms }}/call<br/>{{ NumFormat $value.ratio_kcache_user_time_ms 2 }}% |
62+
{{- RawFloatFormat $value.diff_kcache_system_time_ms 2 }}&nbsp;ms<br/>{{ MsFormat $value.per_sec_kcache_system_time_ms }}/sec<br/>{{ MsFormat $value.per_call_kcache_system_time_ms }}/call<br/>{{ NumFormat $value.ratio_kcache_system_time_ms 2 }}%
6363
{{ end }}{{/* range */}}
6464
{{- else -}}{{/* if host data */}}
6565
No data

0 commit comments

Comments
 (0)