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

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: the real changes 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 = XRayFrameGetStartTimestampPair(
57 capture, frame);
58 struct XRayTimestampPair end_time = XRayFrameGetEndTimestampPair(
59 capture, frame);
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 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*) * (XRAY_TRACE_STACK_SIZE + 1));
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)) {
79 if (XRayTraceIsAnnotation(capture, i)) {
80 continue;
81 }
82
83 uint32_t depth = XRAY_EXTRACT_DEPTH(
84 XRayTraceGetEntry(capture, i)->depth_addr);
85
86 while(*stack_top &&
87 XRAY_EXTRACT_DEPTH((*stack_top)->depth_addr) >= depth) {
88 struct XRayTraceBufferEntry* e = *(stack_top--);
89 ppb_trace_event_interface->AddTraceEventWithThreadIdAndTimestamp(
90 'E', cat_enabled,
91 XRayGetName(symbols, e),
92 0, thread_id,
93 (scale_a * e->end_tick) + scale_b,
94 0, NULL, NULL, NULL, 0
95 );
96 }
97
98 struct XRayTraceBufferEntry* e = XRayTraceGetEntry(capture, i);
99 ppb_trace_event_interface->AddTraceEventWithThreadIdAndTimestamp(
100 'B', cat_enabled,
101 XRayGetName(symbols, e),
102 0, thread_id,
103 (scale_a * e->start_tick) + scale_b,
104 0, NULL, NULL, NULL, 0
105 );
106
107 *(++stack_top) = e;
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