Chromium Code Reviews| 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 | |
|
nfullagar1
2013/07/17 00:53:19
wrap this file with #ifndef XRAY_DISABLE_BROWSER_I
grosse
2013/07/17 19:37:56
Done.
| |
| 9 #include <alloca.h> | |
| 10 #include <assert.h> | |
| 11 #include <errno.h> | |
| 12 #include <stdarg.h> | |
| 13 #include <stdint.h> | |
| 14 #include <stdio.h> | |
| 15 #include <stdlib.h> | |
| 16 #include <string.h> | |
| 17 #include <unistd.h> | |
| 18 #include "ppapi/c/dev/ppb_trace_event_dev.h" | |
| 19 #include "xray/xray_priv.h" | |
| 20 | |
| 21 | |
| 22 #if defined(XRAY) | |
| 23 static PPB_GetInterface get_browser_interface = NULL; | |
| 24 static PPB_Trace_Event_Dev* trace; | |
| 25 | |
| 26 const char* XRayGetName(struct XRaySymbolTable* symbols, | |
| 27 struct XRayTraceBufferEntry* e) | |
| 28 { | |
| 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 XRayPepperBeginCalibration(void) | |
|
nfullagar1
2013/07/17 00:53:19
{ hoisted to end of line above, here and else wher
grosse
2013/07/17 19:37:56
Done.
| |
| 35 { | |
| 36 struct XrayTimestampPair pair; | |
| 37 assert(trace); | |
| 38 | |
| 39 XRayGetTSC(&pair.xray); | |
| 40 pair.pepper = trace->Now(); | |
| 41 return pair; | |
| 42 } | |
| 43 | |
| 44 | |
| 45 void XRayBrowserTraceReport(struct XRayTraceCapture* capture) | |
| 46 { | |
| 47 | |
| 48 struct XrayTimestampPair start_time = *XRayGetStartTimestamp(capture); | |
| 49 struct XrayTimestampPair end_time = XRayPepperBeginCalibration(); | |
|
nfullagar1
2013/07/17 00:53:19
A bit confusing above - end_time is set to 'BeginC
| |
| 50 | |
| 51 double pdiff = (end_time.pepper - start_time.pepper); | |
| 52 double odiff = (end_time.xray - start_time.xray); | |
| 53 double scale_a = pdiff/odiff; | |
|
nfullagar1
2013/07/17 00:53:19
spaces around binary operator, pdiff / odiff;
(sam
grosse
2013/07/17 19:40:01
Done.
| |
| 54 double scale_b = ((double)end_time.pepper) - (scale_a*end_time.xray); | |
| 55 printf("Calibration: %f %f\n", scale_a, scale_b); | |
| 56 | |
| 57 const void* cat_enabled = trace->GetCategoryEnabled("xray"); | |
| 58 struct XRaySymbolTable* symbols = XRayGetSymbolTable(capture); | |
| 59 | |
| 60 int head = XRayFrameGetHead(capture); | |
| 61 int frame = XRayFrameGetTail(capture); | |
| 62 while(frame != head) { | |
| 63 | |
| 64 int start = XRayFrameGetTraceStartIndex(capture, frame); | |
| 65 int end = XRayFrameGetTraceEndIndex(capture, frame); | |
| 66 int count = XRayFrameGetTraceCount(capture, frame); | |
| 67 | |
| 68 struct XRayTraceBufferEntry** stack_base = XRayMalloc( | |
| 69 sizeof(struct XRayTraceBufferEntry*) * (count+1)); | |
| 70 struct XRayTraceBufferEntry** stack_top = stack_base; | |
| 71 *stack_top = NULL; | |
| 72 | |
| 73 int arg_count = 0; | |
| 74 const char* arg_names[1]; | |
| 75 const uint8_t arg_types[1] = {}; | |
| 76 const uint64_t arg_values[1] = {}; | |
| 77 | |
| 78 int i; | |
| 79 for(i = start; i != end; i = XRayTraceNextEntry(capture, i)){ | |
| 80 if (XRayTraceIsAnnotation(capture, i)) { | |
| 81 // arg_names[0] = (char*)(XRayTraceGetEntry(capture, i)) + 1; | |
|
nfullagar1
2013/07/17 00:53:19
remove dead code?
grosse
2013/07/17 19:37:56
Done.
| |
| 82 // arg_count = 1; | |
| 83 continue; | |
| 84 } | |
| 85 | |
| 86 | |
| 87 struct XRayTraceBufferEntry* e = XRayTraceGetEntry(capture, i); | |
| 88 uint32_t depth = XRAY_EXTRACT_DEPTH(e->depth_addr); | |
| 89 | |
| 90 while(*stack_top && e->start_tick >= (*stack_top)->end_tick){ | |
| 91 struct XRayTraceBufferEntry* e2 = *(stack_top--); | |
|
nfullagar1
2013/07/17 00:53:19
something more descriptive than 'e2'
grosse
2013/07/17 19:40:01
Done.
| |
| 92 | |
| 93 printf("E %s %llu\n", XRayGetName(symbols, e2), e2->end_tick); | |
| 94 trace->AddTraceEventWithThreadIdAndTimestamp( | |
| 95 'E', cat_enabled, | |
| 96 XRayGetName(symbols, e2), | |
| 97 0, 1337, | |
| 98 (scale_a * e2->end_tick) + scale_b, | |
| 99 0, NULL, NULL, NULL, 0 | |
| 100 ); | |
| 101 } | |
| 102 | |
| 103 | |
| 104 if (arg_count){ | |
| 105 printf("Sending annotation %s\n", arg_names[0]); | |
| 106 } | |
| 107 | |
| 108 printf("B %s %llu\n", XRayGetName(symbols, e), e->start_tick); | |
|
nfullagar1
2013/07/17 00:53:19
are the printfs for debugging? imo, for browser tr
grosse
2013/07/17 19:40:01
Done.
| |
| 109 trace->AddTraceEventWithThreadIdAndTimestamp( | |
| 110 'B', cat_enabled, | |
| 111 XRayGetName(symbols, e), | |
| 112 0, 1337, | |
| 113 (scale_a * e->start_tick) + scale_b, | |
| 114 arg_count, arg_names, arg_types, arg_values, 0 | |
| 115 ); | |
| 116 | |
| 117 arg_count = 0; | |
| 118 *(++stack_top) = e; | |
| 119 } | |
| 120 | |
| 121 while(*stack_top){ | |
| 122 struct XRayTraceBufferEntry* e2 = *(stack_top--); | |
| 123 | |
| 124 printf("E %s %llu\n", XRayGetName(symbols, e2), e2->end_tick); | |
| 125 trace->AddTraceEventWithThreadIdAndTimestamp( | |
| 126 'E', cat_enabled, | |
| 127 XRayGetName(symbols, e2), | |
| 128 0, 1337, | |
|
nfullagar1
2013/07/17 00:53:19
why not get real TID and send it? (stash in XRayB
| |
| 129 (scale_a * e2->end_tick) + scale_b, | |
| 130 0, NULL, NULL, NULL, 0 | |
| 131 ); | |
| 132 } | |
| 133 | |
| 134 frame = XRayFrameGetNext(capture, frame); | |
| 135 XRayFree(stack_base); | |
| 136 } | |
| 137 } | |
| 138 | |
| 139 void XRayBrowserRegisterInterface(PPB_GetInterface interface) { | |
| 140 get_browser_interface = interface; | |
|
nfullagar1
2013/07/17 00:53:19
no need to stash get_browser_interface if you only
grosse
2013/07/17 19:40:01
Done.
| |
| 141 trace = (PPB_Trace_Event_Dev*)get_browser_interface( | |
|
nfullagar1
2013/07/17 00:53:19
ppb_trace_interface
grosse
2013/07/17 19:40:01
Done.
| |
| 142 PPB_TRACE_EVENT_DEV_INTERFACE); | |
| 143 } | |
| 144 | |
| 145 #endif // XRAY | |
|
nfullagar1
2013/07/17 00:53:19
/* XRAY */
(might as well fix report.c too)
grosse
2013/07/17 19:37:56
Done.
| |
| OLD | NEW |