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

Side by Side Diff: base/debug/task_annotator.cc

Issue 2973543002: Record task durations on Renderer Main & Compositor threads.
Patch Set: Fix layering issues. Created 3 years, 4 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
« no previous file with comments | « no previous file | base/debug/task_annotator_unittest.cc » ('j') | base/tracked_objects.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/debug/task_annotator.h" 5 #include "base/debug/task_annotator.h"
6 6
7 #include <array> 7 #include <array>
8 8
9 #include "base/debug/activity_tracker.h" 9 #include "base/debug/activity_tracker.h"
10 #include "base/debug/alias.h" 10 #include "base/debug/alias.h"
11 #include "base/metrics/histogram_functions.h"
11 #include "base/pending_task.h" 12 #include "base/pending_task.h"
12 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
13 #include "base/tracked_objects.h" 14 #include "base/tracked_objects.h"
14 15
16 namespace {
17
18 void RecordCPUTimeUMA(tracked_objects::ThreadData* thread_data,
19 base::TimeDelta duration) {
20 if (!thread_data)
21 return;
22
23 if (duration.InMillisecondsF() == 0)
24 return;
25
26 if (!thread_data->task_length_recording_enabled_for_uma())
Sami 2017/07/26 20:36:38 Can we swap this before the previous 'if' since th
27 return;
28
29 // TODO - this is slow.
Sami 2017/07/26 20:36:38 TODO(tdresser) In any case we probably can't land
tdresser 2017/07/27 19:18:05 Oops, yeah, I meant to call this out as something
Sami 2017/08/04 15:46:32 Yeah, this is pretty tough from a layering perspec
30 base::UmaHistogramCustomCounts(
31 "Scheduling.TaskTime." + thread_data->sanitized_thread_name(),
32 duration.InMicroseconds(), 1, 1000 * 1000, 50);
33 }
34
35 } // namespace
36
15 namespace base { 37 namespace base {
16 namespace debug { 38 namespace debug {
17 39
18 TaskAnnotator::TaskAnnotator() { 40 TaskAnnotator::TaskAnnotator() {
19 } 41 }
20 42
21 TaskAnnotator::~TaskAnnotator() { 43 TaskAnnotator::~TaskAnnotator() {
22 } 44 }
23 45
24 void TaskAnnotator::DidQueueTask(const char* queue_function, 46 void TaskAnnotator::DidQueueTask(const char* queue_function,
(...skipping 27 matching lines...) Expand all
52 std::tuple_size<decltype(pending_task->task_backtrace)>::value + 1; 74 std::tuple_size<decltype(pending_task->task_backtrace)>::value + 1;
53 std::array<const void*, kStackTaskTraceSnapshotSize> task_backtrace; 75 std::array<const void*, kStackTaskTraceSnapshotSize> task_backtrace;
54 task_backtrace[0] = pending_task->posted_from.program_counter(); 76 task_backtrace[0] = pending_task->posted_from.program_counter();
55 std::copy(pending_task->task_backtrace.begin(), 77 std::copy(pending_task->task_backtrace.begin(),
56 pending_task->task_backtrace.end(), task_backtrace.begin() + 1); 78 pending_task->task_backtrace.end(), task_backtrace.begin() + 1);
57 debug::Alias(&task_backtrace); 79 debug::Alias(&task_backtrace);
58 80
59 std::move(pending_task->task).Run(); 81 std::move(pending_task->task).Run();
60 82
61 stopwatch.Stop(); 83 stopwatch.Stop();
84
85 RecordCPUTimeUMA(stopwatch.GetThreadData(), stopwatch.RunDuration());
86
62 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(*pending_task, 87 tracked_objects::ThreadData::TallyRunOnNamedThreadIfTracking(*pending_task,
63 stopwatch); 88 stopwatch);
64 } 89 }
65 90
66 uint64_t TaskAnnotator::GetTaskTraceID(const PendingTask& task) const { 91 uint64_t TaskAnnotator::GetTaskTraceID(const PendingTask& task) const {
67 return (static_cast<uint64_t>(task.sequence_num) << 32) | 92 return (static_cast<uint64_t>(task.sequence_num) << 32) |
68 ((static_cast<uint64_t>(reinterpret_cast<intptr_t>(this)) << 32) >> 93 ((static_cast<uint64_t>(reinterpret_cast<intptr_t>(this)) << 32) >>
69 32); 94 32);
70 } 95 }
71 96
72 } // namespace debug 97 } // namespace debug
73 } // namespace base 98 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/debug/task_annotator_unittest.cc » ('j') | base/tracked_objects.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698