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..7cc949b2bc81abbbe0b1913eff09046c3552c043 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; |
@@ -62,6 +61,11 @@ struct XRayTraceFrameEntry { |
uint64_t total_ticks; |
int annotation_count; |
bool valid; |
+ |
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION |
+ struct XRayTimestampPair start_time; |
+ struct XRayTimestampPair end_time; |
+#endif |
}; |
@@ -93,6 +97,10 @@ struct XRayTraceCapture { |
uint32_t guard3; |
struct XRayTraceBufferEntry* buffer; |
struct XRayTraceFrame frame; |
+ |
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION |
+ int32_t thread_id; |
+#endif |
} XRAY_ALIGN64; |
@@ -100,10 +108,15 @@ 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); |
+#if defined(__pnacl__) |
+XRAY_NO_INSTRUMENT void __pnacl_profile_func_enter(const char* fname); |
+XRAY_NO_INSTRUMENT void __pnacl_profile_func_exit(const char* fname); |
+#else |
+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); |
+#endif |
+ |
XRAY_NO_INSTRUMENT void __xray_profile_append_annotation( |
struct XRayTraceCapture* capture, |
struct XRayTraceStackEntry* se, |
@@ -113,7 +126,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 +315,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 */ |
+void __pnacl_profile_func_enter(const char* fname) { |
nfullagar1
2013/07/18 00:47:22
(you may have missed this one from last round)
sug
|
+ 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,7 +407,22 @@ void __cyg_profile_func_exit(void* this_fn, void* call_site) { |
} |
} |
} |
+#endif /* __pnacl__ */ |
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION |
+void XRayGetTSC(uint64_t* tsc) {GTSC(*tsc);} |
nfullagar1
2013/07/18 00:47:22
above: unless it is inlined in a class, avoid putt
grosse
2013/07/18 01:26:40
Done.
|
+ |
+int32_t XRayGetThreadID(struct XRayTraceCapture* capture) { |
nfullagar1
2013/07/18 00:47:22
Need a brief comment here that ret val is the thre
grosse
2013/07/18 01:26:40
Done.
|
+ return capture->thread_id; |
+} |
+ |
+struct XRayTimestampPair* XRayGetTimestamp( |
+ struct XRayTraceCapture* capture, int frame, bool end) { |
+ |
+ struct XRayTraceFrameEntry* entry = &(capture->frame.entry[frame]); |
+ return end ? &entry->end_time : &entry->start_time; |
+} |
+#endif |
/* Special case appending annotation string to trace buffer */ |
/* this function should only ever be called from __cyg_profile_func_exit() */ |
@@ -573,6 +646,11 @@ void XRayStartFrame(struct XRayTraceCapture* capture) { |
capture->recording = true; |
GTSC(capture->frame.entry[i].start_tsc); |
g_xray_capture = capture; |
+ |
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION |
+ capture->frame.entry[i].start_time = XRayGenerateTimestampsNow(); |
+#endif /* XRAY_DISABLE_BROWSER_INTEGRATION */ |
nfullagar1
2013/07/18 00:47:22
code style is to have two spaces between #endif an
grosse
2013/07/18 01:26:40
Done.
|
+ |
} |
@@ -612,6 +690,10 @@ void XRayEndFrame(struct XRayTraceCapture* capture) { |
XRayCheckGuards(capture); |
} |
g_xray_capture = NULL; |
+ |
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION |
+ capture->frame.entry[i].end_time = XRayGenerateTimestampsNow(); |
+#endif /* XRAY_DISABLE_BROWSER_INTEGRATION */ |
} |
@@ -699,6 +781,10 @@ struct XRayTraceCapture* XRayInit(int stack_depth, |
if (NULL != mapfilename) |
XRaySymbolTableParseMapfile(capture->symbols, mapfilename); |
+#ifndef XRAY_DISABLE_BROWSER_INTEGRATION |
+ capture->thread_id = (int32_t)(&g_xray_capture); |
nfullagar1
2013/07/18 00:47:22
Suggest having a separate '__thread int g_xray_tid
grosse
2013/07/18 01:26:40
Done.
|
+#endif |
+ |
return capture; |
} |