| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/trace_event/trace_event_etw_export_win.h" | 5 #include "base/trace_event/trace_event_etw_export_win.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "base/trace_event/trace_event_impl.h" | 12 #include "base/trace_event/trace_event_impl.h" |
| 13 | 13 |
| 14 // The GetProcAddress technique is borrowed from | 14 // The GetProcAddress technique is borrowed from |
| 15 // https://github.com/randomascii/main/tree/master/xperf/ETWProviders | 15 // https://github.com/google/UIforETW/tree/master/ETWProviders |
| 16 // | 16 // |
| 17 // EVNTAPI is used in evntprov.h which is included by chrome_events_win.h. | 17 // EVNTAPI is used in evntprov.h which is included by chrome_events_win.h. |
| 18 // We define EVNTAPI without the DECLSPEC_IMPORT specifier so that we can | 18 // We define EVNTAPI without the DECLSPEC_IMPORT specifier so that we can |
| 19 // implement these functions locally instead of using the import library, and | 19 // implement these functions locally instead of using the import library, and |
| 20 // can therefore still run on Windows XP. | 20 // can therefore still run on Windows XP. |
| 21 #define EVNTAPI __stdcall | 21 #define EVNTAPI __stdcall |
| 22 // Include the event register/write/unregister macros compiled from the manifest | 22 // Include the event register/write/unregister macros compiled from the manifest |
| 23 // file. Note that this includes evntprov.h which requires a Vista+ Windows SDK. | 23 // file. Note that this includes evntprov.h which requires a Vista+ Windows SDK. |
| 24 // | 24 // |
| 25 // In SHARED_INTERMEDIATE_DIR. | 25 // In SHARED_INTERMEDIATE_DIR. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 44 | 44 |
| 45 // Redirector function for EventRegister. Called by macros in | 45 // Redirector function for EventRegister. Called by macros in |
| 46 // chrome_events_win.h | 46 // chrome_events_win.h |
| 47 ULONG EVNTAPI EventRegister(LPCGUID ProviderId, | 47 ULONG EVNTAPI EventRegister(LPCGUID ProviderId, |
| 48 PENABLECALLBACK EnableCallback, | 48 PENABLECALLBACK EnableCallback, |
| 49 PVOID CallbackContext, | 49 PVOID CallbackContext, |
| 50 PREGHANDLE RegHandle) { | 50 PREGHANDLE RegHandle) { |
| 51 if (EventRegisterProc) | 51 if (EventRegisterProc) |
| 52 return EventRegisterProc(ProviderId, EnableCallback, CallbackContext, | 52 return EventRegisterProc(ProviderId, EnableCallback, CallbackContext, |
| 53 RegHandle); | 53 RegHandle); |
| 54 *RegHandle = 0; |
| 54 return 0; | 55 return 0; |
| 55 } | 56 } |
| 56 | 57 |
| 57 // Redirector function for EventWrite. Called by macros in | 58 // Redirector function for EventWrite. Called by macros in |
| 58 // chrome_events_win.h | 59 // chrome_events_win.h |
| 59 ULONG EVNTAPI EventWrite(REGHANDLE RegHandle, | 60 ULONG EVNTAPI EventWrite(REGHANDLE RegHandle, |
| 60 PCEVENT_DESCRIPTOR EventDescriptor, | 61 PCEVENT_DESCRIPTOR EventDescriptor, |
| 61 ULONG UserDataCount, | 62 ULONG UserDataCount, |
| 62 PEVENT_DATA_DESCRIPTOR UserData) { | 63 PEVENT_DATA_DESCRIPTOR UserData) { |
| 63 if (EventWriteProc) | 64 if (EventWriteProc) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 int num_args, | 126 int num_args, |
| 126 const char** arg_names, | 127 const char** arg_names, |
| 127 const unsigned char* arg_types, | 128 const unsigned char* arg_types, |
| 128 const unsigned long long* arg_values, | 129 const unsigned long long* arg_values, |
| 129 const scoped_refptr<ConvertableToTraceFormat>* convertable_values) { | 130 const scoped_refptr<ConvertableToTraceFormat>* convertable_values) { |
| 130 // We bail early in case exporting is disabled or no consumer is listening. | 131 // We bail early in case exporting is disabled or no consumer is listening. |
| 131 if (!GetInstance() || !GetInstance()->ETWExportEnabled_ || | 132 if (!GetInstance() || !GetInstance()->ETWExportEnabled_ || |
| 132 !EventEnabledChromeEvent()) | 133 !EventEnabledChromeEvent()) |
| 133 return; | 134 return; |
| 134 | 135 |
| 135 std::string phase_string; | 136 const char* phase_string = nullptr; |
| 137 // Space to store the phase identifier and null-terminator, when needed. |
| 138 char phase_buffer[2]; |
| 136 switch (phase) { | 139 switch (phase) { |
| 137 case TRACE_EVENT_PHASE_BEGIN: | 140 case TRACE_EVENT_PHASE_BEGIN: |
| 138 phase_string = "Begin"; | 141 phase_string = "Begin"; |
| 139 break; | 142 break; |
| 140 case TRACE_EVENT_PHASE_END: | 143 case TRACE_EVENT_PHASE_END: |
| 141 phase_string = "End"; | 144 phase_string = "End"; |
| 142 break; | 145 break; |
| 143 case TRACE_EVENT_PHASE_COMPLETE: | 146 case TRACE_EVENT_PHASE_COMPLETE: |
| 144 phase_string = "Complete"; | 147 phase_string = "Complete"; |
| 145 break; | 148 break; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 case TRACE_EVENT_PHASE_CREATE_OBJECT: | 191 case TRACE_EVENT_PHASE_CREATE_OBJECT: |
| 189 phase_string = "Phase Create Object"; | 192 phase_string = "Phase Create Object"; |
| 190 break; | 193 break; |
| 191 case TRACE_EVENT_PHASE_SNAPSHOT_OBJECT: | 194 case TRACE_EVENT_PHASE_SNAPSHOT_OBJECT: |
| 192 phase_string = "Phase Snapshot Object"; | 195 phase_string = "Phase Snapshot Object"; |
| 193 break; | 196 break; |
| 194 case TRACE_EVENT_PHASE_DELETE_OBJECT: | 197 case TRACE_EVENT_PHASE_DELETE_OBJECT: |
| 195 phase_string = "Phase Delete Object"; | 198 phase_string = "Phase Delete Object"; |
| 196 break; | 199 break; |
| 197 default: | 200 default: |
| 198 phase_string.push_back(phase); | 201 phase_buffer[0] = phase; |
| 202 phase_buffer[1] = 0; |
| 203 phase_string = phase_buffer; |
| 199 break; | 204 break; |
| 200 } | 205 } |
| 201 | 206 |
| 202 std::string arg_values_string[3]; | 207 std::string arg_values_string[3]; |
| 203 for (int i = 0; i < num_args; i++) { | 208 for (int i = 0; i < num_args; i++) { |
| 204 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE) { | 209 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE) { |
| 205 convertable_values[i]->AppendAsTraceFormat(arg_values_string + i); | 210 // Temporarily do nothing here. This function consumes 1/3 to 1/2 of |
| 211 // *total* process CPU time when ETW tracing, and many of the strings |
| 212 // created exceed WPA's 4094 byte limit and are shown as: |
| 213 // "Unable to parse data". See crbug.com/488257 |
| 214 //convertable_values[i]->AppendAsTraceFormat(arg_values_string + i); |
| 206 } else { | 215 } else { |
| 207 TraceEvent::TraceValue trace_event; | 216 TraceEvent::TraceValue trace_event; |
| 208 trace_event.as_uint = arg_values[i]; | 217 trace_event.as_uint = arg_values[i]; |
| 209 TraceEvent::AppendValueAsJSON(arg_types[i], trace_event, | 218 TraceEvent::AppendValueAsJSON(arg_types[i], trace_event, |
| 210 arg_values_string + i); | 219 arg_values_string + i); |
| 211 } | 220 } |
| 212 } | 221 } |
| 213 | 222 |
| 214 EventWriteChromeEvent( | 223 EventWriteChromeEvent( |
| 215 name, phase_string.c_str(), num_args > 0 ? arg_names[0] : "", | 224 name, phase_string, num_args > 0 ? arg_names[0] : "", |
| 216 arg_values_string[0].c_str(), num_args > 1 ? arg_names[1] : "", | 225 arg_values_string[0].c_str(), num_args > 1 ? arg_names[1] : "", |
| 217 arg_values_string[1].c_str(), num_args > 2 ? arg_names[2] : "", | 226 arg_values_string[1].c_str(), num_args > 2 ? arg_names[2] : "", |
| 218 arg_values_string[2].c_str()); | 227 arg_values_string[2].c_str()); |
| 219 } | 228 } |
| 220 | 229 |
| 221 // static | 230 // static |
| 222 void TraceEventETWExport::AddCustomEvent(const char* name, | 231 void TraceEventETWExport::AddCustomEvent(const char* name, |
| 223 char const* phase, | 232 char const* phase, |
| 224 const char* arg_name_1, | 233 const char* arg_name_1, |
| 225 const char* arg_value_1, | 234 const char* arg_value_1, |
| 226 const char* arg_name_2, | 235 const char* arg_name_2, |
| 227 const char* arg_value_2, | 236 const char* arg_value_2, |
| 228 const char* arg_name_3, | 237 const char* arg_name_3, |
| 229 const char* arg_value_3) { | 238 const char* arg_value_3) { |
| 230 if (!GetInstance() || !GetInstance()->ETWExportEnabled_ || | 239 if (!GetInstance() || !GetInstance()->ETWExportEnabled_ || |
| 231 !EventEnabledChromeEvent()) | 240 !EventEnabledChromeEvent()) |
| 232 return; | 241 return; |
| 233 | 242 |
| 234 EventWriteChromeEvent(name, phase, arg_name_1, arg_value_1, arg_name_2, | 243 EventWriteChromeEvent(name, phase, arg_name_1, arg_value_1, arg_name_2, |
| 235 arg_value_2, arg_name_3, arg_value_3); | 244 arg_value_2, arg_name_3, arg_value_3); |
| 236 } | 245 } |
| 237 | 246 |
| 238 void TraceEventETWExport::Resurrect() { | 247 void TraceEventETWExport::Resurrect() { |
| 239 StaticMemorySingletonTraits<TraceEventETWExport>::Resurrect(); | 248 StaticMemorySingletonTraits<TraceEventETWExport>::Resurrect(); |
| 240 } | 249 } |
| 241 | 250 |
| 242 } // namespace trace_event | 251 } // namespace trace_event |
| 243 } // namespace base | 252 } // namespace base |
| OLD | NEW |