-
Notifications
You must be signed in to change notification settings - Fork 0
/
g.go
2155 lines (1737 loc) · 53 KB
/
g.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2000-2018, 达梦数据库有限公司.
* All rights reserved.
*/
package dm
import (
"fmt"
"math"
"os"
"sort"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/gotomicro/dmgo/util"
)
type ExecuteTypeEnum int
const (
Execute ExecuteTypeEnum = iota
ExecuteQuery
ExecuteUpdate
)
var idGenerator int64 = 0
func generateId() string {
return time.Now().String() + strconv.Itoa(int(atomic.AddInt64(&idGenerator, 1)))
}
func getInt64(counter *int64, reset bool) int64 {
if reset {
return atomic.SwapInt64(counter, 0)
}
return atomic.LoadInt64(counter)
}
type SqlStatValue struct {
id string
sql string
sqlHash int64
dataSource string
dataSourceId string
executeLastStartTime int64
executeBatchSizeTotal int64
executeBatchSizeMax int64
executeSuccessCount int64
executeSpanNanoTotal int64
executeSpanNanoMax int64
runningCount int64
concurrentMax int64
resultSetHoldTimeNano int64
executeAndResultSetHoldTime int64
executeNanoSpanMaxOccurTime int64
executeErrorCount int64
executeErrorLast error
executeErrorLastMessage string
executeErrorLastStackTrace string
executeErrorLastTime int64
updateCount int64
updateCountMax int64
fetchRowCount int64
fetchRowCountMax int64
inTransactionCount int64
lastSlowParameters string
clobOpenCount int64
blobOpenCount int64
readStringLength int64
readBytesLength int64
inputStreamOpenCount int64
readerOpenCount int64
histogram_0_1 int64
histogram_1_10 int64
histogram_10_100 int64
histogram_100_1000 int64
histogram_1000_10000 int64
histogram_10000_100000 int64
histogram_100000_1000000 int64
histogram_1000000_more int64
executeAndResultHoldTime_0_1 int64
executeAndResultHoldTime_1_10 int64
executeAndResultHoldTime_10_100 int64
executeAndResultHoldTime_100_1000 int64
executeAndResultHoldTime_1000_10000 int64
executeAndResultHoldTime_10000_100000 int64
executeAndResultHoldTime_100000_1000000 int64
executeAndResultHoldTime_1000000_more int64
fetchRowCount_0_1 int64
fetchRowCount_1_10 int64
fetchRowCount_10_100 int64
fetchRowCount_100_1000 int64
fetchRowCount_1000_10000 int64
fetchRowCount_10000_more int64
updateCount_0_1 int64
updateCount_1_10 int64
updateCount_10_100 int64
updateCount_100_1000 int64
updateCount_1000_10000 int64
updateCount_10000_more int64
}
func newSqlStatValue() *SqlStatValue {
ssv := new(SqlStatValue)
return ssv
}
func (ssv *SqlStatValue) getExecuteHistogram() []int64 {
return []int64{
ssv.histogram_0_1,
ssv.histogram_1_10,
ssv.histogram_10_100,
ssv.histogram_100_1000,
ssv.histogram_1000_10000,
ssv.histogram_10000_100000,
ssv.histogram_100000_1000000,
ssv.histogram_1000000_more,
}
}
func (ssv *SqlStatValue) getExecuteAndResultHoldHistogram() []int64 {
return []int64{ssv.executeAndResultHoldTime_0_1,
ssv.executeAndResultHoldTime_1_10,
ssv.executeAndResultHoldTime_10_100,
ssv.executeAndResultHoldTime_100_1000,
ssv.executeAndResultHoldTime_1000_10000,
ssv.executeAndResultHoldTime_10000_100000,
ssv.executeAndResultHoldTime_100000_1000000,
ssv.executeAndResultHoldTime_1000000_more,
}
}
func (ssv *SqlStatValue) getFetchRowHistogram() []int64 {
return []int64{ssv.fetchRowCount_0_1,
ssv.fetchRowCount_1_10,
ssv.fetchRowCount_10_100,
ssv.fetchRowCount_100_1000,
ssv.fetchRowCount_1000_10000,
ssv.fetchRowCount_10000_more,
}
}
func (ssv *SqlStatValue) getUpdateHistogram() []int64 {
return []int64{ssv.updateCount_0_1,
ssv.updateCount_1_10,
ssv.updateCount_10_100,
ssv.updateCount_100_1000,
ssv.updateCount_1000_10000,
ssv.updateCount_10000_more,
}
}
func (ssv *SqlStatValue) getExecuteCount() int64 {
return ssv.executeErrorCount + ssv.executeSuccessCount
}
func (ssv *SqlStatValue) getExecuteMillisMax() int64 {
return ssv.executeSpanNanoMax / (1000 * 1000)
}
func (ssv *SqlStatValue) getExecuteMillisTotal() int64 {
return ssv.executeSpanNanoTotal / (1000 * 1000)
}
func (ssv *SqlStatValue) getHistogramValues() []int64 {
return []int64{
ssv.histogram_0_1,
ssv.histogram_1_10,
ssv.histogram_10_100,
ssv.histogram_100_1000,
ssv.histogram_1000_10000,
ssv.histogram_10000_100000,
ssv.histogram_100000_1000000,
ssv.histogram_1000000_more,
}
}
func (ssv *SqlStatValue) getFetchRowCountHistogramValues() []int64 {
return []int64{
ssv.fetchRowCount_0_1,
ssv.fetchRowCount_1_10,
ssv.fetchRowCount_10_100,
ssv.fetchRowCount_100_1000,
ssv.fetchRowCount_1000_10000,
ssv.fetchRowCount_10000_more,
}
}
func (ssv *SqlStatValue) getUpdateCountHistogramValues() []int64 {
return []int64{
ssv.updateCount_0_1,
ssv.updateCount_1_10,
ssv.updateCount_10_100,
ssv.updateCount_100_1000,
ssv.updateCount_1000_10000,
ssv.updateCount_10000_more,
}
}
func (ssv *SqlStatValue) getExecuteAndResultHoldTimeHistogramValues() []int64 {
return []int64{
ssv.executeAndResultHoldTime_0_1,
ssv.executeAndResultHoldTime_1_10,
ssv.executeAndResultHoldTime_10_100,
ssv.executeAndResultHoldTime_100_1000,
ssv.executeAndResultHoldTime_1000_10000,
ssv.executeAndResultHoldTime_10000_100000,
ssv.executeAndResultHoldTime_100000_1000000,
ssv.executeAndResultHoldTime_1000000_more,
}
}
func (ssv *SqlStatValue) getResultSetHoldTimeMilis() int64 {
return ssv.resultSetHoldTimeNano / (1000 * 1000)
}
func (ssv *SqlStatValue) getExecuteAndResultSetHoldTimeMilis() int64 {
return ssv.executeAndResultSetHoldTime / (1000 * 1000)
}
func (ssv *SqlStatValue) getData() map[string]interface{} {
m := make(map[string]interface{})
m[idConstStr] = ssv.id
m[dataSourceConstStr] = ssv.dataSource
m["DataSourceId"] = ssv.dataSourceId
m[sqlConstStr] = ssv.sql
m[executeCountConstStr] = ssv.getExecuteCount()
m[errorCountConstStr] = ssv.executeErrorCount
m[totalTimeConstStr] = ssv.getExecuteMillisTotal()
m["LastTime"] = ssv.executeLastStartTime
m[maxTimespanConstStr] = ssv.getExecuteMillisMax()
m["LastError"] = ssv.executeErrorLast
m[effectedRowCountConstStr] = ssv.updateCount
m[fetchRowCountConstStr] = ssv.fetchRowCount
m["MaxTimespanOccurTime"] = ssv.executeNanoSpanMaxOccurTime
m["BatchSizeMax"] = ssv.executeBatchSizeMax
m["BatchSizeTotal"] = ssv.executeBatchSizeTotal
m[concurrentMaxConstStr] = ssv.concurrentMax
m[runningCountConstStr] = ssv.runningCount
if ssv.executeErrorLastMessage != "" {
m["LastErrorMessage"] = ssv.executeErrorLastMessage
m["LastErrorStackTrace"] = ssv.executeErrorLastStackTrace
m["LastErrorTime"] = ssv.executeErrorLastTime
} else {
m["LastErrorMessage"] = ""
m["LastErrorClass"] = ""
m["LastErrorStackTrace"] = ""
m["LastErrorTime"] = ""
}
m[urlConstStr] = ""
m[inTransactionCountConstStr] = ssv.inTransactionCount
m["Histogram"] = ssv.getHistogramValues()
m["LastSlowParameters"] = ssv.lastSlowParameters
m["ResultSetHoldTime"] = ssv.getResultSetHoldTimeMilis()
m["ExecuteAndResultSetHoldTime"] = ssv.getExecuteAndResultSetHoldTimeMilis()
m[fetchRowCountConstStr] = ssv.getFetchRowCountHistogramValues()
m[effectedRowCountHistogramConstStr] = ssv.getUpdateCountHistogramValues()
m[executeAndResultHoldTimeHistogramConstStr] = ssv.getExecuteAndResultHoldTimeHistogramValues()
m["EffectedRowCountMax"] = ssv.updateCountMax
m["FetchRowCountMax"] = ssv.fetchRowCountMax
m[clobOpenCountConstStr] = ssv.clobOpenCount
m[blobOpenCountConstStr] = ssv.blobOpenCount
m["ReadStringLength"] = ssv.readStringLength
m["ReadBytesLength"] = ssv.readBytesLength
m["InputStreamOpenCount"] = ssv.inputStreamOpenCount
m["ReaderOpenCount"] = ssv.readerOpenCount
m["HASH"] = ssv.sqlHash
m[executeHoldTimeHistogramConstStr] = ssv.getExecuteHistogram()
return m
}
type sqlStat struct {
Sql string
SqlHash int64
Id string
ExecuteLastStartTime int64
ExecuteBatchSizeTotal int64
ExecuteBatchSizeMax int64
ExecuteSuccessCount int64
ExecuteSpanNanoTotal int64
ExecuteSpanNanoMax int64
RunningCount int64
ConcurrentMax int64
ResultSetHoldTimeNano int64
ExecuteAndResultSetHoldTime int64
DataSource string
File string
ExecuteNanoSpanMaxOccurTime int64
ExecuteErrorCount int64
ExecuteErrorLast error
ExecuteErrorLastTime int64
UpdateCount int64
UpdateCountMax int64
FetchRowCount int64
FetchRowCountMax int64
InTransactionCount int64
LastSlowParameters string
Removed int64
ClobOpenCount int64
BlobOpenCount int64
ReadStringLength int64
ReadBytesLength int64
InputStreamOpenCount int64
ReaderOpenCount int64
Histogram_0_1 int64
Histogram_1_10 int64
Histogram_10_100 int64
Histogram_100_1000 int64
Histogram_1000_10000 int64
Histogram_10000_100000 int64
Histogram_100000_1000000 int64
Histogram_1000000_more int64
ExecuteAndResultHoldTime_0_1 int64
ExecuteAndResultHoldTime_1_10 int64
ExecuteAndResultHoldTime_10_100 int64
ExecuteAndResultHoldTime_100_1000 int64
ExecuteAndResultHoldTime_1000_10000 int64
ExecuteAndResultHoldTime_10000_100000 int64
ExecuteAndResultHoldTime_100000_1000000 int64
ExecuteAndResultHoldTime_1000000_more int64
FetchRowCount_0_1 int64
FetchRowCount_1_10 int64
FetchRowCount_10_100 int64
FetchRowCount_100_1000 int64
FetchRowCount_1000_10000 int64
FetchRowCount_10000_more int64
UpdateCount_0_1 int64
UpdateCount_1_10 int64
UpdateCount_10_100 int64
UpdateCount_100_1000 int64
UpdateCount_1000_10000 int64
UpdateCount_10000_more int64
DataSourceId string
}
func NewSqlStat(sql string) *sqlStat {
s := new(sqlStat)
s.Sql = sql
s.Id = "SQL" + generateId()
return s
}
func (s *sqlStat) reset() {
s.ExecuteLastStartTime = 0
s.ExecuteBatchSizeTotal = 0
s.ExecuteBatchSizeMax = 0
s.ExecuteSuccessCount = 0
s.ExecuteSpanNanoTotal = 0
s.ExecuteSpanNanoMax = 0
s.ExecuteNanoSpanMaxOccurTime = 0
s.ConcurrentMax = 0
s.ExecuteErrorCount = 0
s.ExecuteErrorLast = nil
s.ExecuteErrorLastTime = 0
s.UpdateCount = 0
s.UpdateCountMax = 0
s.FetchRowCount = 0
s.FetchRowCountMax = 0
s.Histogram_0_1 = 0
s.Histogram_1_10 = 0
s.Histogram_10_100 = 0
s.Histogram_100_1000 = 0
s.Histogram_1000_10000 = 0
s.Histogram_10000_100000 = 0
s.Histogram_100000_1000000 = 0
s.Histogram_1000000_more = 0
s.LastSlowParameters = ""
s.InTransactionCount = 0
s.ResultSetHoldTimeNano = 0
s.ExecuteAndResultSetHoldTime = 0
s.FetchRowCount_0_1 = 0
s.FetchRowCount_1_10 = 0
s.FetchRowCount_10_100 = 0
s.FetchRowCount_100_1000 = 0
s.FetchRowCount_1000_10000 = 0
s.FetchRowCount_10000_more = 0
s.UpdateCount_0_1 = 0
s.UpdateCount_1_10 = 0
s.UpdateCount_10_100 = 0
s.UpdateCount_100_1000 = 0
s.UpdateCount_1000_10000 = 0
s.UpdateCount_10000_more = 0
s.ExecuteAndResultHoldTime_0_1 = 0
s.ExecuteAndResultHoldTime_1_10 = 0
s.ExecuteAndResultHoldTime_10_100 = 0
s.ExecuteAndResultHoldTime_100_1000 = 0
s.ExecuteAndResultHoldTime_1000_10000 = 0
s.ExecuteAndResultHoldTime_10000_100000 = 0
s.ExecuteAndResultHoldTime_100000_1000000 = 0
s.ExecuteAndResultHoldTime_1000000_more = 0
s.BlobOpenCount = 0
s.ClobOpenCount = 0
s.ReadStringLength = 0
s.ReadBytesLength = 0
s.InputStreamOpenCount = 0
s.ReaderOpenCount = 0
}
func (s *sqlStat) getValueAndReset() *SqlStatValue {
return s.getValue(true)
}
func (s *sqlStat) getValue(reset bool) *SqlStatValue {
ssv := newSqlStatValue()
ssv.dataSource = s.DataSource
ssv.dataSourceId = s.DataSourceId
ssv.sql = s.Sql
ssv.sqlHash = s.SqlHash
ssv.id = s.Id
ssv.executeLastStartTime = s.ExecuteLastStartTime
if reset {
s.ExecuteLastStartTime = 0
}
ssv.executeBatchSizeTotal = getInt64(&s.ExecuteBatchSizeTotal, reset)
ssv.executeBatchSizeMax = getInt64(&s.ExecuteBatchSizeMax, reset)
ssv.executeSuccessCount = getInt64(&s.ExecuteSuccessCount, reset)
ssv.executeSpanNanoTotal = getInt64(&s.ExecuteSpanNanoTotal, reset)
ssv.executeSpanNanoMax = getInt64(&s.ExecuteSpanNanoMax, reset)
ssv.executeNanoSpanMaxOccurTime = s.ExecuteNanoSpanMaxOccurTime
if reset {
s.ExecuteNanoSpanMaxOccurTime = 0
}
ssv.runningCount = s.RunningCount
ssv.concurrentMax = getInt64(&s.ConcurrentMax, reset)
ssv.executeErrorCount = getInt64(&s.ExecuteErrorCount, reset)
ssv.executeErrorLast = s.ExecuteErrorLast
if reset {
s.ExecuteErrorLast = nil
}
ssv.executeErrorLastTime = s.ExecuteErrorLastTime
if reset {
ssv.executeErrorLastTime = 0
}
ssv.updateCount = getInt64(&s.UpdateCount, reset)
ssv.updateCountMax = getInt64(&s.UpdateCountMax, reset)
ssv.fetchRowCount = getInt64(&s.FetchRowCount, reset)
ssv.fetchRowCountMax = getInt64(&s.FetchRowCountMax, reset)
ssv.histogram_0_1 = getInt64(&s.Histogram_0_1, reset)
ssv.histogram_1_10 = getInt64(&s.Histogram_1_10, reset)
ssv.histogram_10_100 = getInt64(&s.Histogram_10_100, reset)
ssv.histogram_100_1000 = getInt64(&s.Histogram_100_1000, reset)
ssv.histogram_1000_10000 = getInt64(&s.Histogram_1000_10000, reset)
ssv.histogram_10000_100000 = getInt64(&s.Histogram_10000_100000, reset)
ssv.histogram_100000_1000000 = getInt64(&s.Histogram_100000_1000000, reset)
ssv.histogram_1000000_more = getInt64(&s.Histogram_1000000_more, reset)
ssv.lastSlowParameters = s.LastSlowParameters
if reset {
s.LastSlowParameters = ""
}
ssv.inTransactionCount = getInt64(&s.InTransactionCount, reset)
ssv.resultSetHoldTimeNano = getInt64(&s.ResultSetHoldTimeNano, reset)
ssv.executeAndResultSetHoldTime = getInt64(&s.ExecuteAndResultSetHoldTime, reset)
ssv.fetchRowCount_0_1 = getInt64(&s.FetchRowCount_0_1, reset)
ssv.fetchRowCount_1_10 = getInt64(&s.FetchRowCount_1_10, reset)
ssv.fetchRowCount_10_100 = getInt64(&s.FetchRowCount_10_100, reset)
ssv.fetchRowCount_100_1000 = getInt64(&s.FetchRowCount_100_1000, reset)
ssv.fetchRowCount_1000_10000 = getInt64(&s.FetchRowCount_1000_10000, reset)
ssv.fetchRowCount_10000_more = getInt64(&s.FetchRowCount_10000_more, reset)
ssv.updateCount_0_1 = getInt64(&s.UpdateCount_0_1, reset)
ssv.updateCount_1_10 = getInt64(&s.UpdateCount_1_10, reset)
ssv.updateCount_10_100 = getInt64(&s.UpdateCount_10_100, reset)
ssv.updateCount_100_1000 = getInt64(&s.UpdateCount_100_1000, reset)
ssv.updateCount_1000_10000 = getInt64(&s.UpdateCount_1000_10000, reset)
ssv.updateCount_10000_more = getInt64(&s.UpdateCount_10000_more, reset)
ssv.executeAndResultHoldTime_0_1 = getInt64(&s.ExecuteAndResultHoldTime_0_1, reset)
ssv.executeAndResultHoldTime_1_10 = getInt64(&s.ExecuteAndResultHoldTime_1_10, reset)
ssv.executeAndResultHoldTime_10_100 = getInt64(&s.ExecuteAndResultHoldTime_10_100, reset)
ssv.executeAndResultHoldTime_100_1000 = getInt64(&s.ExecuteAndResultHoldTime_100_1000, reset)
ssv.executeAndResultHoldTime_1000_10000 = getInt64(&s.ExecuteAndResultHoldTime_1000_10000, reset)
ssv.executeAndResultHoldTime_10000_100000 = getInt64(&s.ExecuteAndResultHoldTime_10000_100000, reset)
ssv.executeAndResultHoldTime_100000_1000000 = getInt64(&s.ExecuteAndResultHoldTime_100000_1000000, reset)
ssv.executeAndResultHoldTime_1000000_more = getInt64(&s.ExecuteAndResultHoldTime_1000000_more, reset)
ssv.blobOpenCount = getInt64(&s.BlobOpenCount, reset)
ssv.clobOpenCount = getInt64(&s.ClobOpenCount, reset)
ssv.readStringLength = getInt64(&s.ReadStringLength, reset)
ssv.readBytesLength = getInt64(&s.ReadBytesLength, reset)
ssv.inputStreamOpenCount = getInt64(&s.InputStreamOpenCount, reset)
ssv.readerOpenCount = getInt64(&s.ReaderOpenCount, reset)
return ssv
}
func (s *sqlStat) addUpdateCount(delta int64) {
if delta > 0 {
atomic.AddInt64(&s.UpdateCount, delta)
}
for {
max := atomic.LoadInt64(&s.UpdateCountMax)
if delta <= max {
break
}
if atomic.CompareAndSwapInt64(&s.UpdateCountMax, max, delta) {
break
}
}
if delta < 1 {
atomic.AddInt64(&s.UpdateCount_0_1, 1)
} else if delta < 10 {
atomic.AddInt64(&s.UpdateCount_1_10, 1)
} else if delta < 100 {
atomic.AddInt64(&s.UpdateCount_10_100, 1)
} else if delta < 1000 {
atomic.AddInt64(&s.UpdateCount_100_1000, 1)
} else if delta < 10000 {
atomic.AddInt64(&s.UpdateCount_1000_10000, 1)
} else {
atomic.AddInt64(&s.UpdateCount_10000_more, 1)
}
}
func (s *sqlStat) incrementClobOpenCount() {
atomic.AddInt64(&s.ClobOpenCount, 1)
}
func (s *sqlStat) incrementBlobOpenCount() {
atomic.AddInt64(&s.BlobOpenCount, 1)
}
func (s *sqlStat) addStringReadLength(length int64) {
atomic.AddInt64(&s.ReadStringLength, length)
}
func (s *sqlStat) addReadBytesLength(length int64) {
atomic.AddInt64(&s.ReadBytesLength, length)
}
func (s *sqlStat) addReaderOpenCount(count int64) {
atomic.AddInt64(&s.ReaderOpenCount, count)
}
func (s *sqlStat) addInputStreamOpenCount(count int64) {
atomic.AddInt64(&s.InputStreamOpenCount, count)
}
func (s *sqlStat) addFetchRowCount(delta int64) {
atomic.AddInt64(&s.FetchRowCount, delta)
for {
max := atomic.LoadInt64(&s.FetchRowCountMax)
if delta <= max {
break
}
if atomic.CompareAndSwapInt64(&s.FetchRowCountMax, max, delta) {
break
}
}
if delta < 1 {
atomic.AddInt64(&s.FetchRowCount_0_1, 1)
} else if delta < 10 {
atomic.AddInt64(&s.FetchRowCount_1_10, 1)
} else if delta < 100 {
atomic.AddInt64(&s.FetchRowCount_10_100, 1)
} else if delta < 1000 {
atomic.AddInt64(&s.FetchRowCount_100_1000, 1)
} else if delta < 10000 {
atomic.AddInt64(&s.FetchRowCount_1000_10000, 1)
} else {
atomic.AddInt64(&s.FetchRowCount_10000_more, 1)
}
}
func (s *sqlStat) addExecuteBatchCount(batchSize int64) {
atomic.AddInt64(&s.ExecuteBatchSizeTotal, batchSize)
for {
current := atomic.LoadInt64(&s.ExecuteBatchSizeMax)
if current < batchSize {
if atomic.CompareAndSwapInt64(&s.ExecuteBatchSizeMax, current, batchSize) {
break
} else {
continue
}
} else {
break
}
}
}
func (s *sqlStat) incrementExecuteSuccessCount() {
atomic.AddInt64(&s.ExecuteSuccessCount, 1)
}
func (s *sqlStat) incrementRunningCount() {
val := atomic.AddInt64(&s.RunningCount, 1)
for {
max := atomic.LoadInt64(&s.ConcurrentMax)
if val > max {
if atomic.CompareAndSwapInt64(&s.ConcurrentMax, max, val) {
break
} else {
continue
}
} else {
break
}
}
}
func (s *sqlStat) decrementRunningCount() {
atomic.AddInt64(&s.RunningCount, -1)
}
func (s *sqlStat) addExecuteTimeAndResultHoldTimeHistogramRecord(executeType ExecuteTypeEnum, firstResultSet bool, nanoSpan int64, parameters string) {
s.addExecuteTime(nanoSpan, parameters)
if ExecuteQuery != executeType && !firstResultSet {
s.executeAndResultHoldTimeHistogramRecord(nanoSpan)
}
}
func (s *sqlStat) executeAndResultHoldTimeHistogramRecord(nanoSpan int64) {
millis := nanoSpan / 1000 / 1000
if millis < 1 {
atomic.AddInt64(&s.ExecuteAndResultHoldTime_0_1, 1)
} else if millis < 10 {
atomic.AddInt64(&s.ExecuteAndResultHoldTime_1_10, 1)
} else if millis < 100 {
atomic.AddInt64(&s.ExecuteAndResultHoldTime_10_100, 1)
} else if millis < 1000 {
atomic.AddInt64(&s.ExecuteAndResultHoldTime_100_1000, 1)
} else if millis < 10000 {
atomic.AddInt64(&s.ExecuteAndResultHoldTime_1000_10000, 1)
} else if millis < 100000 {
atomic.AddInt64(&s.ExecuteAndResultHoldTime_10000_100000, 1)
} else if millis < 1000000 {
atomic.AddInt64(&s.ExecuteAndResultHoldTime_100000_1000000, 1)
} else {
atomic.AddInt64(&s.ExecuteAndResultHoldTime_1000000_more, 1)
}
}
func (s *sqlStat) histogramRecord(nanoSpan int64) {
millis := nanoSpan / 1000 / 1000
if millis < 1 {
atomic.AddInt64(&s.Histogram_0_1, 1)
} else if millis < 10 {
atomic.AddInt64(&s.Histogram_1_10, 1)
} else if millis < 100 {
atomic.AddInt64(&s.Histogram_10_100, 1)
} else if millis < 1000 {
atomic.AddInt64(&s.Histogram_100_1000, 1)
} else if millis < 10000 {
atomic.AddInt64(&s.Histogram_1000_10000, 1)
} else if millis < 100000 {
atomic.AddInt64(&s.Histogram_10000_100000, 1)
} else if millis < 1000000 {
atomic.AddInt64(&s.Histogram_100000_1000000, 1)
} else {
atomic.AddInt64(&s.Histogram_1000000_more, 1)
}
}
func (s *sqlStat) addExecuteTime(nanoSpan int64, parameters string) {
atomic.AddInt64(&s.ExecuteSpanNanoTotal, nanoSpan)
for {
current := atomic.LoadInt64(&s.ExecuteSpanNanoMax)
if current < nanoSpan {
if atomic.CompareAndSwapInt64(&s.ExecuteSpanNanoMax, current, nanoSpan) {
s.ExecuteNanoSpanMaxOccurTime = time.Now().UnixNano()
s.LastSlowParameters = parameters
break
} else {
continue
}
} else {
break
}
}
s.histogramRecord(nanoSpan)
}
func (s *sqlStat) getExecuteMillisTotal() int64 {
return s.ExecuteSpanNanoTotal / (1000 * 1000)
}
func (s *sqlStat) getExecuteMillisMax() int64 {
return s.ExecuteSpanNanoMax / (1000 * 1000)
}
func (s *sqlStat) incrementInTransactionCount() {
atomic.AddInt64(&s.InTransactionCount, 1)
}
func (s *sqlStat) getExecuteCount() int64 {
return s.ExecuteErrorCount + s.ExecuteSuccessCount
}
func (s *sqlStat) getData() map[string]interface{} {
return s.getValue(false).getData()
}
func (s *sqlStat) getHistogramValues() []int64 {
return []int64{
s.Histogram_0_1,
s.Histogram_1_10,
s.Histogram_10_100,
s.Histogram_100_1000,
s.Histogram_1000_10000,
s.Histogram_10000_100000,
s.Histogram_100000_1000000,
s.Histogram_1000000_more,
}
}
func (s *sqlStat) getHistogramSum() int64 {
values := s.getHistogramValues()
var sum int64 = 0
for i := 0; i < len(values); i++ {
sum += values[i]
}
return sum
}
func (s *sqlStat) error(err error) {
atomic.AddInt64(&s.ExecuteErrorCount, 1)
s.ExecuteErrorLastTime = time.Now().UnixNano()
s.ExecuteErrorLast = err
}
func (s *sqlStat) getResultSetHoldTimeMilis() int64 {
return s.ResultSetHoldTimeNano / (1000 * 1000)
}
func (s *sqlStat) getExecuteAndResultSetHoldTimeMilis() int64 {
return s.ExecuteAndResultSetHoldTime / (1000 * 1000)
}
func (s *sqlStat) getFetchRowCountHistogramValues() []int64 {
return []int64{
s.FetchRowCount_0_1,
s.FetchRowCount_1_10,
s.FetchRowCount_10_100,
s.FetchRowCount_100_1000,
s.FetchRowCount_1000_10000,
s.FetchRowCount_10000_more,
}
}
func (s *sqlStat) getUpdateCountHistogramValues() []int64 {
return []int64{
s.UpdateCount_0_1,
s.UpdateCount_1_10,
s.UpdateCount_10_100,
s.UpdateCount_100_1000,
s.UpdateCount_1000_10000,
s.UpdateCount_10000_more,
}
}
func (s *sqlStat) getExecuteAndResultHoldTimeHistogramValues() []int64 {
return []int64{
s.ExecuteAndResultHoldTime_0_1,
s.ExecuteAndResultHoldTime_1_10,
s.ExecuteAndResultHoldTime_10_100,
s.ExecuteAndResultHoldTime_100_1000,
s.ExecuteAndResultHoldTime_1000_10000,
s.ExecuteAndResultHoldTime_10000_100000,
s.ExecuteAndResultHoldTime_100000_1000000,
s.ExecuteAndResultHoldTime_1000000_more,
}
}
func (s *sqlStat) getExecuteAndResultHoldTimeHistogramSum() int64 {
values := s.getExecuteAndResultHoldTimeHistogramValues()
var sum int64 = 0
for i := 0; i < len(values); i++ {
sum += values[i]
}
return sum
}
func (s *sqlStat) addResultSetHoldTimeNano(nano int64) {
atomic.AddInt64(&s.ResultSetHoldTimeNano, nano)
}
func (s *sqlStat) addResultSetHoldTimeNano2(statementExecuteNano int64, resultHoldTimeNano int64) {
atomic.AddInt64(&s.ResultSetHoldTimeNano, resultHoldTimeNano)
atomic.AddInt64(&s.ExecuteAndResultSetHoldTime, statementExecuteNano+resultHoldTimeNano)
s.executeAndResultHoldTimeHistogramRecord((statementExecuteNano + resultHoldTimeNano) / 1000 / 1000)
atomic.AddInt64(&s.UpdateCount_0_1, 1)
}
type connectionStatValue struct {
id string
url string
connCount int64
activeConnCount int64
maxActiveConnCount int64
executeCount int64
errorCount int64
stmtCount int64
activeStmtCount int64
maxActiveStmtCount int64
commitCount int64
rollbackCount int64
clobOpenCount int64
blobOpenCount int64
properties string
}
func newConnectionStatValue() *connectionStatValue {
csv := new(connectionStatValue)
return csv
}
func (csv *connectionStatValue) getData() map[string]interface{} {
m := make(map[string]interface{})
m[idConstStr] = csv.id
m[urlConstStr] = csv.url
m[connCountConstStr] = csv.connCount
m[activeConnCountConstStr] = csv.activeConnCount
m[maxActiveConnCountConstStr] = csv.maxActiveConnCount
m[stmtCountConstStr] = csv.stmtCount
m[activeStmtCountConstStr] = csv.activeStmtCount
m[maxActiveStmtCountConstStr] = csv.maxActiveStmtCount
m[executeCountConstStr] = csv.executeCount
m[errorCountConstStr] = csv.errorCount