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; | |
nfullagar1
2013/07/18 00:47:22
s/trace/ppb_trace_event_interface
grosse
2013/07/18 01:26:40
Done.
| |
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 int head = XRayFrameGetHead(capture); | |
50 int frame = XRayFrameGetTail(capture); | |
51 while(frame != head) { | |
52 | |
53 struct XRayTimestampPair* start_time = XRayGetTimestamp( | |
54 capture, frame, false); | |
55 struct XRayTimestampPair* end_time = XRayGetTimestamp( | |
56 capture, frame, true); | |
57 | |
58 double pdiff = (end_time->pepper - start_time->pepper); | |
59 double odiff = (end_time->xray - start_time->xray); | |
60 double scale_a = pdiff / odiff; | |
61 double scale_b = ((double)end_time->pepper) - (scale_a * end_time->xray); | |
62 printf("Xray timestamp calibration frame %d: %f %f\n", | |
63 frame, scale_a, scale_b); | |
64 | |
65 | |
66 int start = XRayFrameGetTraceStartIndex(capture, frame); | |
67 int end = XRayFrameGetTraceEndIndex(capture, frame); | |
68 int count = XRayFrameGetTraceCount(capture, frame); | |
69 | |
70 struct XRayTraceBufferEntry** stack_base = XRayMalloc( | |
71 sizeof(struct XRayTraceBufferEntry*) * (count+1)); | |
72 struct XRayTraceBufferEntry** stack_top = stack_base; | |
73 *stack_top = NULL; | |
74 | |
75 int i; | |
76 for(i = start; i != end; i = XRayTraceNextEntry(capture, i)) { | |
77 if (XRayTraceIsAnnotation(capture, i)) {continue;} | |
nfullagar1
2013/07/18 00:47:22
line above:
if (...)
continue;
grosse
2013/07/18 01:26:40
Done.
| |
78 | |
79 uint64_t current_tick = XRayTraceGetEntry(capture, i)->start_tick; | |
80 while(*stack_top && current_tick >= (*stack_top)->end_tick){ | |
nfullagar1
2013/07/18 00:47:22
line above: space between ) and {
grosse
2013/07/18 01:26:40
Done.
| |
81 struct XRayTraceBufferEntry* e = *(stack_top--); | |
82 trace->AddTraceEventWithThreadIdAndTimestamp( | |
83 'E', cat_enabled, | |
84 XRayGetName(symbols, e), | |
85 0, 1337, | |
86 (scale_a * e->end_tick) + scale_b, | |
87 0, NULL, NULL, NULL, 0 | |
88 ); | |
89 } | |
90 | |
91 { | |
92 struct XRayTraceBufferEntry* e = XRayTraceGetEntry(capture, i); | |
93 trace->AddTraceEventWithThreadIdAndTimestamp( | |
94 'B', cat_enabled, | |
95 XRayGetName(symbols, e), | |
96 0, 1337, | |
97 (scale_a * e->start_tick) + scale_b, | |
98 0, NULL, NULL, NULL, 0 | |
99 ); | |
100 | |
101 *(++stack_top) = e; | |
102 } | |
103 } | |
104 | |
105 while(*stack_top){ | |
106 struct XRayTraceBufferEntry* e = *(stack_top--); | |
107 trace->AddTraceEventWithThreadIdAndTimestamp( | |
108 'E', cat_enabled, | |
109 XRayGetName(symbols, e), | |
110 0, 1337, | |
111 (scale_a * e->end_tick) + scale_b, | |
112 0, NULL, NULL, NULL, 0 | |
113 ); | |
114 } | |
115 | |
116 frame = XRayFrameGetNext(capture, frame); | |
117 XRayFree(stack_base); | |
118 } | |
119 } | |
120 | |
121 void XRayRegisterBrowserInterface(PPB_GetInterface interface) { | |
122 trace = (PPB_Trace_Event_Dev*)interface(PPB_TRACE_EVENT_DEV_INTERFACE); | |
nfullagar1
2013/07/18 00:47:22
ppb_trace_event_interface = ...
grosse
2013/07/18 01:26:40
Done.
| |
123 assert(trace); | |
124 } | |
125 | |
126 #endif /* XRAY */ | |
127 #endif /* XRAY_DISABLE_BROWSER_INTEGRATION */ | |
OLD | NEW |