| 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 "chrome/browser/metrics/profiler_metrics_provider.h" | 5 #include "components/metrics/profiler/profiler_metrics_provider.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/tracked_objects.h" | 11 #include "base/tracked_objects.h" |
| 12 #include "components/metrics/metrics_log.h" | 12 #include "components/metrics/metrics_log.h" |
| 13 #include "components/nacl/common/nacl_process_type.h" | 13 #include "components/nacl/common/nacl_process_type.h" |
| 14 #include "content/public/common/process_type.h" | 14 #include "content/public/common/process_type.h" |
| 15 | 15 |
| 16 using metrics::ProfilerEventProto; | |
| 17 using tracked_objects::ProcessDataSnapshot; | 16 using tracked_objects::ProcessDataSnapshot; |
| 18 | 17 |
| 18 namespace metrics { |
| 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType( | 22 ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType( |
| 22 int process_type) { | 23 int process_type) { |
| 23 switch (process_type) { | 24 switch (process_type) { |
| 24 case content::PROCESS_TYPE_BROWSER: | 25 case content::PROCESS_TYPE_BROWSER: |
| 25 return ProfilerEventProto::TrackedObject::BROWSER; | 26 return ProfilerEventProto::TrackedObject::BROWSER; |
| 26 case content::PROCESS_TYPE_RENDERER: | 27 case content::PROCESS_TYPE_RENDERER: |
| 27 return ProfilerEventProto::TrackedObject::RENDERER; | 28 return ProfilerEventProto::TrackedObject::RENDERER; |
| 28 case content::PROCESS_TYPE_PLUGIN: | 29 case content::PROCESS_TYPE_PLUGIN: |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 int process_type, | 80 int process_type, |
| 80 ProfilerEventProto* performance_profile) { | 81 ProfilerEventProto* performance_profile) { |
| 81 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it = | 82 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it = |
| 82 profiler_data.tasks.begin(); | 83 profiler_data.tasks.begin(); |
| 83 it != profiler_data.tasks.end(); | 84 it != profiler_data.tasks.end(); |
| 84 ++it) { | 85 ++it) { |
| 85 const tracked_objects::DeathDataSnapshot& death_data = it->death_data; | 86 const tracked_objects::DeathDataSnapshot& death_data = it->death_data; |
| 86 ProfilerEventProto::TrackedObject* tracked_object = | 87 ProfilerEventProto::TrackedObject* tracked_object = |
| 87 performance_profile->add_tracked_object(); | 88 performance_profile->add_tracked_object(); |
| 88 tracked_object->set_birth_thread_name_hash( | 89 tracked_object->set_birth_thread_name_hash( |
| 89 metrics::MetricsLog::Hash(MapThreadName(it->birth.thread_name))); | 90 MetricsLog::Hash(MapThreadName(it->birth.thread_name))); |
| 90 tracked_object->set_exec_thread_name_hash( | 91 tracked_object->set_exec_thread_name_hash( |
| 91 metrics::MetricsLog::Hash(MapThreadName(it->death_thread_name))); | 92 MetricsLog::Hash(MapThreadName(it->death_thread_name))); |
| 92 tracked_object->set_source_file_name_hash( | 93 tracked_object->set_source_file_name_hash( |
| 93 metrics::MetricsLog::Hash(NormalizeFileName( | 94 MetricsLog::Hash(NormalizeFileName( |
| 94 it->birth.location.file_name))); | 95 it->birth.location.file_name))); |
| 95 tracked_object->set_source_function_name_hash( | 96 tracked_object->set_source_function_name_hash( |
| 96 metrics::MetricsLog::Hash(it->birth.location.function_name)); | 97 MetricsLog::Hash(it->birth.location.function_name)); |
| 97 tracked_object->set_source_line_number(it->birth.location.line_number); | 98 tracked_object->set_source_line_number(it->birth.location.line_number); |
| 98 tracked_object->set_exec_count(death_data.count); | 99 tracked_object->set_exec_count(death_data.count); |
| 99 tracked_object->set_exec_time_total(death_data.run_duration_sum); | 100 tracked_object->set_exec_time_total(death_data.run_duration_sum); |
| 100 tracked_object->set_exec_time_sampled(death_data.run_duration_sample); | 101 tracked_object->set_exec_time_sampled(death_data.run_duration_sample); |
| 101 tracked_object->set_queue_time_total(death_data.queue_duration_sum); | 102 tracked_object->set_queue_time_total(death_data.queue_duration_sum); |
| 102 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample); | 103 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample); |
| 103 tracked_object->set_process_type(AsProtobufProcessType(process_type)); | 104 tracked_object->set_process_type(AsProtobufProcessType(process_type)); |
| 104 tracked_object->set_process_id(profiler_data.process_id); | 105 tracked_object->set_process_id(profiler_data.process_id); |
| 105 } | 106 } |
| 106 } | 107 } |
| 107 | 108 |
| 108 } // namespace | 109 } // namespace |
| 109 | 110 |
| 110 ProfilerMetricsProvider::ProfilerMetricsProvider() : has_profiler_data_(false) { | 111 ProfilerMetricsProvider::ProfilerMetricsProvider() : has_profiler_data_(false) { |
| 111 } | 112 } |
| 112 | 113 |
| 113 ProfilerMetricsProvider::~ProfilerMetricsProvider() { | 114 ProfilerMetricsProvider::~ProfilerMetricsProvider() { |
| 114 } | 115 } |
| 115 | 116 |
| 116 void ProfilerMetricsProvider::ProvideGeneralMetrics( | 117 void ProfilerMetricsProvider::ProvideGeneralMetrics( |
| 117 metrics::ChromeUserMetricsExtension* uma_proto) { | 118 ChromeUserMetricsExtension* uma_proto) { |
| 118 if (!has_profiler_data_) | 119 if (!has_profiler_data_) |
| 119 return; | 120 return; |
| 120 | 121 |
| 121 DCHECK_EQ(tracked_objects::TIME_SOURCE_TYPE_WALL_TIME, | 122 DCHECK_EQ(tracked_objects::TIME_SOURCE_TYPE_WALL_TIME, |
| 122 tracked_objects::GetTimeSourceType()); | 123 tracked_objects::GetTimeSourceType()); |
| 123 | 124 |
| 124 DCHECK_EQ(0, uma_proto->profiler_event_size()); | 125 DCHECK_EQ(0, uma_proto->profiler_event_size()); |
| 125 ProfilerEventProto* profile = uma_proto->add_profiler_event(); | 126 ProfilerEventProto* profile = uma_proto->add_profiler_event(); |
| 126 profile->Swap(&profiler_event_cache_); | 127 profile->Swap(&profiler_event_cache_); |
| 127 has_profiler_data_ = false; | 128 has_profiler_data_ = false; |
| 128 } | 129 } |
| 129 | 130 |
| 130 void ProfilerMetricsProvider::RecordProfilerData( | 131 void ProfilerMetricsProvider::RecordProfilerData( |
| 131 const tracked_objects::ProcessDataSnapshot& process_data, | 132 const tracked_objects::ProcessDataSnapshot& process_data, |
| 132 int process_type) { | 133 int process_type) { |
| 133 if (tracked_objects::GetTimeSourceType() != | 134 if (tracked_objects::GetTimeSourceType() != |
| 134 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) { | 135 tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) { |
| 135 // We currently only support the default time source, wall clock time. | 136 // We currently only support the default time source, wall clock time. |
| 136 return; | 137 return; |
| 137 } | 138 } |
| 138 | 139 |
| 139 has_profiler_data_ = true; | 140 has_profiler_data_ = true; |
| 140 profiler_event_cache_.set_profile_type(ProfilerEventProto::STARTUP_PROFILE); | 141 profiler_event_cache_.set_profile_type(ProfilerEventProto::STARTUP_PROFILE); |
| 141 profiler_event_cache_.set_time_source(ProfilerEventProto::WALL_CLOCK_TIME); | 142 profiler_event_cache_.set_time_source(ProfilerEventProto::WALL_CLOCK_TIME); |
| 142 WriteProfilerData(process_data, process_type, &profiler_event_cache_); | 143 WriteProfilerData(process_data, process_type, &profiler_event_cache_); |
| 143 } | 144 } |
| 145 |
| 146 } // namespace metrics |
| OLD | NEW |