#Is there a way to see precise CPU, and memory usage of a Go program?
16 messages · Page 1 of 1 (latest)
do you know use to use top or htop ?
yea I've used htop, but I couldn't see it in the process list
try lunching htop as root
should I also launch the binary as root or just my usual user?
your usual user
htop should work if you lunch it as the same user but I'm lazy and lunching it as root should always work
alright, ill try this very soon and report back the results, thank you.
@idle raptor Thank you! with your help i managed to find my program's memory usage
for those who may need this in the future:
i ran sudo htop, used the search feature in htop to find my program, and then i looked at the RES column, and that states memory usage in kb, which if you put into a quick converter for megabytes or gigabytes tells you exactly how much a paticular program on your system is using.
You could also use the runtime package to look at current stats about memory usage, GC pause, etc.: https://pkg.go.dev/runtime#ReadMemStats
func ReadMemStats(m *MemStats)
ReadMemStats populates m with memory allocator statistics.
The returned memory allocator statistics are up to date as of the call to ReadMemStats. This is in contrast with a heap profile, which is a snapshot as of the most recently completed garbage collection cycle.
ooh, thats very interesting: ill have a look at using that too, since my project is designed to use up very very little resources, this could be helpful too, to keep a watch on it. thank you
There is a pprof package to help you to debug https://pkg.go.dev/runtime/pprof
Types: 2
Functions: 12
Package pprof writes runtime profiling data in the format expected by the pprof visualization tool....
More documentation omitted
And net/http/pprof if you are lazy to wrap low level pprof
https://pkg.go.dev/net/http/pprof
Types: 0
Functions: 6
Package pprof serves via its HTTP server runtime profiling data in the format expected by the pprof visualization tool....
More documentation omitted