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 83595f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 9 additions & 12 deletions pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ import (
var (
client appinsights.TelemetryClient
version string
btoMb uint64 = 1024

// 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 +153,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 >> 20

Check failure on line 166 in pkg/telemetry/telemetry.go

View workflow job for this annotation

GitHub Actions / Lint (linux, amd64)

mnd: Magic number: 20, in <return> detected (gomnd)

Check failure on line 166 in pkg/telemetry/telemetry.go

View workflow job for this annotation

GitHub Actions / Lint (linux, arm64)

mnd: Magic number: 20, in <return> detected (gomnd)

Check failure on line 166 in pkg/telemetry/telemetry.go

View workflow job for this annotation

GitHub Actions / Lint (windows, amd64)

mnd: Magic number: 20, in <return> detected (gomnd)

Check failure on line 166 in pkg/telemetry/telemetry.go

View workflow job for this annotation

GitHub Actions / Lint (windows, arm64)

mnd: Magic number: 20, in <return> detected (gomnd)
}

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 83595f4

Please sign in to comment.