Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The idea of a tree seems... wasteful.</p> <p>What you are doing requires a simple stack.</p> <ul> <li>Log the ID/entry timestamp pair</li> <li>Execute child calls</li> <li>Modify top-of-stack entry with exit timestamp</li> </ul> <p>Also, all child calls are actually children of the same parent...</p> <p>In your position, I would simply use:</p> <ul> <li>RAII for automatic exit-timestamp logging</li> <li>A <code>deque</code>-like structure for fast record append</li> </ul> <p>The record structure would be like:</p> <pre><code>struct Record { unsigned level; unsigned id; unsigned entry; unsigned exit; }; </code></pre> <p>Then, you keep two thread-local structures:</p> <pre><code>extern thread_local unsigned CurrentLevel; extern thread_local std::deque&lt;Record&gt; CallRecords; </code></pre> <p>And finally, you implement a simple RAII class:</p> <pre><code>class CallRecorder: boost::noncopyable() { public: CallRecord(unsigned id): record(*CallRecords.insert(CallRecords.end(), Record{CurrentLevel++, id, time(), 0})) { } ~CallRecord() { record.exit = time(); --CurrentLevel; } private: Record&amp; record; }; </code></pre> <p>You could, potentially, pass down the ID of the parent to each child call, but it does not seem worth it. This is information you can reconstruct when exploiting the stream (keeping a separate stack on the side).</p> <p>I only have two notes:</p> <ul> <li>You might want to create your own implementation of <code>deque</code> to allocate bigger chunks (4K page for examples) and really optimize for append above all.</li> <li>Using RAII, we deal with both regular returns and exceptions. Only <code>abort</code> are not logged, since the program terminates. It can be detected as it leaves an incomplete trace.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload