On Tue, Jan 11, 2011 at 10:54 AM, Amos Jeffries <squid3_at_treenet.co.nz> wrote:
> On 11/01/11 22:08, Kinkie wrote:
>>
>> On Tue, Jan 11, 2011 at 8:03 AM, Amos Jeffries<squid3_at_treenet.co.nz>
>> wrote:
>>>
>>> The profiler aufs assertions are caused by the profiler not being thread
>>> safe but attempting to account operations inside each of the AIO threads.
>>> Lack of thread safety is due to the stack the profiler maintains of what
>>> states are currently being counted.
>>>
>>> I don't believe we should be maintaining such a stack. Instead I think we
>>> should leverage the existing system stack by having the PROF_start(X)
>>> macro
>>> create a counter object in the local scope being counted. When the local
>>> scope exists for any reason the system stack object will be destructed
>>> and
>>> the destructor can accumulate the counters back into the global data.
>>
>> +1. I like this.
>>
>
> FWIW; I looked at coding it up. There is one major side effect with the
> change:
>
> It seems the current profiler is trying some fancy accounting to eliminate
> time when child-scopes were operating. But only if they had their own
> counters.
>
> The proposed change will give us high level functions displayed with much
> longer running times than before. Since the new profiler scheme will account
> child run-times in with the parent function/method. However these will be
> more consistent (if not accurate) than previous outputs.
How about using thread-local storage for that, when available?
https://secure.wikimedia.org/wikipedia/en/wiki/Thread-local_storage#GCC
In other words, implementing a roll-our-own stack frame pointer-alike..
something like:
__thread statobj *current_statobj;
class statobj {
accurate_timediff_t ticks;
accurate_time_t started_at, created_at;
string funcname;
statobj * upstack;
statobj() : ticks(0), upstack(current_statobj),
created_at(get_accurate_time()) {
current_statobj=this;
start();
}
stop() {
ticks+=(get_accurate_time()-started_at);
}
start() {
started_at=get_accurate_time();
}
~statobj() {
stop();
report(funcname,ticks,get_accurate_time()-created_at); //get both
scope lifetime and runtime
current_statobj=upstack;
}
operator new() {
throw("only on stack, please");
}
}
-- /kinkieReceived on Tue Jan 11 2011 - 11:11:22 MST
This archive was generated by hypermail 2.2.0 : Tue Jan 11 2011 - 12:00:06 MST