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

Side by Side Diff: base/trace_event/trace_log.cc

Issue 1837013003: [tracing] Add support for profiling trace events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ipc_trace
Patch Set: nits. Created 4 years, 8 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
« base/trace_event/trace_log.h ('K') | « base/trace_event/trace_log.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_log.h" 5 #include "base/trace_event/trace_log.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 if (mode_ == RECORDING_MODE && 454 if (mode_ == RECORDING_MODE &&
455 trace_config_.IsCategoryGroupEnabled(category_group)) { 455 trace_config_.IsCategoryGroupEnabled(category_group)) {
456 enabled_flag |= ENABLED_FOR_RECORDING; 456 enabled_flag |= ENABLED_FOR_RECORDING;
457 } 457 }
458 458
459 if (event_callback_ && 459 if (event_callback_ &&
460 event_callback_trace_config_.IsCategoryGroupEnabled(category_group)) { 460 event_callback_trace_config_.IsCategoryGroupEnabled(category_group)) {
461 enabled_flag |= ENABLED_FOR_EVENT_CALLBACK; 461 enabled_flag |= ENABLED_FOR_EVENT_CALLBACK;
462 } 462 }
463 463
464 if (AllocationContextTracker::capture_enabled()) {
465 enabled_flag |= ENABLED_FOR_HEAP_PROFILING;
466 }
467
464 #if defined(OS_WIN) 468 #if defined(OS_WIN)
465 if (base::trace_event::TraceEventETWExport::IsCategoryGroupEnabled( 469 if (base::trace_event::TraceEventETWExport::IsCategoryGroupEnabled(
466 category_group)) { 470 category_group)) {
467 enabled_flag |= ENABLED_FOR_ETW_EXPORT; 471 enabled_flag |= ENABLED_FOR_ETW_EXPORT;
468 } 472 }
469 #endif 473 #endif
470 474
471 g_category_group_enabled[category_index] = enabled_flag; 475 g_category_group_enabled[category_index] = enabled_flag;
472 } 476 }
473 477
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 unsigned long long bind_id, 1165 unsigned long long bind_id,
1162 int thread_id, 1166 int thread_id,
1163 const TimeTicks& timestamp, 1167 const TimeTicks& timestamp,
1164 int num_args, 1168 int num_args,
1165 const char** arg_names, 1169 const char** arg_names,
1166 const unsigned char* arg_types, 1170 const unsigned char* arg_types,
1167 const unsigned long long* arg_values, 1171 const unsigned long long* arg_values,
1168 scoped_ptr<ConvertableToTraceFormat>* convertable_values, 1172 scoped_ptr<ConvertableToTraceFormat>* convertable_values,
1169 unsigned int flags) { 1173 unsigned int flags) {
1170 TraceEventHandle handle = {0, 0, 0}; 1174 TraceEventHandle handle = {0, 0, 0};
1171 if (!*category_group_enabled) 1175 if (!(*category_group_enabled & ENABLED_FOR_NON_PROFILING_MODE))
1172 return handle; 1176 return handle;
1173 1177
1174 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when 1178 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when
1175 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> 1179 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) ->
1176 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... 1180 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ...
1177 if (thread_is_in_trace_event_.Get()) 1181 if (thread_is_in_trace_event_.Get())
1178 return handle; 1182 return handle;
1179 1183
1180 AutoThreadLocalBoolean thread_is_in_trace_event(&thread_is_in_trace_event_); 1184 AutoThreadLocalBoolean thread_is_in_trace_event(&thread_is_in_trace_event_);
1181 1185
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 if (event_callback) { 1312 if (event_callback) {
1309 event_callback( 1313 event_callback(
1310 offset_event_timestamp, 1314 offset_event_timestamp,
1311 phase == TRACE_EVENT_PHASE_COMPLETE ? TRACE_EVENT_PHASE_BEGIN : phase, 1315 phase == TRACE_EVENT_PHASE_COMPLETE ? TRACE_EVENT_PHASE_BEGIN : phase,
1312 category_group_enabled, name, scope, id, num_args, arg_names, 1316 category_group_enabled, name, scope, id, num_args, arg_names,
1313 arg_types, arg_values, flags); 1317 arg_types, arg_values, flags);
1314 } 1318 }
1315 } 1319 }
1316 1320
1317 // TODO(primiano): Add support for events with copied name crbug.com/581078 1321 // TODO(primiano): Add support for events with copied name crbug.com/581078
1322 // TODO(ssid): Move push to ScopedTracer after adding profiling support in
1323 // Blink and skia crbug.com/598426.
1318 if (!(flags & TRACE_EVENT_FLAG_COPY)) { 1324 if (!(flags & TRACE_EVENT_FLAG_COPY)) {
1319 if (AllocationContextTracker::capture_enabled()) { 1325 if (AllocationContextTracker::capture_enabled()) {
1320 if (phase == TRACE_EVENT_PHASE_BEGIN || 1326 if (phase == TRACE_EVENT_PHASE_BEGIN ||
1321 phase == TRACE_EVENT_PHASE_COMPLETE) { 1327 phase == TRACE_EVENT_PHASE_COMPLETE) {
1322 AllocationContextTracker::GetInstanceForCurrentThread() 1328 AllocationContextTracker::GetInstanceForCurrentThread()
1323 ->PushPseudoStackFrame(name); 1329 ->PushPseudoStackFrame(name);
1324 } else if (phase == TRACE_EVENT_PHASE_END) 1330 } else if (phase == TRACE_EVENT_PHASE_END) {
1325 // The pop for |TRACE_EVENT_PHASE_COMPLETE| events 1331 // The pop for |TRACE_EVENT_PHASE_COMPLETE| events
1326 // is in |TraceLog::UpdateTraceEventDuration|. 1332 // is in |TraceLog::UpdateTraceEventDuration|.
1327 AllocationContextTracker::GetInstanceForCurrentThread() 1333 AllocationContextTracker::GetInstanceForCurrentThread()
1328 ->PopPseudoStackFrame(name); 1334 ->PopPseudoStackFrame(name);
1335 }
1329 } 1336 }
1330 } 1337 }
1331 1338
1332 return handle; 1339 return handle;
1333 } 1340 }
1334 1341
1335 void TraceLog::AddMetadataEvent( 1342 void TraceLog::AddMetadataEvent(
1336 const unsigned char* category_group_enabled, 1343 const unsigned char* category_group_enabled,
1337 const char* name, 1344 const char* name,
1338 int num_args, 1345 int num_args,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 thread_event_start_times_[thread_id].push(timestamp); 1409 thread_event_start_times_[thread_id].push(timestamp);
1403 1410
1404 return log.str(); 1411 return log.str();
1405 } 1412 }
1406 1413
1407 void TraceLog::UpdateTraceEventDuration( 1414 void TraceLog::UpdateTraceEventDuration(
1408 const unsigned char* category_group_enabled, 1415 const unsigned char* category_group_enabled,
1409 const char* name, 1416 const char* name,
1410 TraceEventHandle handle) { 1417 TraceEventHandle handle) {
1411 char category_group_enabled_local = *category_group_enabled; 1418 char category_group_enabled_local = *category_group_enabled;
1412 if (!category_group_enabled_local) 1419 if (!(category_group_enabled_local & ENABLED_FOR_NON_PROFILING_MODE))
1413 return; 1420 return;
1414 1421
1415 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when 1422 // Avoid re-entrance of AddTraceEvent. This may happen in GPU process when
1416 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) -> 1423 // ECHO_TO_CONSOLE is enabled: AddTraceEvent -> LOG(ERROR) ->
1417 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ... 1424 // GpuProcessLogMessageHandler -> PostPendingTask -> TRACE_EVENT ...
1418 if (thread_is_in_trace_event_.Get()) 1425 if (thread_is_in_trace_event_.Get())
1419 return; 1426 return;
1420 1427
1421 AutoThreadLocalBoolean thread_is_in_trace_event(&thread_is_in_trace_event_); 1428 AutoThreadLocalBoolean thread_is_in_trace_event(&thread_is_in_trace_event_);
1422 1429
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 1716
1710 ScopedTraceBinaryEfficient::ScopedTraceBinaryEfficient( 1717 ScopedTraceBinaryEfficient::ScopedTraceBinaryEfficient(
1711 const char* category_group, 1718 const char* category_group,
1712 const char* name) { 1719 const char* name) {
1713 // The single atom works because for now the category_group can only be "gpu". 1720 // The single atom works because for now the category_group can only be "gpu".
1714 DCHECK_EQ(strcmp(category_group, "gpu"), 0); 1721 DCHECK_EQ(strcmp(category_group, "gpu"), 0);
1715 static TRACE_EVENT_API_ATOMIC_WORD atomic = 0; 1722 static TRACE_EVENT_API_ATOMIC_WORD atomic = 0;
1716 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES( 1723 INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES(
1717 category_group, atomic, category_group_enabled_); 1724 category_group, atomic, category_group_enabled_);
1718 name_ = name; 1725 name_ = name;
1719 if (*category_group_enabled_) { 1726 if (*category_group_enabled_ &
1727 base::trace_event::TraceLog::ENABLED_FOR_NON_PROFILING_MODE) {
1720 event_handle_ = 1728 event_handle_ =
1721 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP( 1729 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_THREAD_ID_AND_TIMESTAMP(
1722 TRACE_EVENT_PHASE_COMPLETE, 1730 TRACE_EVENT_PHASE_COMPLETE,
1723 category_group_enabled_, 1731 category_group_enabled_,
1724 name, 1732 name,
1725 trace_event_internal::kGlobalScope, // scope 1733 trace_event_internal::kGlobalScope, // scope
1726 trace_event_internal::kNoId, // id 1734 trace_event_internal::kNoId, // id
1727 static_cast<int>(base::PlatformThread::CurrentId()), // thread_id 1735 static_cast<int>(base::PlatformThread::CurrentId()), // thread_id
1728 base::TimeTicks::Now(), 1736 base::TimeTicks::Now(),
1729 trace_event_internal::kZeroNumArgs, 1737 trace_event_internal::kZeroNumArgs,
1730 nullptr, 1738 nullptr,
1731 nullptr, 1739 nullptr,
1732 nullptr, 1740 nullptr,
1733 nullptr, 1741 nullptr,
1734 TRACE_EVENT_FLAG_NONE); 1742 TRACE_EVENT_FLAG_NONE);
1735 } 1743 }
1736 } 1744 }
1737 1745
1738 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 1746 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
1739 if (*category_group_enabled_) { 1747 if (*category_group_enabled_ &
1748 base::trace_event::TraceLog::ENABLED_FOR_NON_PROFILING_MODE) {
1740 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, 1749 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_,
1741 event_handle_); 1750 event_handle_);
1742 } 1751 }
1743 } 1752 }
1744 1753
1745 } // namespace trace_event_internal 1754 } // namespace trace_event_internal
OLDNEW
« base/trace_event/trace_log.h ('K') | « base/trace_event/trace_log.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698