Skip to content

Commit cf0f9cd

Browse files
committed
格式化表格添加没列输出
1 parent e2ac38c commit cf0f9cd

11 files changed

+284
-38
lines changed

go.mod

+5
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ require (
6464
github.com/leodido/go-urn v1.2.4 // indirect
6565
github.com/lib/pq v1.10.7 // indirect
6666
github.com/mailru/easyjson v0.7.7 // indirect
67+
github.com/makiuchi-d/gozxing v0.1.1 // indirect
68+
github.com/maruel/rs v1.1.0 // indirect
6769
github.com/mattn/go-isatty v0.0.19 // indirect
6870
github.com/mattn/go-sqlite3 v1.14.16 // indirect
6971
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
@@ -72,7 +74,9 @@ require (
7274
github.com/pierrec/lz4/v4 v4.1.17 // indirect
7375
github.com/pkg/errors v0.9.1 // indirect
7476
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
77+
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
7578
github.com/tjfoc/gmsm v1.4.1 // indirect
79+
github.com/tuotoo/qrcode v0.0.0-20220425170535-52ccc2bebf5d // indirect
7680
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
7781
github.com/ugorji/go/codec v1.2.11 // indirect
7882
go.uber.org/atomic v1.7.0 // indirect
@@ -84,4 +88,5 @@ require (
8488
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
8589
google.golang.org/protobuf v1.30.0 // indirect
8690
gopkg.in/yaml.v3 v3.0.1 // indirect
91+
rsc.io/qr v0.2.0 // indirect
8792
)

go.sum

+11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ github.com/Shopify/toxiproxy/v2 v2.5.0 h1:i4LPT+qrSlKNtQf5QliVjdP08GyAH8+BUIc9gT
1212
github.com/apache/thrift v0.17.0 h1:cMd2aj52n+8VoAtvSvLn4kDC3aZ6IAkBuqWQ2IDu7wo=
1313
github.com/apache/thrift v0.17.0/go.mod h1:OLxhMRJxomX+1I/KUw03qoV3mMz16BwaKI+d4fPBx7Q=
1414
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
15+
github.com/bits-and-blooms/bitset v1.2.1/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA=
1516
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
1617
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
1718
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
@@ -149,6 +150,10 @@ github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
149150
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
150151
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
151152
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
153+
github.com/makiuchi-d/gozxing v0.1.1 h1:xxqijhoedi+/lZlhINteGbywIrewVdVv2wl9r5O9S1I=
154+
github.com/makiuchi-d/gozxing v0.1.1/go.mod h1:eRIHbOjX7QWxLIDJoQuMLhuXg9LAuw6znsUtRkNw9DU=
155+
github.com/maruel/rs v1.1.0 h1:dh4OceAF5yD06EASOrb+DS358LI4g0B90YApSdjCP6U=
156+
github.com/maruel/rs v1.1.0/go.mod h1:vzwMjzSJJxLIXmU62qHj6O5QRn5kvCKxFrfaFCxBcUY=
152157
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
153158
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
154159
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
@@ -181,6 +186,8 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV
181186
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
182187
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
183188
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
189+
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
190+
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
184191
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
185192
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
186193
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -205,6 +212,8 @@ github.com/team-ide/goja v1.0.2 h1:AyTbZ+9JKPSAsq90YDEV7g6htbuwN/gntYQptfbAQTo=
205212
github.com/team-ide/goja v1.0.2/go.mod h1:Sd/GNJgfOpBvXEGIy2JgJden3hW+WWayjZwC8EATRTM=
206213
github.com/tjfoc/gmsm v1.4.1 h1:aMe1GlZb+0bLjn+cKTPEvvn9oUEBlJitaZiiBwsbgho=
207214
github.com/tjfoc/gmsm v1.4.1/go.mod h1:j4INPkHWMrhJb38G+J6W4Tw0AbuN8Thu3PbdVYhVcTE=
215+
github.com/tuotoo/qrcode v0.0.0-20220425170535-52ccc2bebf5d h1:4x1FeGJRB00cvxnKXnRJDT89fvG/Lzm2ecm0vlr/qDs=
216+
github.com/tuotoo/qrcode v0.0.0-20220425170535-52ccc2bebf5d/go.mod h1:uSELzeIcTceNCgzbKdJuJa0ouCqqtkyzL+6bnA3rM+M=
208217
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
209218
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
210219
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
@@ -322,3 +331,5 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
322331
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
323332
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
324333
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
334+
rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY=
335+
rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs=

metric/count.go

+1
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ func WorkersCount(countList []*Count, countTop bool) (count *Count) {
194194
}
195195

196196
type Count struct {
197+
Name string `json:"name"`
197198
StartTime int64 `json:"startTime"` // 纳秒
198199
EndTime int64 `json:"endTime"` // 纳秒
199200
Count int `json:"count"`

metric/markdown.go

+158-37
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,174 @@ func MarkdownTableByCounts(counts []*Count) (content string) {
1515
type Options struct {
1616
AddHtmlFormat bool
1717
WarnUseTime int64 // 超过该时间 出现警告 为毫秒数
18+
Columns []*TableColumn
19+
}
20+
21+
type TableColumn struct {
22+
Label string `json:"label"`
23+
GetCol func(count *Count, options *Options) (res string)
24+
}
25+
26+
var (
27+
TableColumnName = &TableColumn{
28+
Label: "名称",
29+
GetCol: func(count *Count, options *Options) (res string) {
30+
res = count.Name
31+
return
32+
},
33+
}
34+
TableColumnTime = &TableColumn{
35+
Label: "任务时间",
36+
GetCol: func(count *Count, options *Options) (res string) {
37+
if options.AddHtmlFormat {
38+
res = " %s <br>-<br> %s |"
39+
} else {
40+
res = " %s - %s |"
41+
}
42+
res = fmt.Sprintf(res,
43+
util.TimeFormat(time.UnixMilli(count.StartTime/int64(time.Millisecond)), "2006-01-02 15:04:05.000"),
44+
util.TimeFormat(time.UnixMilli(count.EndTime/int64(time.Millisecond)), "2006-01-02 15:04:05.000"),
45+
)
46+
return
47+
},
48+
}
49+
TableColumnCount = &TableColumn{
50+
Label: "总/成功/失败",
51+
GetCol: func(count *Count, options *Options) (res string) {
52+
if options.AddHtmlFormat {
53+
res = " %d <br> <font color='green'>%d</font> <br> <font color='red'>%d</font> |"
54+
} else {
55+
res = " %d / %d / %d |"
56+
}
57+
res = fmt.Sprintf(res, count.Count, count.SuccessCount, count.ErrorCount)
58+
return
59+
},
60+
}
61+
TableColumnTotalTime = &TableColumn{
62+
Label: "任务用时",
63+
GetCol: func(count *Count, options *Options) (res string) {
64+
res = ToTimeStr(count.TotalTime / 1000000)
65+
return
66+
},
67+
}
68+
TableColumnExecuteTime = &TableColumn{
69+
Label: "执行用时",
70+
GetCol: func(count *Count, options *Options) (res string) {
71+
res = ToTimeStr(count.ExecuteTime / 1000000)
72+
return
73+
},
74+
}
75+
TableColumnUseTime = &TableColumn{
76+
Label: "累计用时",
77+
GetCol: func(count *Count, options *Options) (res string) {
78+
res = ToTimeStr(count.UseTime / 1000000)
79+
return
80+
},
81+
}
82+
TableColumnTps = &TableColumn{
83+
Label: "TPS",
84+
GetCol: func(count *Count, options *Options) (res string) {
85+
res = count.Tps
86+
return
87+
},
88+
}
89+
TableColumnAvg = &TableColumn{
90+
Label: "Avg",
91+
GetCol: func(count *Count, options *Options) (res string) {
92+
res = GetTableTimeOut(count.AvgValue, count.Avg, options)
93+
return
94+
},
95+
}
96+
TableColumnMin = &TableColumn{
97+
Label: "Min",
98+
GetCol: func(count *Count, options *Options) (res string) {
99+
res = GetTableTimeOut(float64(count.MinUseTime)/float64(time.Millisecond), count.Min, options)
100+
return
101+
},
102+
}
103+
TableColumnMax = &TableColumn{
104+
Label: "Max",
105+
GetCol: func(count *Count, options *Options) (res string) {
106+
res = GetTableTimeOut(float64(count.MaxUseTime)/float64(time.Millisecond), count.Max, options)
107+
return
108+
},
109+
}
110+
TableColumnT50 = &TableColumn{
111+
Label: "T50",
112+
GetCol: func(count *Count, options *Options) (res string) {
113+
res = GetTableTimeOut(util.StringToFloat64(count.T50), count.T50, options)
114+
return
115+
},
116+
}
117+
TableColumnT80 = &TableColumn{
118+
Label: "T80",
119+
GetCol: func(count *Count, options *Options) (res string) {
120+
res = GetTableTimeOut(util.StringToFloat64(count.T80), count.T80, options)
121+
return
122+
},
123+
}
124+
TableColumnT90 = &TableColumn{
125+
Label: "T90",
126+
GetCol: func(count *Count, options *Options) (res string) {
127+
res = GetTableTimeOut(util.StringToFloat64(count.T90), count.T90, options)
128+
return
129+
},
130+
}
131+
TableColumnT99 = &TableColumn{
132+
Label: "T99",
133+
GetCol: func(count *Count, options *Options) (res string) {
134+
res = GetTableTimeOut(util.StringToFloat64(count.T99), count.T99, options)
135+
return
136+
},
137+
}
138+
defaultColumns = []*TableColumn{TableColumnTime,
139+
TableColumnCount,
140+
TableColumnTotalTime,
141+
TableColumnTps,
142+
TableColumnAvg,
143+
TableColumnMin,
144+
TableColumnMax,
145+
TableColumnT50,
146+
TableColumnT80,
147+
TableColumnT90,
148+
TableColumnT99,
149+
}
150+
)
151+
152+
func GetTableTimeOut(v float64, s string, options *Options) string {
153+
if options.AddHtmlFormat && options.WarnUseTime > 0 && int64(v) >= options.WarnUseTime {
154+
return fmt.Sprintf("<font color='red'>%s</font>", s)
155+
}
156+
return s
18157
}
19158

20159
func MarkdownTable(counts []*Count, options *Options) (content string) {
21160
if options == nil {
22161
options = &Options{}
23162
}
24-
content += fmt.Sprintf("| 任务时间 | 总/成功/失败 | 任务用时| 执行用时 | 累计用时 |TPS |Avg |Min |Max |T50 |T80 | T90 | T99 | \n")
25-
content += fmt.Sprintf("| :------: | :------: | :------: | :------: | :------: |:------: | :------: | :------: | :------: | :------: | :------: | :------: | :------: | \n")
26-
27-
getTimeOut := func(v float64, s string) string {
28-
if options.AddHtmlFormat && options.WarnUseTime > 0 && int64(v) >= options.WarnUseTime {
29-
return fmt.Sprintf("<font color='red'>%s</font>", s)
30-
}
31-
return s
163+
columns := options.Columns
164+
if len(columns) == 0 {
165+
columns = defaultColumns
32166
}
33-
var s string
34-
for _, count := range counts {
167+
content += "|"
168+
for _, column := range columns {
169+
content += " " + column.Label + " |"
170+
}
171+
content += "\n"
172+
content += "|"
173+
for _, _ = range columns {
174+
content += " :------: |"
175+
}
176+
content += "\n"
35177

36-
content += fmt.Sprintf("|")
37-
if options.AddHtmlFormat {
38-
s = " %s <br>-<br> %s |"
39-
} else {
40-
s = " %s - %s |"
41-
}
42-
content += fmt.Sprintf(s,
43-
util.TimeFormat(time.UnixMilli(count.StartTime/int64(time.Millisecond)), "2006-01-02 15:04:05.000"),
44-
util.TimeFormat(time.UnixMilli(count.EndTime/int64(time.Millisecond)), "2006-01-02 15:04:05.000"),
45-
)
46-
if options.AddHtmlFormat {
47-
s = " %d <br> <font color='green'>%d</font> <br> <font color='red'>%d</font> |"
48-
} else {
49-
s = " %d / %d / %d |"
178+
for _, count := range counts {
179+
content += "|"
180+
for _, column := range columns {
181+
content += " " + column.GetCol(count, options) + " |"
50182
}
51-
content += fmt.Sprintf(s, count.Count, count.SuccessCount, count.ErrorCount)
52-
content += fmt.Sprintf(" %s |", ToTimeStr(count.TotalTime/1000000))
53-
content += fmt.Sprintf(" %s |", ToTimeStr(count.ExecuteTime/1000000))
54-
content += fmt.Sprintf(" %s |", ToTimeStr(count.UseTime/1000000))
55-
content += fmt.Sprintf(" %s |", count.Tps)
56-
content += fmt.Sprintf(" %s |", getTimeOut(float64(count.AvgValue), count.Avg))
57-
content += fmt.Sprintf(" %s |", getTimeOut(float64(count.MinUseTime)/float64(time.Millisecond), count.Min))
58-
content += fmt.Sprintf(" %s |", getTimeOut(float64(count.MaxUseTime)/float64(time.Millisecond), count.Max))
59-
content += fmt.Sprintf(" %s |", getTimeOut(util.StringToFloat64(count.T50), count.T50))
60-
content += fmt.Sprintf(" %s |", getTimeOut(util.StringToFloat64(count.T80), count.T80))
61-
content += fmt.Sprintf(" %s |", getTimeOut(util.StringToFloat64(count.T90), count.T90))
62-
content += fmt.Sprintf(" %s |", getTimeOut(util.StringToFloat64(count.T99), count.T99))
63-
content += fmt.Sprintf("\n")
183+
content += "\n"
64184
}
185+
65186
return
66187
}
67188

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "0.8.5"
2+
"version": "0.8.6"
33
}

qrcode/positionDetectionPattern0.png

330 Bytes
Loading

qrcode/positionDetectionPattern1.png

326 Bytes
Loading

qrcode/positionDetectionPattern2.png

1.14 KB
Loading

qrcode/positionDetectionPattern3.png

330 Bytes
Loading

qrcode/qrcode.go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package qrcode

0 commit comments

Comments
 (0)