OLD | NEW |
---|---|
(Empty) | |
1 /* Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 * Use of this source code is governed by a BSD-style license that can be | |
3 * found in the LICENSE file. | |
4 */ | |
5 | |
6 | |
7 /* XRay -- a simple profiler for Native Client */ | |
8 | |
9 #ifndef XRAY_DISABLE_BROWSER_INTEGRATION | |
10 | |
11 #include <alloca.h> | |
12 #include <assert.h> | |
13 #include <errno.h> | |
14 #include <stdarg.h> | |
15 #include <stdint.h> | |
16 #include <stdio.h> | |
17 #include <stdlib.h> | |
18 #include <string.h> | |
19 #include <unistd.h> | |
20 #include "ppapi/c/dev/ppb_trace_event_dev.h" | |
21 #include "xray/xray_priv.h" | |
22 | |
23 | |
24 #if defined(XRAY) | |
25 static PPB_Trace_Event_Dev* trace = NULL; | |
26 | |
27 static const char* XRayGetName(struct XRaySymbolTable* symbols, | |
28 struct XRayTraceBufferEntry* e) { | |
29 uint32_t addr = XRAY_EXTRACT_ADDR(e->depth_addr); | |
30 struct XRaySymbol* symbol = XRaySymbolTableLookup(symbols, addr); | |
31 return XRaySymbolGetName(symbol); | |
32 } | |
33 | |
34 struct XRayTimestampPair XRayGenerateTimestampsNow(void) { | |
35 struct XRayTimestampPair pair; | |
36 assert(trace); | |
37 | |
38 XRayGetTSC(&pair.xray); | |
39 pair.pepper = trace->Now(); | |
40 return pair; | |
41 } | |
42 | |
43 | |
44 void XRayBrowserTraceReport(struct XRayTraceCapture* capture) { | |
45 | |
46 const void* cat_enabled = trace->GetCategoryEnabled("xray"); | |
47 struct XRaySymbolTable* symbols = XRayGetSymbolTable(capture); | |
48 | |
49 int32_t thread_id = XRayGetThreadID(capture); | |
50 | |
51 int head = XRayFrameGetHead(capture); | |
52 int frame = XRayFrameGetTail(capture); | |
53 while(frame != head) { | |
54 | |
55 struct XRayTimestampPair* start_time = XRayGetTimestamp( | |
56 capture, frame, false); | |
57 struct XRayTimestampPair* end_time = XRayGetTimestamp( | |
58 capture, frame, true); | |
59 | |
60 double pdiff = (end_time->pepper - start_time->pepper); | |
61 double odiff = (end_time->xray - start_time->xray); | |
62 double scale_a = pdiff / odiff; | |
63 double scale_b = ((double)end_time->pepper) - (scale_a * end_time->xray); | |
64 printf("Xray timestamp calibration frame %d: %f %f\n", | |
65 frame, scale_a, scale_b); | |
66 | |
67 | |
68 int start = XRayFrameGetTraceStartIndex(capture, frame); | |
69 int end = XRayFrameGetTraceEndIndex(capture, frame); | |
70 int count = XRayFrameGetTraceCount(capture, frame); | |
71 | |
72 struct XRayTraceBufferEntry** stack_base = XRayMalloc( | |
73 sizeof(struct XRayTraceBufferEntry*) * (count+1)); | |
nfullagar1
2013/07/18 00:47:22
spaces between binary ops; (count + 1)
(here and e
| |
74 struct XRayTraceBufferEntry** stack_top = stack_base; | |
75 *stack_top = NULL; | |
76 | |
77 int i; | |
78 for(i = start; i != end; i = XRayTraceNextEntry(capture, i)) { | |
nfullagar1
2013/07/18 00:47:22
merge two lines above: for (int i = start; ...
| |
79 if (XRayTraceIsAnnotation(capture, i)) {continue;} | |
80 | |
81 uint64_t current_tick = XRayTraceGetEntry(capture, i)->start_tick; | |
82 while(*stack_top && current_tick >= (*stack_top)->end_tick){ | |
83 struct XRayTraceBufferEntry* e = *(stack_top--); | |
84 trace->AddTraceEventWithThreadIdAndTimestamp( | |
85 'E', cat_enabled, | |
86 XRayGetName(symbols, e), | |
87 0, thread_id, | |
88 (scale_a * e->end_tick) + scale_b, | |
89 0, NULL, NULL, NULL, 0 | |
90 ); | |
91 } | |
92 | |
93 { | |
nfullagar1
2013/07/18 00:47:22
remove extra scope, afaict it isn't needed.
| |
94 struct XRayTraceBufferEntry* e = XRayTraceGetEntry(capture, i); | |
95 trace->AddTraceEventWithThreadIdAndTimestamp( | |
96 'B', cat_enabled, | |
97 XRayGetName(symbols, e), | |
98 0, thread_id, | |
99 (scale_a * e->start_tick) + scale_b, | |
100 0, NULL, NULL, NULL, 0 | |
101 ); | |
102 | |
103 *(++stack_top) = e; | |
104 } | |
105 } | |
106 | |
107 while(*stack_top){ | |
108 struct XRayTraceBufferEntry* e = *(stack_top--); | |
109 trace->AddTraceEventWithThreadIdAndTimestamp( | |
110 'E', cat_enabled, | |
111 XRayGetName(symbols, e), | |
112 0, thread_id, | |
113 (scale_a * e->end_tick) + scale_b, | |
114 0, NULL, NULL, NULL, 0 | |
115 ); | |
116 } | |
117 | |
118 frame = XRayFrameGetNext(capture, frame); | |
119 XRayFree(stack_base); | |
120 } | |
121 } | |
122 | |
123 void XRayRegisterBrowserInterface(PPB_GetInterface interface) { | |
124 trace = (PPB_Trace_Event_Dev*)interface(PPB_TRACE_EVENT_DEV_INTERFACE); | |
125 assert(trace); | |
126 } | |
127 | |
128 #endif /* XRAY */ | |
129 #endif /* XRAY_DISABLE_BROWSER_INTEGRATION */ | |
OLD | NEW |