Chromium Code Reviews| Index: native_client_sdk/src/libraries/xray/xray.c |
| diff --git a/native_client_sdk/src/libraries/xray/xray.c b/native_client_sdk/src/libraries/xray/xray.c |
| index 5cfa42a275abaf70803b2133eeb852e408068ef2..e3ee84600b260af8954cc2c0d062eaf8e6c86489 100644 |
| --- a/native_client_sdk/src/libraries/xray/xray.c |
| +++ b/native_client_sdk/src/libraries/xray/xray.c |
| @@ -40,7 +40,6 @@ FORCE_INLINE uint64_t GTOD() { |
| #define GTSC(_x) _x = GTOD(); |
| #endif |
| - |
| /* Use a TLS variable for cheap thread uid. */ |
| __thread struct XRayTraceCapture* g_xray_capture = NULL; |
| @@ -93,6 +92,9 @@ struct XRayTraceCapture { |
| uint32_t guard3; |
| struct XRayTraceBufferEntry* buffer; |
| struct XRayTraceFrame frame; |
| + |
| + struct XrayTimestampPair start_time; |
| + bool start_time_initialized; |
|
nfullagar1
2013/07/17 00:53:19
wrap these as well with XRAY_DISABLE_BROWSER_INTEG
grosse
2013/07/17 19:37:56
Done.
|
| } XRAY_ALIGN64; |
| @@ -100,10 +102,8 @@ struct XRayTraceCapture { |
| extern "C" { |
| #endif |
| -XRAY_NO_INSTRUMENT void __cyg_profile_func_enter(void* this_fn, |
| - void* call_site); |
| -XRAY_NO_INSTRUMENT void __cyg_profile_func_exit(void* this_fn, |
| - void* call_site); |
| +XRAY_NO_INSTRUMENT void __pnacl_profile_func_enter(const char* fname); |
| +XRAY_NO_INSTRUMENT void __pnacl_profile_func_exit(const char* fname); |
|
nfullagar1
2013/07/17 00:53:19
above: need to add back __cyg_profile versions for
grosse
2013/07/17 19:37:56
Done.
|
| XRAY_NO_INSTRUMENT void __xray_profile_append_annotation( |
| struct XRayTraceCapture* capture, |
| struct XRayTraceStackEntry* se, |
| @@ -113,7 +113,6 @@ XRAY_NO_INSTRUMENT void __xray_profile_append_annotation( |
| } |
| #endif |
| - |
| /* Asserts that the guard values haven't changed. */ |
| void XRayCheckGuards(struct XRayTraceCapture* capture) { |
| assert(capture->guard0 == XRAY_GUARD_VALUE_0x12345678); |
| @@ -303,7 +302,53 @@ void XRayFree(void* data) { |
| } |
| +#if defined(__pnacl__) |
| +/* Main profile capture function that is called at the start */ |
| +/* of every instrumented function. This function is implicitly */ |
| +/* called when code is compilied with the -finstrument-functions option */ |
|
nfullagar1
2013/07/17 00:53:19
comment above should include compiler options for
|
| +void __pnacl_profile_func_enter(const char* fname) { |
|
nfullagar1
2013/07/17 00:53:19
fname -> this_fn, and I think you could avoid a lo
|
| + struct XRayTraceCapture* capture = g_xray_capture; |
| + if (capture && capture->recording) { |
| + uint32_t depth = capture->stack_depth; |
| + if (depth < capture->max_stack_depth) { |
| + struct XRayTraceStackEntry* se = &capture->stack[depth]; |
| + uint32_t addr = (uint32_t)fname; |
| + se->depth_addr = XRAY_PACK_DEPTH_ADDR(depth, addr); |
| + se->dest = capture->buffer_index; |
| + se->annotation_index = 0; |
| + GTSC(se->tsc); |
| + capture->buffer_index = |
| + XRayTraceIncrementIndexInline(capture, capture->buffer_index); |
| + } |
| + ++capture->stack_depth; |
| + } |
| +} |
| + |
| +/* Main profile capture function that is called at the exit of */ |
| +/* every instrumented function. This function is implicity called */ |
| +/* when the code is compiled with the -finstrument-functions option */ |
| +void __pnacl_profile_func_exit(const char* fname) { |
| + struct XRayTraceCapture* capture = g_xray_capture; |
| + if (capture && capture->recording) { |
| + --capture->stack_depth; |
| + if (capture->stack_depth < capture->max_stack_depth) { |
| + uint32_t depth = capture->stack_depth; |
| + struct XRayTraceStackEntry* se = &capture->stack[depth]; |
| + uint32_t buffer_index = se->dest; |
| + uint64_t tsc; |
| + struct XRayTraceBufferEntry* be = &capture->buffer[buffer_index]; |
| + GTSC(tsc); |
| + be->depth_addr = se->depth_addr; |
| + be->start_tick = se->tsc; |
| + be->end_tick = tsc; |
| + be->annotation_index = 0; |
| + if (0 != se->annotation_index) |
| + __xray_profile_append_annotation(capture, se, be); |
| + } |
| + } |
| +} |
| +#else |
| /* Main profile capture function that is called at the start */ |
| /* of every instrumented function. This function is implicitly */ |
| /* called when code is compilied with the -finstrument-functions option */ |
| @@ -349,6 +394,17 @@ void __cyg_profile_func_exit(void* this_fn, void* call_site) { |
| } |
| } |
| } |
| +#endif // __pnacl__ |
|
nfullagar1
2013/07/17 00:53:19
above: /* __pnacl__ */
/* c style comment */
grosse
2013/07/17 19:37:56
Done.
|
| + |
| + |
| +void XRayGetTSC(uint64_t* tsc) {GTSC(*tsc);} |
| + |
| +struct XrayTimestampPair* XRayGetStartTimestamp( |
| + struct XRayTraceCapture* capture) |
| +{ |
| + assert(capture->start_time_initialized); |
| + return &capture->start_time; |
| +} |
| /* Special case appending annotation string to trace buffer */ |
| @@ -573,6 +629,14 @@ void XRayStartFrame(struct XRayTraceCapture* capture) { |
| capture->recording = true; |
| GTSC(capture->frame.entry[i].start_tsc); |
| g_xray_capture = capture; |
| + |
| +#ifndef XRAY_NOPEPPER |
|
nfullagar1
2013/07/17 00:53:19
XRAY_DISABLE_BROWSER_INTEGRATION (here & elsewher
grosse
2013/07/17 19:37:56
Done.
|
| + if (!capture->start_time_initialized) { |
| + capture->start_time = XRayPepperBeginCalibration(); |
|
nfullagar1
2013/07/17 00:53:19
XRayBrowserBeginCalibration ?
|
| + capture->start_time_initialized = true; |
| + } |
| +#endif /* XRAY_NOPEPPER */ |
|
nfullagar1
2013/07/17 00:53:19
I think the above may be better if this was done f
|
| + |
| } |
| @@ -690,6 +754,7 @@ struct XRayTraceCapture* XRayInit(int stack_depth, |
| capture->guard3 = XRAY_GUARD_VALUE_0x12345678; |
| capture->initialized = true; |
| capture->recording = false; |
| + capture->start_time_initialized = false; |
| XRaySetMaxStackDepth(capture, stack_depth); |
| XRayReset(capture); |