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

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

Issue 1900223003: [tracing] Ignore tracing allocations in heap profiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: make heap_profiler.h and rebase 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
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 <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 12 matching lines...) Expand all
23 #include "base/strings/string_split.h" 23 #include "base/strings/string_split.h"
24 #include "base/strings/string_tokenizer.h" 24 #include "base/strings/string_tokenizer.h"
25 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
26 #include "base/sys_info.h" 26 #include "base/sys_info.h"
27 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 27 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
28 #include "base/thread_task_runner_handle.h" 28 #include "base/thread_task_runner_handle.h"
29 #include "base/threading/platform_thread.h" 29 #include "base/threading/platform_thread.h"
30 #include "base/threading/thread_id_name_manager.h" 30 #include "base/threading/thread_id_name_manager.h"
31 #include "base/threading/worker_pool.h" 31 #include "base/threading/worker_pool.h"
32 #include "base/time/time.h" 32 #include "base/time/time.h"
33 #include "base/trace_event/heap_profiler.h"
33 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" 34 #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
34 #include "base/trace_event/memory_dump_manager.h" 35 #include "base/trace_event/memory_dump_manager.h"
35 #include "base/trace_event/memory_dump_provider.h" 36 #include "base/trace_event/memory_dump_provider.h"
36 #include "base/trace_event/process_memory_dump.h" 37 #include "base/trace_event/process_memory_dump.h"
37 #include "base/trace_event/trace_buffer.h" 38 #include "base/trace_event/trace_buffer.h"
38 #include "base/trace_event/trace_event.h" 39 #include "base/trace_event/trace_event.h"
39 #include "base/trace_event/trace_event_synthetic_delay.h" 40 #include "base/trace_event/trace_event_synthetic_delay.h"
40 #include "base/trace_event/trace_sampling_thread.h" 41 #include "base/trace_event/trace_sampling_thread.h"
41 #include "build/build_config.h" 42 #include "build/build_config.h"
42 43
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 TraceLog::~TraceLog() {} 385 TraceLog::~TraceLog() {}
385 386
386 void TraceLog::InitializeThreadLocalEventBufferIfSupported() { 387 void TraceLog::InitializeThreadLocalEventBufferIfSupported() {
387 // A ThreadLocalEventBuffer needs the message loop 388 // A ThreadLocalEventBuffer needs the message loop
388 // - to know when the thread exits; 389 // - to know when the thread exits;
389 // - to handle the final flush. 390 // - to handle the final flush.
390 // For a thread without a message loop or the message loop may be blocked, the 391 // For a thread without a message loop or the message loop may be blocked, the
391 // trace events will be added into the main buffer directly. 392 // trace events will be added into the main buffer directly.
392 if (thread_blocks_message_loop_.Get() || !MessageLoop::current()) 393 if (thread_blocks_message_loop_.Get() || !MessageLoop::current())
393 return; 394 return;
395 HEAP_PROFILER_SCOPED_IGNORE;
394 auto thread_local_event_buffer = thread_local_event_buffer_.Get(); 396 auto thread_local_event_buffer = thread_local_event_buffer_.Get();
395 if (thread_local_event_buffer && 397 if (thread_local_event_buffer &&
396 !CheckGeneration(thread_local_event_buffer->generation())) { 398 !CheckGeneration(thread_local_event_buffer->generation())) {
397 delete thread_local_event_buffer; 399 delete thread_local_event_buffer;
398 thread_local_event_buffer = NULL; 400 thread_local_event_buffer = NULL;
399 } 401 }
400 if (!thread_local_event_buffer) { 402 if (!thread_local_event_buffer) {
401 thread_local_event_buffer = new ThreadLocalEventBuffer(this); 403 thread_local_event_buffer = new ThreadLocalEventBuffer(this);
402 thread_local_event_buffer_.Set(thread_local_event_buffer); 404 thread_local_event_buffer_.Set(thread_local_event_buffer);
403 } 405 }
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 } 902 }
901 903
902 // Usually it runs on a different thread. 904 // Usually it runs on a different thread.
903 void TraceLog::ConvertTraceEventsToTraceFormat( 905 void TraceLog::ConvertTraceEventsToTraceFormat(
904 std::unique_ptr<TraceBuffer> logged_events, 906 std::unique_ptr<TraceBuffer> logged_events,
905 const OutputCallback& flush_output_callback, 907 const OutputCallback& flush_output_callback,
906 const ArgumentFilterPredicate& argument_filter_predicate) { 908 const ArgumentFilterPredicate& argument_filter_predicate) {
907 if (flush_output_callback.is_null()) 909 if (flush_output_callback.is_null())
908 return; 910 return;
909 911
912 HEAP_PROFILER_SCOPED_IGNORE;
910 // The callback need to be called at least once even if there is no events 913 // The callback need to be called at least once even if there is no events
911 // to let the caller know the completion of flush. 914 // to let the caller know the completion of flush.
912 scoped_refptr<RefCountedString> json_events_str_ptr = new RefCountedString(); 915 scoped_refptr<RefCountedString> json_events_str_ptr = new RefCountedString();
913 while (const TraceBufferChunk* chunk = logged_events->NextChunk()) { 916 while (const TraceBufferChunk* chunk = logged_events->NextChunk()) {
914 for (size_t j = 0; j < chunk->size(); ++j) { 917 for (size_t j = 0; j < chunk->size(); ++j) {
915 size_t size = json_events_str_ptr->size(); 918 size_t size = json_events_str_ptr->size();
916 if (size > kTraceEventBufferSizeInBytes) { 919 if (size > kTraceEventBufferSizeInBytes) {
917 flush_output_callback.Run(json_events_str_ptr, true); 920 flush_output_callback.Run(json_events_str_ptr, true);
918 json_events_str_ptr = new RefCountedString(); 921 json_events_str_ptr = new RefCountedString();
919 } else if (size) { 922 } else if (size) {
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 1337
1335 void TraceLog::AddMetadataEvent( 1338 void TraceLog::AddMetadataEvent(
1336 const unsigned char* category_group_enabled, 1339 const unsigned char* category_group_enabled,
1337 const char* name, 1340 const char* name,
1338 int num_args, 1341 int num_args,
1339 const char** arg_names, 1342 const char** arg_names,
1340 const unsigned char* arg_types, 1343 const unsigned char* arg_types,
1341 const unsigned long long* arg_values, 1344 const unsigned long long* arg_values,
1342 std::unique_ptr<ConvertableToTraceFormat>* convertable_values, 1345 std::unique_ptr<ConvertableToTraceFormat>* convertable_values,
1343 unsigned int flags) { 1346 unsigned int flags) {
1347 HEAP_PROFILER_SCOPED_IGNORE;
1344 std::unique_ptr<TraceEvent> trace_event(new TraceEvent); 1348 std::unique_ptr<TraceEvent> trace_event(new TraceEvent);
1345 int thread_id = static_cast<int>(base::PlatformThread::CurrentId()); 1349 int thread_id = static_cast<int>(base::PlatformThread::CurrentId());
1346 ThreadTicks thread_now = ThreadNow(); 1350 ThreadTicks thread_now = ThreadNow();
1347 TimeTicks now = OffsetNow(); 1351 TimeTicks now = OffsetNow();
1348 AutoLock lock(lock_); 1352 AutoLock lock(lock_);
1349 trace_event->Initialize( 1353 trace_event->Initialize(
1350 thread_id, now, thread_now, TRACE_EVENT_PHASE_METADATA, 1354 thread_id, now, thread_now, TRACE_EVENT_PHASE_METADATA,
1351 category_group_enabled, name, 1355 category_group_enabled, name,
1352 trace_event_internal::kGlobalScope, // scope 1356 trace_event_internal::kGlobalScope, // scope
1353 trace_event_internal::kNoId, // id 1357 trace_event_internal::kNoId, // id
1354 trace_event_internal::kNoId, // bind_id 1358 trace_event_internal::kNoId, // bind_id
1355 num_args, arg_names, arg_types, arg_values, convertable_values, flags); 1359 num_args, arg_names, arg_types, arg_values, convertable_values, flags);
1356 metadata_events_.push_back(std::move(trace_event)); 1360 metadata_events_.push_back(std::move(trace_event));
1357 } 1361 }
1358 1362
1359 // May be called when a COMPELETE event ends and the unfinished event has been 1363 // May be called when a COMPELETE event ends and the unfinished event has been
1360 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL). 1364 // recycled (phase == TRACE_EVENT_PHASE_END and trace_event == NULL).
1361 std::string TraceLog::EventToConsoleMessage(unsigned char phase, 1365 std::string TraceLog::EventToConsoleMessage(unsigned char phase,
1362 const TimeTicks& timestamp, 1366 const TimeTicks& timestamp,
1363 TraceEvent* trace_event) { 1367 TraceEvent* trace_event) {
1368 HEAP_PROFILER_SCOPED_IGNORE;
1364 AutoLock thread_info_lock(thread_info_lock_); 1369 AutoLock thread_info_lock(thread_info_lock_);
1365 1370
1366 // The caller should translate TRACE_EVENT_PHASE_COMPLETE to 1371 // The caller should translate TRACE_EVENT_PHASE_COMPLETE to
1367 // TRACE_EVENT_PHASE_BEGIN or TRACE_EVENT_END. 1372 // TRACE_EVENT_PHASE_BEGIN or TRACE_EVENT_END.
1368 DCHECK(phase != TRACE_EVENT_PHASE_COMPLETE); 1373 DCHECK(phase != TRACE_EVENT_PHASE_COMPLETE);
1369 1374
1370 TimeDelta duration; 1375 TimeDelta duration;
1371 int thread_id = 1376 int thread_id =
1372 trace_event ? trace_event->thread_id() : PlatformThread::CurrentId(); 1377 trace_event ? trace_event->thread_id() : PlatformThread::CurrentId();
1373 if (phase == TRACE_EVENT_PHASE_END) { 1378 if (phase == TRACE_EVENT_PHASE_END) {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 1662
1658 void TraceLog::SetCurrentThreadBlocksMessageLoop() { 1663 void TraceLog::SetCurrentThreadBlocksMessageLoop() {
1659 thread_blocks_message_loop_.Set(true); 1664 thread_blocks_message_loop_.Set(true);
1660 if (thread_local_event_buffer_.Get()) { 1665 if (thread_local_event_buffer_.Get()) {
1661 // This will flush the thread local buffer. 1666 // This will flush the thread local buffer.
1662 delete thread_local_event_buffer_.Get(); 1667 delete thread_local_event_buffer_.Get();
1663 } 1668 }
1664 } 1669 }
1665 1670
1666 TraceBuffer* TraceLog::CreateTraceBuffer() { 1671 TraceBuffer* TraceLog::CreateTraceBuffer() {
1672 HEAP_PROFILER_SCOPED_IGNORE;
1667 InternalTraceOptions options = trace_options(); 1673 InternalTraceOptions options = trace_options();
1668 if (options & kInternalRecordContinuously) 1674 if (options & kInternalRecordContinuously)
1669 return TraceBuffer::CreateTraceBufferRingBuffer( 1675 return TraceBuffer::CreateTraceBufferRingBuffer(
1670 kTraceEventRingBufferChunks); 1676 kTraceEventRingBufferChunks);
1671 else if (options & kInternalEchoToConsole) 1677 else if (options & kInternalEchoToConsole)
1672 return TraceBuffer::CreateTraceBufferRingBuffer( 1678 return TraceBuffer::CreateTraceBufferRingBuffer(
1673 kEchoToConsoleTraceEventBufferChunks); 1679 kEchoToConsoleTraceEventBufferChunks);
1674 else if (options & kInternalRecordAsMuchAsPossible) 1680 else if (options & kInternalRecordAsMuchAsPossible)
1675 return TraceBuffer::CreateTraceBufferVectorOfSize( 1681 return TraceBuffer::CreateTraceBufferVectorOfSize(
1676 kTraceEventVectorBigBufferChunks); 1682 kTraceEventVectorBigBufferChunks);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1736 } 1742 }
1737 1743
1738 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { 1744 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() {
1739 if (*category_group_enabled_) { 1745 if (*category_group_enabled_) {
1740 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_, 1746 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, name_,
1741 event_handle_); 1747 event_handle_);
1742 } 1748 }
1743 } 1749 }
1744 1750
1745 } // namespace trace_event_internal 1751 } // namespace trace_event_internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698