@@ -19,6 +19,7 @@ package metrics
1919import (
2020 "context"
2121 "log"
22+ "math"
2223 "runtime"
2324 "time"
2425
@@ -379,76 +380,76 @@ func (msp *MemStatsProvider) Start(ctx context.Context, period time.Duration) {
379380 ms := runtime.MemStats {}
380381 runtime .ReadMemStats (& ms )
381382 if msp .Alloc != nil {
382- Record (ctx , msp .Alloc .M (int64 (ms .Alloc )))
383+ Record (ctx , msp .Alloc .M (safeint64 (ms .Alloc )))
383384 }
384385 if msp .TotalAlloc != nil {
385- Record (ctx , msp .TotalAlloc .M (int64 (ms .TotalAlloc )))
386+ Record (ctx , msp .TotalAlloc .M (safeint64 (ms .TotalAlloc )))
386387 }
387388 if msp .Sys != nil {
388- Record (ctx , msp .Sys .M (int64 (ms .Sys )))
389+ Record (ctx , msp .Sys .M (safeint64 (ms .Sys )))
389390 }
390391 if msp .Lookups != nil {
391- Record (ctx , msp .Lookups .M (int64 (ms .Lookups )))
392+ Record (ctx , msp .Lookups .M (safeint64 (ms .Lookups )))
392393 }
393394 if msp .Mallocs != nil {
394- Record (ctx , msp .Mallocs .M (int64 (ms .Mallocs )))
395+ Record (ctx , msp .Mallocs .M (safeint64 (ms .Mallocs )))
395396 }
396397 if msp .Frees != nil {
397- Record (ctx , msp .Frees .M (int64 (ms .Frees )))
398+ Record (ctx , msp .Frees .M (safeint64 (ms .Frees )))
398399 }
399400 if msp .HeapAlloc != nil {
400- Record (ctx , msp .HeapAlloc .M (int64 (ms .HeapAlloc )))
401+ Record (ctx , msp .HeapAlloc .M (safeint64 (ms .HeapAlloc )))
401402 }
402403 if msp .HeapSys != nil {
403- Record (ctx , msp .HeapSys .M (int64 (ms .HeapSys )))
404+ Record (ctx , msp .HeapSys .M (safeint64 (ms .HeapSys )))
404405 }
405406 if msp .HeapIdle != nil {
406- Record (ctx , msp .HeapIdle .M (int64 (ms .HeapIdle )))
407+ Record (ctx , msp .HeapIdle .M (safeint64 (ms .HeapIdle )))
407408 }
408409 if msp .HeapInuse != nil {
409- Record (ctx , msp .HeapInuse .M (int64 (ms .HeapInuse )))
410+ Record (ctx , msp .HeapInuse .M (safeint64 (ms .HeapInuse )))
410411 }
411412 if msp .HeapReleased != nil {
412- Record (ctx , msp .HeapReleased .M (int64 (ms .HeapReleased )))
413+ Record (ctx , msp .HeapReleased .M (safeint64 (ms .HeapReleased )))
413414 }
414415 if msp .HeapObjects != nil {
415- Record (ctx , msp .HeapObjects .M (int64 (ms .HeapObjects )))
416+ Record (ctx , msp .HeapObjects .M (safeint64 (ms .HeapObjects )))
416417 }
417418 if msp .StackInuse != nil {
418- Record (ctx , msp .StackInuse .M (int64 (ms .StackInuse )))
419+ Record (ctx , msp .StackInuse .M (safeint64 (ms .StackInuse )))
419420 }
420421 if msp .StackSys != nil {
421- Record (ctx , msp .StackSys .M (int64 (ms .StackSys )))
422+ Record (ctx , msp .StackSys .M (safeint64 (ms .StackSys )))
422423 }
423424 if msp .MSpanInuse != nil {
424- Record (ctx , msp .MSpanInuse .M (int64 (ms .MSpanInuse )))
425+ Record (ctx , msp .MSpanInuse .M (safeint64 (ms .MSpanInuse )))
425426 }
426427 if msp .MSpanSys != nil {
427- Record (ctx , msp .MSpanSys .M (int64 (ms .MSpanSys )))
428+ Record (ctx , msp .MSpanSys .M (safeint64 (ms .MSpanSys )))
428429 }
429430 if msp .MCacheInuse != nil {
430- Record (ctx , msp .MCacheInuse .M (int64 (ms .MCacheInuse )))
431+ Record (ctx , msp .MCacheInuse .M (safeint64 (ms .MCacheInuse )))
431432 }
432433 if msp .MCacheSys != nil {
433- Record (ctx , msp .MCacheSys .M (int64 (ms .MCacheSys )))
434+ Record (ctx , msp .MCacheSys .M (safeint64 (ms .MCacheSys )))
434435 }
435436 if msp .BuckHashSys != nil {
436- Record (ctx , msp .BuckHashSys .M (int64 (ms .BuckHashSys )))
437+ Record (ctx , msp .BuckHashSys .M (safeint64 (ms .BuckHashSys )))
437438 }
438439 if msp .GCSys != nil {
439- Record (ctx , msp .GCSys .M (int64 (ms .GCSys )))
440+ Record (ctx , msp .GCSys .M (safeint64 (ms .GCSys )))
440441 }
441442 if msp .OtherSys != nil {
442- Record (ctx , msp .OtherSys .M (int64 (ms .OtherSys )))
443+ Record (ctx , msp .OtherSys .M (safeint64 (ms .OtherSys )))
443444 }
444445 if msp .NextGC != nil {
445- Record (ctx , msp .NextGC .M (int64 (ms .NextGC )))
446+ Record (ctx , msp .NextGC .M (safeint64 (ms .NextGC )))
446447 }
447448 if msp .LastGC != nil {
448- Record (ctx , msp .LastGC .M (int64 (ms .LastGC )))
449+ Record (ctx , msp .LastGC .M (safeint64 (ms .LastGC )))
449450 }
450451 if msp .PauseTotalNs != nil {
451- Record (ctx , msp .PauseTotalNs .M (int64 (ms .PauseTotalNs )))
452+ Record (ctx , msp .PauseTotalNs .M (safeint64 (ms .PauseTotalNs )))
452453 }
453454 if msp .NumGC != nil {
454455 Record (ctx , msp .NumGC .M (int64 (ms .NumGC )))
@@ -549,3 +550,11 @@ func (msp *MemStatsProvider) DefaultViews() (views []*view.View) {
549550 }
550551 return
551552}
553+
554+ func safeint64 (val uint64 ) int64 {
555+ if val > math .MaxInt64 {
556+ return math .MaxInt64
557+ }
558+
559+ return int64 (val )
560+ }
0 commit comments