Hi, Saifi On Tue, 30 Mar 2021, SAIFI wrote:
Gabriele thanks for sharing the detailed write up. in the spirit of 'gcc-help', can you please share pointers as to how one can profile C++ code using GCC plugins ? in your example you mention 'f1 ()'; i'd like to replace that with a instance of class 'X' created and then profile or instrument a member function. Have you explored that ? any preliminary thoughts on how does one go about doing it ? warm regards Saifi.
to be honest, I hadn't the chance to profile C++ code. I think the problem can be solved in different ways. A quick and dirty solution, you can build 'X' as a singleton and then, in the profiler function (declared as static) get the singleton instance. However, if your class need to be instanced multiple times, an idea could be to declare the profiler function as static and then pass "this" as the first parameter. Clearly in this second scenario, your function must "see" in some way the instance of the class X mentioned. These are my preliminary thoughts but I think the way you can implement this really depends on the use case. For instance, if your profiler can be executed after the function prologue, maybe it is possible to operate directly with GIMPLE and realize something like the C++11 lambda function (with the capture list). Here, unfortunately, I can't say more than this because I hadn't the chance to analyze deeper the question. However, in next few days, I will investigate on that. Thank for the question Regards, Gabriele Serra