OLD | NEW |
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 "components/metrics/profiler/profiler_metrics_provider.h" | 5 #include "components/metrics/profiler/profiler_metrics_provider.h" |
6 | 6 |
7 #include <ctype.h> | |
8 #include <stddef.h> | 7 #include <stddef.h> |
9 #include <string> | 8 #include <string> |
10 #include <vector> | 9 #include <vector> |
11 | 10 |
12 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
13 #include "base/tracked_objects.h" | 12 #include "base/tracked_objects.h" |
14 #include "components/metrics/metrics_log.h" | 13 #include "components/metrics/metrics_log.h" |
15 | 14 |
16 namespace metrics { | 15 namespace metrics { |
17 namespace { | 16 namespace { |
18 | 17 |
19 // Maps a thread name by replacing trailing sequence of digits with "*". | |
20 // Examples: | |
21 // 1. "BrowserBlockingWorker1/23857" => "BrowserBlockingWorker1/*" | |
22 // 2. "Chrome_IOThread" => "Chrome_IOThread" | |
23 std::string MapThreadName(const std::string& thread_name) { | |
24 size_t i = thread_name.length(); | |
25 | |
26 while (i > 0 && isdigit(thread_name[i - 1])) { | |
27 --i; | |
28 } | |
29 | |
30 if (i == thread_name.length()) | |
31 return thread_name; | |
32 | |
33 return thread_name.substr(0, i) + '*'; | |
34 } | |
35 | |
36 // Normalizes a source filename (which is platform- and build-method-dependent) | 18 // Normalizes a source filename (which is platform- and build-method-dependent) |
37 // by extracting the last component of the full file name. | 19 // by extracting the last component of the full file name. |
38 // Example: "c:\b\build\slave\win\build\src\chrome\app\chrome_main.cc" => | 20 // Example: "c:\b\build\slave\win\build\src\chrome\app\chrome_main.cc" => |
39 // "chrome_main.cc". | 21 // "chrome_main.cc". |
40 std::string NormalizeFileName(const std::string& file_name) { | 22 std::string NormalizeFileName(const std::string& file_name) { |
41 const size_t offset = file_name.find_last_of("\\/"); | 23 const size_t offset = file_name.find_last_of("\\/"); |
42 return offset != std::string::npos ? file_name.substr(offset + 1) : file_name; | 24 return offset != std::string::npos ? file_name.substr(offset + 1) : file_name; |
43 } | 25 } |
44 | 26 |
45 void WriteProfilerData( | 27 void WriteProfilerData( |
46 const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase, | 28 const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase, |
47 base::ProcessId process_id, | 29 base::ProcessId process_id, |
48 ProfilerEventProto::TrackedObject::ProcessType process_type, | 30 ProfilerEventProto::TrackedObject::ProcessType process_type, |
49 ProfilerEventProto* performance_profile) { | 31 ProfilerEventProto* performance_profile) { |
50 for (const auto& task : process_data_phase.tasks) { | 32 for (const auto& task : process_data_phase.tasks) { |
51 const tracked_objects::DeathDataSnapshot& death_data = task.death_data; | 33 const tracked_objects::DeathDataSnapshot& death_data = task.death_data; |
52 ProfilerEventProto::TrackedObject* tracked_object = | 34 ProfilerEventProto::TrackedObject* tracked_object = |
53 performance_profile->add_tracked_object(); | 35 performance_profile->add_tracked_object(); |
54 tracked_object->set_birth_thread_name_hash( | 36 tracked_object->set_birth_thread_name_hash( |
55 MetricsLog::Hash(MapThreadName(task.birth.thread_name))); | 37 MetricsLog::Hash(task.birth.thread_name)); |
56 tracked_object->set_exec_thread_name_hash( | 38 tracked_object->set_exec_thread_name_hash( |
57 MetricsLog::Hash(MapThreadName(task.death_thread_name))); | 39 MetricsLog::Hash(task.death_thread_name)); |
58 tracked_object->set_source_file_name_hash( | 40 tracked_object->set_source_file_name_hash( |
59 MetricsLog::Hash(NormalizeFileName(task.birth.location.file_name))); | 41 MetricsLog::Hash(NormalizeFileName(task.birth.location.file_name))); |
60 tracked_object->set_source_function_name_hash( | 42 tracked_object->set_source_function_name_hash( |
61 MetricsLog::Hash(task.birth.location.function_name)); | 43 MetricsLog::Hash(task.birth.location.function_name)); |
62 tracked_object->set_source_line_number(task.birth.location.line_number); | 44 tracked_object->set_source_line_number(task.birth.location.line_number); |
63 tracked_object->set_exec_count(death_data.count); | 45 tracked_object->set_exec_count(death_data.count); |
64 tracked_object->set_exec_time_total(death_data.run_duration_sum); | 46 tracked_object->set_exec_time_total(death_data.run_duration_sum); |
65 tracked_object->set_exec_time_sampled(death_data.run_duration_sample); | 47 tracked_object->set_exec_time_sampled(death_data.run_duration_sample); |
66 tracked_object->set_queue_time_total(death_data.queue_duration_sum); | 48 tracked_object->set_queue_time_total(death_data.queue_duration_sum); |
67 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample); | 49 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 109 } |
128 | 110 |
129 bool ProfilerMetricsProvider::IsCellularLogicEnabled() { | 111 bool ProfilerMetricsProvider::IsCellularLogicEnabled() { |
130 if (cellular_callback_.is_null()) | 112 if (cellular_callback_.is_null()) |
131 return false; | 113 return false; |
132 | 114 |
133 return cellular_callback_.Run(); | 115 return cellular_callback_.Run(); |
134 } | 116 } |
135 | 117 |
136 } // namespace metrics | 118 } // namespace metrics |
OLD | NEW |