-4

I have a compiled Go program, which sometimes occupies large amount of memory. Unfortunately, I don't have its source code, so it is impossible to modify it to add a runtime/pprof server. I was wondering is there any way to invoke runtime.GC() or generate a heap dump without modifying the source code?

lz96
  • 2,816
  • 2
  • 28
  • 46
  • 1
    Consider interacting with the provider (or author) of that Go program, and give him some bug report – Basile Starynkevitch Jun 06 '18 at 05:00
  • @BasileStarynkevitch Unfortunately the source code is already lost due to power outage :( – lz96 Jun 06 '18 at 05:39
  • 2
    My hard disks keep their state on power outage. Forget this project, start a new one, life is short – Bert Verhees Jun 06 '18 at 06:14
  • 2
    For your next programming project, use some [version control](https://en.wikipedia.org/wiki/Version_control) system like [git](http://git-scm.com/) – Basile Starynkevitch Jun 06 '18 at 06:45
  • Memory pressure will cause GC to run anyway, and it generally runs pretty frequently with an active program. If you're seeing a lot of memory usage, it's either because a) the program is actually using the memory, so it can't be freed by GC, or b) the program has run GC already and freed the memory, but the OS hasn't seen the need to reclaim it. – Adrian Jun 06 '18 at 11:41

1 Answers1

1

I don't think so.

Even reacting to a signal (like SIGQUIT) would require to code it, as seen here.

With only the executable (no .a, no sources), you would only have go tool objdump.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • What about hacking by creating a user-land thread sharing the same memory/fd space running `runtime.GC()`? Is it feasible? – lz96 Jun 06 '18 at 05:38
  • Not sure (I haven't tested it). Even articles like https://medium.com/samsara-engineering/running-go-on-low-memory-devices-536e1ca2fe8f or thread like https://www.reddit.com/r/golang/comments/6zqk1v/any_recommendation_for_golang_gc_tuning_resources/ need the program sources to debug anything. – VonC Jun 06 '18 at 05:43