-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
50 lines (43 loc) · 1.05 KB
/
utils.go
File metadata and controls
50 lines (43 loc) · 1.05 KB
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
package tinygo_logger
import (
"runtime"
)
var (
// memoryStatsHeader is the header for memory statistics output
memoryStatsHeader = []byte("Memory Stats:")
// memoryStatsAllocKey is the key for currently allocated memory in KB
memoryStatsAllocKey = []byte("\tCurrently Allocated (KB) =")
// memoryStatsTotalAllocKey is the key for cumulative allocated memory in KB
memoryStatsTotalAllocKey = []byte("\tTotal Allocated (KB) =")
)
// DebugMemory logs the current memory statistics using the provided Logger instance.
//
// Parameters:
//
// logger: The Logger instance to use for logging memory statistics.
func DebugMemory(logger Logger) {
// Check if logger is nil
if logger == nil {
return
}
// Read memory statistics
var m runtime.MemStats
runtime.ReadMemStats(&m)
// Log memory stats
logger.AddMessage(memoryStatsHeader, true)
logger.AddMessageWithUint64(
memoryStatsAllocKey,
m.Alloc/1024,
true,
true,
false,
)
logger.AddMessageWithUint64(
memoryStatsTotalAllocKey,
m.TotalAlloc/1024,
true,
true,
false,
)
logger.Debug()
}