Skip to content

Commit

Permalink
bitshift
Browse files Browse the repository at this point in the history
  • Loading branch information
matmerr committed Aug 8, 2024
1 parent 9f06932 commit d059a85
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 10 additions & 12 deletions pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ import (
var (
client appinsights.TelemetryClient
version string
btoMb uint64 = 1024
mbShift uint64 = 10

// property keys
kernelversion = "kernelversion"
allocatedmem = "allocmem"
totalallocatedmem = "totalallocmem"
sysmem = "sysmem"
goroutines = "goroutines"
kernelversion = "kernelversion"
allocatedmem = "allocmem"
sysmem = "sysmem"
goroutines = "goroutines"
)

type Telemetry interface {
Expand Down Expand Up @@ -155,18 +154,17 @@ func (t *TelemetryClient) heartbeat(ctx context.Context) {
var m runtime.MemStats
runtime.ReadMemStats(&m)
props := map[string]string{
kernelversion: kernelVersion,
allocatedmem: strconv.FormatUint(bToMb(m.Alloc), 10),
totalallocatedmem: strconv.FormatUint(bToMb(m.TotalAlloc), 10),
sysmem: strconv.FormatUint(bToMb(m.Sys), 10),
goroutines: strconv.Itoa(runtime.NumGoroutine()),
kernelversion: kernelVersion,
allocatedmem: strconv.FormatUint(bToMb(m.Alloc), 10),
sysmem: strconv.FormatUint(bToMb(m.Sys), 10),
goroutines: strconv.Itoa(runtime.NumGoroutine()),
}

t.TrackEvent("heartbeat", props)
}

func bToMb(b uint64) uint64 {
return b / btoMb / btoMb
return b >> mbShift
}

func (t *TelemetryClient) TrackEvent(name string, properties map[string]string) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/telemetry/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,7 @@ func TestTelemetryClient_StopPerf(t *testing.T) {
})
}
}

func TestBtoMB(t *testing.T) {
require.Equal(t, uint64(1), bToMb(1048576))
}

0 comments on commit d059a85

Please sign in to comment.