Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1452)

Unified Diff: native_client_sdk/src/libraries/xray/xray.c

Issue 19409003: Update Xray for PNaCl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change to perframe calibration Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..2a8e733f91d61440f55a33347ffa4c7a83091f26 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
};
@@ -100,10 +104,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);
nfullagar1 2013/07/18 00:47:22 plz format/indent above as it was before
+#endif
+
XRAY_NO_INSTRUMENT void __xray_profile_append_annotation(
struct XRayTraceCapture* capture,
struct XRayTraceStackEntry* se,
@@ -113,7 +122,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 +311,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) {
+ 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 +403,18 @@ 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);}
+
+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 +638,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 */
+
}
@@ -612,6 +682,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 */
}

Powered by Google App Engine
This is Rietveld 408576698