RESOLVED FIXED 110932
[chromium] Implement TRACE_EVENT macros for sampling profiling
https://bugs.webkit.org/show_bug.cgi?id=110932
Summary [chromium] Implement TRACE_EVENT macros for sampling profiling
Kentaro Hara
Reported 2013-02-26 18:30:16 PST
We are implementing TRACE_EVENT macros for sampling profiling. It works in the following mechanism: - Chromium defines global state variables for sampling profiling. (i.e. g_trace_state0, g_trace_state1, g_trace_state2 in trace_event.h) - WebKit gets the addresses of the global state variables at the initialization step. (i.e. EventTracer::initialize()) - WebKit updates the global states by using TRACE_EVENT_SAMPLING_STATE() macros every time WebKit changes its state. (e.g. DOM attribute getters/setters/methods) - A sampling thread running in Chrome reads the global states periodically and visualizes the profiling results into about://tracing. In this bug, we implement (1) a WebKit API to get the addresses of the global states and (2) the TRACE_EVENT_SAMPLING_STATE() macro.
Attachments
Patch (12.19 KB, patch)
2013-02-26 18:33 PST, Kentaro Hara
no flags
Patch (12.20 KB, patch)
2013-02-26 19:35 PST, Kentaro Hara
no flags
Patch (11.66 KB, patch)
2013-02-26 19:36 PST, Kentaro Hara
no flags
fixed builds (11.59 KB, patch)
2013-02-27 08:46 PST, Kentaro Hara
no flags
Kentaro Hara
Comment 1 2013-02-26 18:33:59 PST
Kentaro Hara
Comment 2 2013-02-26 18:34:47 PST
The patch depends on the Chromium patch: https://codereview.chromium.org/12316146 Early comments are appreciated:)
Scott Graham
Comment 3 2013-02-26 19:32:01 PST
Comment on attachment 190410 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=190410&action=review > Source/WebCore/platform/chromium/TraceEvent.h:559 > + *WebCore::traceSamplingState##threadBucket = reinterpret_cast<TraceEventAPIAtomicWord>(name); \ the sampling thread expects the string to be of the form "category\0name". if you don't think we need a category, perhaps this macro could be changed to ... reinterpret_cast<TraceEventAPIAtomicWord>("WebKit\0" name); \ ?
Kentaro Hara
Comment 4 2013-02-26 19:35:13 PST
Kentaro Hara
Comment 5 2013-02-26 19:35:39 PST
(In reply to comment #3) > the sampling thread expects the string to be of the form "category\0name". if you don't think we need a category, perhaps this macro could be changed to > > ... reinterpret_cast<TraceEventAPIAtomicWord>("WebKit\0" name); \ Done!
Kentaro Hara
Comment 6 2013-02-26 19:36:53 PST
Kentaro Hara
Comment 7 2013-02-27 08:37:31 PST
Comment on attachment 190424 [details] Patch Setting r?
WebKit Review Bot
Comment 8 2013-02-27 08:38:46 PST
Please wait for approval from abarth@webkit.org, dglazkov@chromium.org, fishd@chromium.org, jamesr@chromium.org or tkent@chromium.org before submitting, as this patch contains changes to the Chromium public API. See also https://trac.webkit.org/wiki/ChromiumWebKitAPI.
Build Bot
Comment 9 2013-02-27 08:42:13 PST
kov's GTK+ EWS bot
Comment 10 2013-02-27 08:42:18 PST
Kentaro Hara
Comment 11 2013-02-27 08:46:42 PST
Created attachment 190532 [details] fixed builds
Kentaro Hara
Comment 12 2013-02-27 10:51:13 PST
nduca, scottmg: informal review please?
Scott Graham
Comment 13 2013-03-04 15:40:03 PST
(In reply to comment #12) > nduca, scottmg: informal review please? lgtm. I like the TRACE_EVENT_SAMPLING_STATE0 style over the change I made in Chromium. We should change it there (rather than the confusing passing of an argument that must be a literal).
Kentaro Hara
Comment 14 2013-03-04 15:43:20 PST
Thanks scott! abarth: r?
Adam Barth
Comment 15 2013-03-04 17:02:14 PST
Comment on attachment 190532 [details] fixed builds View in context: https://bugs.webkit.org/attachment.cgi?id=190532&action=review r=me, assuming you're confident in the answer to my question below. > Source/WebCore/platform/chromium/TraceEvent.h:559 > + *WebCore::traceSamplingState##threadBucket = reinterpret_cast<TraceEventAPIAtomicWord>("WebKit\0" name); \ Is this operation really atomic? You're using names like "AtomicWord" in the names of the types, but I don't know enough about the subtle threading issues to know if what you're doing here is sufficient.
Kentaro Hara
Comment 16 2013-03-04 17:14:31 PST
(In reply to comment #15) > (From update of attachment 190532 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=190532&action=review > > r=me, assuming you're confident in the answer to my question below. > > > Source/WebCore/platform/chromium/TraceEvent.h:559 > > + *WebCore::traceSamplingState##threadBucket = reinterpret_cast<TraceEventAPIAtomicWord>("WebKit\0" name); \ > > Is this operation really atomic? You're using names like "AtomicWord" in the names of the types, but I don't know enough about the subtle threading issues to know if what you're doing here is sufficient. No, I'm not confident. In practice, this operation does not need to be atomic. Before talking about threading conflict, we've not yet taken care of the issue that we cannot distinguish which main thread or worker thread called the TRACE_EVENT_SAMPLING_STATE0() macro. We are thinking it's OK for the time being because we are just interested in profiling the main thread. Maybe can we rename TraceEventAPIAtomicWord to TraceEventAPIWord ?
Scott Graham
Comment 17 2013-03-04 17:24:44 PST
(In reply to comment #16) > (In reply to comment #15) > > (From update of attachment 190532 [details] [details]) > > View in context: https://bugs.webkit.org/attachment.cgi?id=190532&action=review > > > > r=me, assuming you're confident in the answer to my question below. > > > > > Source/WebCore/platform/chromium/TraceEvent.h:559 > > > + *WebCore::traceSamplingState##threadBucket = reinterpret_cast<TraceEventAPIAtomicWord>("WebKit\0" name); \ > > > > Is this operation really atomic? You're using names like "AtomicWord" in the names of the types, but I don't know enough about the subtle threading issues to know if what you're doing here is sufficient. > > No, I'm not confident. In practice, this operation does not need to be atomic. Before talking about threading conflict, we've not yet taken care of the issue that we cannot distinguish which main thread or worker thread called the TRACE_EVENT_SAMPLING_STATE0() macro. We are thinking it's OK for the time being because we are just interested in profiling the main thread. > > Maybe can we rename TraceEventAPIAtomicWord to TraceEventAPIWord ? As long as "long int" isn't 8 bytes on some crazy config, "*p = v" with 32 bit sizes is OK for this code, at least on x86 and ARM. Perhaps we could add a static_assert that sizeof(TraceEventAPIAtomicWord) == 4, and #error if !(ARCH=x86 || ARCH=arm). I think the size is already checked by needing to match getTraceSamplingState. (Assuming there's not some atomics primitives we could be using instead)
Kentaro Hara
Comment 18 2013-03-04 17:31:42 PST
(In reply to comment #17) > As long as "long int" isn't 8 bytes on some crazy config, "*p = v" with 32 bit sizes is OK for this code, at least on x86 and ARM. > > Perhaps we could add a static_assert that sizeof(TraceEventAPIAtomicWord) == 4, and #error if !(ARCH=x86 || ARCH=arm). I think the size is already checked by needing to match getTraceSamplingState. Will add the assert about the size and a comment.
Kentaro Hara
Comment 19 2013-03-04 17:44:23 PST
Roger Fong
Comment 20 2013-03-04 18:23:52 PST
Hello, this appears to have broken all the mac builds. Here is the error message: Source/WebCore/platform/EventTracer.cpp:37:1: error: function 'initialize' could be declared with attribute 'noreturn' [-Werror,-Wmissing-noreturn]
Kentaro Hara
Comment 21 2013-03-04 18:44:25 PST
(In reply to comment #20) > Hello, this appears to have broken all the mac builds. > Here is the error message: > Source/WebCore/platform/EventTracer.cpp:37:1: error: function 'initialize' could be declared with attribute 'noreturn' [-Werror,-Wmissing-noreturn] Sorry, fix is coming in mins.
Kentaro Hara
Comment 22 2013-03-04 18:50:58 PST
(In reply to comment #21) > (In reply to comment #20) > > Hello, this appears to have broken all the mac builds. > > Here is the error message: > > Source/WebCore/platform/EventTracer.cpp:37:1: error: function 'initialize' could be declared with attribute 'noreturn' [-Werror,-Wmissing-noreturn] > > Sorry, fix is coming in mins. Fixed in r144707.
Darin Adler
Comment 23 2013-03-04 19:37:29 PST
Mac builds are still broken. Removing that bogus "return" won't fix the Mac builds. The issue is that the assertion is always false. That's because sizeof(long int) is not 4 on 64-bit platforms. I suggest using COMPILE_ASSERT instead of ASSERT for compile time assertions. And I suggest int rather than long int if you are looking for a type that is 4 bytes even on 64-bit platforms.
Kentaro Hara
Comment 24 2013-03-04 19:46:24 PST
Removed the ASSERT in r144711. Scott: sizeof(long int) is 8 bytes, so atomicity is not guaranteed. Given that we don't care about atomicity, maybe shall we rename TraceEventAPIAtomicWord to TraceEventAPIWord ?
Note You need to log in before you can comment on or make changes to this bug.