GoLang-是否有一种方法可以描述使用反射的代码的内存使用情况?
I am using gocraft/web
in a project and am trying to debug some high memory usage. gocraft/web
uses reflection to call handlers. I've set up the net/http/pprof
profiler which works very well, but the largest block of memory, and the one that I am iterested in, only shows reflect.Value.call
as the function. That's not very helpful.
How can I get around the fact that gocraft/web
is using reflection and dig deeper into the memory profile?
Here's an example of the profile output I am seeing:
我在项目中使用 我该如何解决 这是我看到的配置文件输出示例: p>
p>
div> gocraft / web code>并尝试调试一些大内存 用法。
gocraft / web code>使用反射来调用处理程序。 我已经设置了
net / http / pprof code>探查器,该探查器工作得很好,但是最大的内存块以及我最喜欢的那个内存块仅显示
reflect.Value.call code>作为功能。 b>
gocraft / web code>正在使用反射并深入挖掘内存配置文件的事实? p> \ n
Thanks to @thwd for filing http://golang.org/issue/11786 about this. This is a display issue in pprof. All the data is there, just being hidden. You can get the data you need by invoking pprof with the -runtime
flag. It will also show data you don't need, but it should serve as a decent workaround until Go 1.6 is out.
The short answer is that you can't directly. reflect.Value.call
calls reflect.call
which forwards to runtime.reflectcall
which is an assembly routine implemented in the runtime, for example for amd64, here. This circumvents what the profiler can see.
Your best bet is to invoke your handlers without reflection and test them like that individually.
Also, enabling the profiler to follow reflective calls would arguably be an acceptable change to propose for the next Go iteration. You should follow the change proposal process for this.
Edit: issue created.