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

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

Issue 1368993002: Reland of "Add thread-local allocation context for tracing" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address primiano comment Created 5 years, 2 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
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 9
10 #include "base/base_switches.h" 10 #include "base/base_switches.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/debug/leak_annotations.h" 13 #include "base/debug/leak_annotations.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.h"
17 #include "base/process/process_metrics.h" 17 #include "base/process/process_metrics.h"
18 #include "base/strings/string_split.h" 18 #include "base/strings/string_split.h"
19 #include "base/strings/string_tokenizer.h" 19 #include "base/strings/string_tokenizer.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/sys_info.h" 21 #include "base/sys_info.h"
22 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 22 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
23 #include "base/thread_task_runner_handle.h" 23 #include "base/thread_task_runner_handle.h"
24 #include "base/threading/platform_thread.h" 24 #include "base/threading/platform_thread.h"
25 #include "base/threading/thread_id_name_manager.h" 25 #include "base/threading/thread_id_name_manager.h"
26 #include "base/threading/worker_pool.h" 26 #include "base/threading/worker_pool.h"
27 #include "base/time/time.h" 27 #include "base/time/time.h"
28 #include "base/trace_event/memory_dump_manager.h" 28 #include "base/trace_event/memory_dump_manager.h"
29 #include "base/trace_event/memory_dump_provider.h" 29 #include "base/trace_event/memory_dump_provider.h"
30 #include "base/trace_event/memory_profiler_allocation_context.h"
30 #include "base/trace_event/process_memory_dump.h" 31 #include "base/trace_event/process_memory_dump.h"
31 #include "base/trace_event/trace_buffer.h" 32 #include "base/trace_event/trace_buffer.h"
32 #include "base/trace_event/trace_event.h" 33 #include "base/trace_event/trace_event.h"
33 #include "base/trace_event/trace_event_synthetic_delay.h" 34 #include "base/trace_event/trace_event_synthetic_delay.h"
34 #include "base/trace_event/trace_log.h" 35 #include "base/trace_event/trace_log.h"
35 #include "base/trace_event/trace_sampling_thread.h" 36 #include "base/trace_event/trace_sampling_thread.h"
36 37
37 #if defined(OS_WIN) 38 #if defined(OS_WIN)
38 #include "base/trace_event/trace_event_etw_export_win.h" 39 #include "base/trace_event/trace_event_etw_export_win.h"
39 #include "base/trace_event/trace_event_win.h" 40 #include "base/trace_event/trace_event_win.h"
(...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 subtle::NoBarrier_Load(&event_callback_)); 1314 subtle::NoBarrier_Load(&event_callback_));
1314 if (event_callback) { 1315 if (event_callback) {
1315 event_callback( 1316 event_callback(
1316 offset_event_timestamp, 1317 offset_event_timestamp,
1317 phase == TRACE_EVENT_PHASE_COMPLETE ? TRACE_EVENT_PHASE_BEGIN : phase, 1318 phase == TRACE_EVENT_PHASE_COMPLETE ? TRACE_EVENT_PHASE_BEGIN : phase,
1318 category_group_enabled, name, id, num_args, arg_names, arg_types, 1319 category_group_enabled, name, id, num_args, arg_names, arg_types,
1319 arg_values, flags); 1320 arg_values, flags);
1320 } 1321 }
1321 } 1322 }
1322 1323
1324 if (base::trace_event::AllocationContextTracker::capture_enabled()) {
1325 if (phase == TRACE_EVENT_PHASE_BEGIN || phase == TRACE_EVENT_PHASE_COMPLETE)
1326 base::trace_event::AllocationContextTracker::PushPseudoStackFrame(name);
1327 else if (phase == TRACE_EVENT_PHASE_END)
1328 // The pop for |TRACE_EVENT_PHASE_COMPLETE| events
1329 // is in |TraceLog::UpdateTraceEventDuration|.
1330 base::trace_event::AllocationContextTracker::PopPseudoStackFrame(name);
1331 }
1332
1323 return handle; 1333 return handle;
1324 } 1334 }
1325 1335
1326 // May be called when a COMPELETE event ends and the unfinished event has been 1336 // May be called when a COMPELETE event ends and the unfinished event has been
1327 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL). 1337 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL).
1328 std::string TraceLog::EventToConsoleMessage(unsigned char phase, 1338 std::string TraceLog::EventToConsoleMessage(unsigned char phase,
1329 const TraceTicks& timestamp, 1339 const TraceTicks& timestamp,
1330 TraceEvent* trace_event) { 1340 TraceEvent* trace_event) {
1331 AutoLock thread_info_lock(thread_info_lock_); 1341 AutoLock thread_info_lock(thread_info_lock_);
1332 1342
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 trace_event->UpdateDuration(now, thread_now); 1428 trace_event->UpdateDuration(now, thread_now);
1419 #if defined(OS_ANDROID) 1429 #if defined(OS_ANDROID)
1420 trace_event->SendToATrace(); 1430 trace_event->SendToATrace();
1421 #endif 1431 #endif
1422 } 1432 }
1423 1433
1424 if (trace_options() & kInternalEchoToConsole) { 1434 if (trace_options() & kInternalEchoToConsole) {
1425 console_message = 1435 console_message =
1426 EventToConsoleMessage(TRACE_EVENT_PHASE_END, now, trace_event); 1436 EventToConsoleMessage(TRACE_EVENT_PHASE_END, now, trace_event);
1427 } 1437 }
1438
1439 if (base::trace_event::AllocationContextTracker::capture_enabled()) {
1440 // The corresponding push is in |AddTraceEventWithThreadIdAndTimestamp|.
1441 base::trace_event::AllocationContextTracker::PopPseudoStackFrame(name);
1442 }
1428 } 1443 }
1429 1444
1430 if (console_message.size()) 1445 if (console_message.size())
1431 LOG(ERROR) << console_message; 1446 LOG(ERROR) << console_message;
1432 1447
1433 if (*category_group_enabled & ENABLED_FOR_EVENT_CALLBACK) { 1448 if (*category_group_enabled & ENABLED_FOR_EVENT_CALLBACK) {
1434 EventCallback event_callback = reinterpret_cast<EventCallback>( 1449 EventCallback event_callback = reinterpret_cast<EventCallback>(
1435 subtle::NoBarrier_Load(&event_callback_)); 1450 subtle::NoBarrier_Load(&event_callback_));
1436 if (event_callback) { 1451 if (event_callback) {
1437 event_callback(now, TRACE_EVENT_PHASE_END, category_group_enabled, name, 1452 event_callback(now, TRACE_EVENT_PHASE_END, category_group_enabled, name,
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 } 1719 }
1705 1720
1706 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 1721 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
1707 if (*category_group_enabled_) { 1722 if (*category_group_enabled_) {
1708 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, 1723 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_,
1709 event_handle_); 1724 event_handle_);
1710 } 1725 }
1711 } 1726 }
1712 1727
1713 } // namespace trace_event_internal 1728 } // namespace trace_event_internal
OLDNEW
« base/trace_event/memory_profiler_allocation_context.cc ('K') | « base/trace_event/trace_event.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698