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

Side by Side Diff: native_client_sdk/src/libraries/xray/browser.c

Issue 19409003: Update Xray for PNaCl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge __x_profile funcs and add comments to address mask 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 unified diff | Download patch
OLDNEW
(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* ppb_trace_event_interface = 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(ppb_trace_event_interface);
37
38 XRayGetTSC(&pair.xray);
39 pair.pepper = ppb_trace_event_interface->Now();
40 return pair;
41 }
42
43
44 void XRayBrowserTraceReport(struct XRayTraceCapture* capture) {
45
46 const void* cat_enabled = ppb_trace_event_interface->GetCategoryEnabled(
47 "xray");
48 struct XRaySymbolTable* symbols = XRayGetSymbolTable(capture);
49
50 int32_t thread_id = XRayGetSavedThreadID(capture);
51
52 int head = XRayFrameGetHead(capture);
53 int frame = XRayFrameGetTail(capture);
54 while(frame != head) {
55
56 struct XRayTimestampPair* start_time = XRayGetTimestamp(
57 capture, frame, false);
58 struct XRayTimestampPair* end_time = XRayGetTimestamp(
59 capture, frame, true);
nfullagar1 2013/07/18 18:21:06 See comment in xray.c about XRayGetTimestamp(...)
grosse 2013/07/18 20:45:37 Done.
60
61 double pdiff = (end_time->pepper - start_time->pepper);
62 double odiff = (end_time->xray - start_time->xray);
63 double scale_a = pdiff / odiff;
64 double scale_b = ((double)end_time->pepper) - (scale_a * end_time->xray);
65 printf("Xray timestamp calibration frame %d: %f %f\n",
66 frame, scale_a, scale_b);
67
68
69 int start = XRayFrameGetTraceStartIndex(capture, frame);
70 int end = XRayFrameGetTraceEndIndex(capture, frame);
71 int count = XRayFrameGetTraceCount(capture, frame);
72
73 struct XRayTraceBufferEntry** stack_base = XRayMalloc(
74 sizeof(struct XRayTraceBufferEntry*) * (count+1));
nfullagar1 2013/07/18 18:21:06 see earlier comment (if new snapshots are uploaded
grosse 2013/07/18 20:45:37 Done.
75 struct XRayTraceBufferEntry** stack_top = stack_base;
76 *stack_top = NULL;
77
78 int i;
79 for(i = start; i != end; i = XRayTraceNextEntry(capture, i)) {
nfullagar1 2013/07/18 18:21:06 see earlier comment
grosse 2013/07/18 20:45:37 The separate int i; is required for it to compile.
80 if (XRayTraceIsAnnotation(capture, i)) {
81 continue;
82 }
83
84 uint64_t current_tick = XRayTraceGetEntry(capture, i)->start_tick;
85 while(*stack_top && current_tick >= (*stack_top)->end_tick) {
86 struct XRayTraceBufferEntry* e = *(stack_top--);
87 ppb_trace_event_interface->AddTraceEventWithThreadIdAndTimestamp(
88 'E', cat_enabled,
89 XRayGetName(symbols, e),
90 0, thread_id,
91 (scale_a * e->end_tick) + scale_b,
92 0, NULL, NULL, NULL, 0
93 );
94 }
95
96 {
nfullagar1 2013/07/18 18:21:06 see earlier comment
grosse 2013/07/18 20:45:37 Done.
97 struct XRayTraceBufferEntry* e = XRayTraceGetEntry(capture, i);
98 ppb_trace_event_interface->AddTraceEventWithThreadIdAndTimestamp(
99 'B', cat_enabled,
100 XRayGetName(symbols, e),
101 0, thread_id,
102 (scale_a * e->start_tick) + scale_b,
103 0, NULL, NULL, NULL, 0
104 );
105
106 *(++stack_top) = e;
107 }
108 }
109
110 while(*stack_top) {
111 struct XRayTraceBufferEntry* e = *(stack_top--);
112 ppb_trace_event_interface->AddTraceEventWithThreadIdAndTimestamp(
113 'E', cat_enabled,
114 XRayGetName(symbols, e),
115 0, thread_id,
116 (scale_a * e->end_tick) + scale_b,
117 0, NULL, NULL, NULL, 0
118 );
119 }
120
121 frame = XRayFrameGetNext(capture, frame);
122 XRayFree(stack_base);
123 }
124 }
125
126 void XRayRegisterBrowserInterface(PPB_GetInterface interface) {
127 ppb_trace_event_interface = (PPB_Trace_Event_Dev*)interface(
128 PPB_TRACE_EVENT_DEV_INTERFACE);
129 assert(ppb_trace_event_interface);
130 }
131
132 #endif /* XRAY */
133 #endif /* XRAY_DISABLE_BROWSER_INTEGRATION */
OLDNEW
« no previous file with comments | « no previous file | native_client_sdk/src/libraries/xray/library.dsc » ('j') | native_client_sdk/src/libraries/xray/symtable.c » ('J')

Powered by Google App Engine
This is Rietveld 408576698