Skip to content

Commit a577da2

Browse files
committed
Print memory usage in the log for now
1 parent 8995a39 commit a577da2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

internal/project/service.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"maps"
8+
"runtime"
89
"strings"
910
"sync"
1011

@@ -219,6 +220,7 @@ func (s *Service) OpenFile(fileName string, fileContent string, scriptKind core.
219220
}
220221
result := s.assignProjectToOpenedScriptInfo(info)
221222
s.cleanupProjectsAndScriptInfos(info, result)
223+
s.printMemoryUsage()
222224
s.printProjects()
223225
}
224226

@@ -929,3 +931,14 @@ func (s *Service) printProjects() {
929931
func (s *Service) logf(format string, args ...any) {
930932
s.Log(fmt.Sprintf(format, args...))
931933
}
934+
935+
func (s *Service) printMemoryUsage() {
936+
runtime.GC() // Force garbage collection to get accurate memory stats
937+
var memStats runtime.MemStats
938+
runtime.ReadMemStats(&memStats)
939+
940+
s.logf("Alloc: %v KB", memStats.Alloc/1024)
941+
s.logf("TotalAlloc: %v KB", memStats.TotalAlloc/1024)
942+
s.logf("Sys: %v KB", memStats.Sys/1024)
943+
s.logf("NumGC: %v", memStats.NumGC)
944+
}

0 commit comments

Comments
 (0)