2

I'm profiling a c++ app on linux compiled with g++.

In the gprof output I'm getting some nontrivial usage statistics for:

global constructors keyed to _ZN4CGps14ms_OutputNamesE

Where _ZN4CGps14ms_OutputNamesE is the mangled name of a static member of one of my classes. It's an array of std::strings:

static std::string ms_OutputNames[MAXOUTPUTS];

I'm a bit surprised that this isn't being constructed once at the beginning of the app. Is there some sort of guard variable or first usage check going on? How would I go about optimising this?

Simon Elliott
  • 2,087
  • 4
  • 30
  • 39
  • There should be one call to each of `global constructors keyed to` functions. Hom many do you get? – n. m. could be an AI Jan 13 '12 at 13:14
  • @n.m: I'm calling some functions thousands of times and there's a corresponding number of "global constructors keyed to static member" messages for each element of the array accessed. – Simon Elliott Jan 13 '12 at 14:23
  • That's certainly not normal. The global constructor thing should be called before `main()`, once, not from your code but from the runtime initialization code. Try running the program under gdb, set a breakpoint to `global constructors keyed to ...` and see what happens. – n. m. could be an AI Jan 13 '12 at 22:33
  • @n.m: It runs on an arm9 based embedded system where it might be tricky debugging it. I think I probably need to put together a simpler example to try to replicate the issue and see if it behaves in a similar way on arm and intel. – Simon Elliott Jan 16 '12 at 09:19

0 Answers0