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

Side by Side Diff: chrome/browser/metrics/metrics_log.cc

Issue 9702015: [UMA] Add performance profile data to UMA uploads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Be careful with the time source Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/metrics_log.h" 5 #include "chrome/browser/metrics/metrics_log.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/perftimer.h" 14 #include "base/perftimer.h"
15 #include "base/profiler/alternate_timer.h"
15 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
16 #include "base/string_util.h" 17 #include "base/string_util.h"
17 #include "base/sys_info.h" 18 #include "base/sys_info.h"
18 #include "base/third_party/nspr/prtime.h" 19 #include "base/third_party/nspr/prtime.h"
19 #include "base/time.h" 20 #include "base/time.h"
21 #include "base/tracked_objects.h"
20 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
21 #include "chrome/browser/autocomplete/autocomplete.h" 23 #include "chrome/browser/autocomplete/autocomplete.h"
22 #include "chrome/browser/autocomplete/autocomplete_match.h" 24 #include "chrome/browser/autocomplete/autocomplete_match.h"
23 #include "chrome/browser/browser_process.h" 25 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/plugin_prefs.h" 26 #include "chrome/browser/plugin_prefs.h"
25 #include "chrome/browser/prefs/pref_service.h" 27 #include "chrome/browser/prefs/pref_service.h"
26 #include "chrome/browser/profiles/profile_manager.h" 28 #include "chrome/browser/profiles/profile_manager.h"
27 #include "chrome/common/chrome_version_info.h" 29 #include "chrome/common/chrome_version_info.h"
28 #include "chrome/common/logging_chrome.h" 30 #include "chrome/common/logging_chrome.h"
29 #include "chrome/common/metrics/proto/omnibox_event.pb.h" 31 #include "chrome/common/metrics/proto/omnibox_event.pb.h"
32 #include "chrome/common/metrics/proto/profiler_event.pb.h"
30 #include "chrome/common/metrics/proto/system_profile.pb.h" 33 #include "chrome/common/metrics/proto/system_profile.pb.h"
31 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
32 #include "content/public/browser/content_browser_client.h" 35 #include "content/public/browser/content_browser_client.h"
33 #include "content/public/browser/gpu_data_manager.h" 36 #include "content/public/browser/gpu_data_manager.h"
37 #include "content/public/common/content_client.h"
34 #include "content/public/common/gpu_info.h" 38 #include "content/public/common/gpu_info.h"
35 #include "content/public/common/content_client.h"
36 #include "googleurl/src/gurl.h" 39 #include "googleurl/src/gurl.h"
37 #include "ui/gfx/screen.h" 40 #include "ui/gfx/screen.h"
38 #include "webkit/plugins/webplugininfo.h" 41 #include "webkit/plugins/webplugininfo.h"
39 42
40 #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) 43 #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
41 44
42 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx 45 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
43 #if defined(OS_WIN) 46 #if defined(OS_WIN)
44 extern "C" IMAGE_DOS_HEADER __ImageBase; 47 extern "C" IMAGE_DOS_HEADER __ImageBase;
45 #endif 48 #endif
46 49
47 using content::GpuDataManager; 50 using content::GpuDataManager;
48 using metrics::OmniboxEventProto; 51 using metrics::OmniboxEventProto;
52 using metrics::ProfilerEventProto;
49 using metrics::SystemProfileProto; 53 using metrics::SystemProfileProto;
54 using tracked_objects::ProcessDataSnapshot;
50 typedef base::FieldTrial::NameGroupId NameGroupId; 55 typedef base::FieldTrial::NameGroupId NameGroupId;
51 56
52 namespace { 57 namespace {
53 58
54 // Returns the date at which the current metrics client ID was created as 59 // Returns the date at which the current metrics client ID was created as
55 // a string containing milliseconds since the epoch, or "0" if none was found. 60 // a string containing milliseconds since the epoch, or "0" if none was found.
56 std::string GetInstallDate(PrefService* pref) { 61 std::string GetInstallDate(PrefService* pref) {
57 if (!pref) { 62 if (!pref) {
58 NOTREACHED(); 63 NOTREACHED();
59 return "0"; 64 return "0";
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 case AutocompleteMatch::SEARCH_OTHER_ENGINE: 139 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
135 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE; 140 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
136 case AutocompleteMatch::EXTENSION_APP: 141 case AutocompleteMatch::EXTENSION_APP:
137 return OmniboxEventProto::Suggestion::EXTENSION_APP; 142 return OmniboxEventProto::Suggestion::EXTENSION_APP;
138 default: 143 default:
139 NOTREACHED(); 144 NOTREACHED();
140 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE; 145 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
141 } 146 }
142 } 147 }
143 148
149 ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
150 content::ProcessType process_type) {
151 switch (process_type) {
152 case content::PROCESS_TYPE_BROWSER:
153 return ProfilerEventProto::TrackedObject::BROWSER;
154 case content::PROCESS_TYPE_RENDERER:
155 return ProfilerEventProto::TrackedObject::RENDERER;
156 case content::PROCESS_TYPE_PLUGIN:
157 return ProfilerEventProto::TrackedObject::PLUGIN;
158 case content::PROCESS_TYPE_WORKER:
159 return ProfilerEventProto::TrackedObject::WORKER;
160 case content::PROCESS_TYPE_NACL_LOADER:
161 return ProfilerEventProto::TrackedObject::NACL_LOADER;
162 case content::PROCESS_TYPE_UTILITY:
163 return ProfilerEventProto::TrackedObject::UTILITY;
164 case content::PROCESS_TYPE_PROFILE_IMPORT:
165 return ProfilerEventProto::TrackedObject::PROFILE_IMPORT;
166 case content::PROCESS_TYPE_ZYGOTE:
167 return ProfilerEventProto::TrackedObject::ZYGOTE;
168 case content::PROCESS_TYPE_SANDBOX_HELPER:
169 return ProfilerEventProto::TrackedObject::SANDBOX_HELPER;
170 case content::PROCESS_TYPE_NACL_BROKER:
171 return ProfilerEventProto::TrackedObject::NACL_BROKER;
172 case content::PROCESS_TYPE_GPU:
173 return ProfilerEventProto::TrackedObject::GPU;
174 case content::PROCESS_TYPE_PPAPI_PLUGIN:
175 return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN;
176 case content::PROCESS_TYPE_PPAPI_BROKER:
177 return ProfilerEventProto::TrackedObject::PPAPI_BROKER;
178 default:
179 NOTREACHED();
180 return ProfilerEventProto::TrackedObject::UNKNOWN;
181 }
182 }
183
144 // Returns the plugin preferences corresponding for this user, if available. 184 // Returns the plugin preferences corresponding for this user, if available.
145 // If multiple user profiles are loaded, returns the preferences corresponding 185 // If multiple user profiles are loaded, returns the preferences corresponding
146 // to an arbitrary one of the profiles. 186 // to an arbitrary one of the profiles.
147 PluginPrefs* GetPluginPrefs() { 187 PluginPrefs* GetPluginPrefs() {
148 ProfileManager* profile_manager = g_browser_process->profile_manager(); 188 ProfileManager* profile_manager = g_browser_process->profile_manager();
149 189
150 if (!profile_manager) { 190 if (!profile_manager) {
151 // The profile manager can be NULL when testing. 191 // The profile manager can be NULL when testing.
152 return NULL; 192 return NULL;
153 } 193 }
(...skipping 20 matching lines...) Expand all
174 SystemProfileProto* system_profile) { 214 SystemProfileProto* system_profile) {
175 for (std::vector<NameGroupId>::const_iterator it = field_trial_ids.begin(); 215 for (std::vector<NameGroupId>::const_iterator it = field_trial_ids.begin();
176 it != field_trial_ids.end(); ++it) { 216 it != field_trial_ids.end(); ++it) {
177 SystemProfileProto::FieldTrial* field_trial = 217 SystemProfileProto::FieldTrial* field_trial =
178 system_profile->add_field_trial(); 218 system_profile->add_field_trial();
179 field_trial->set_name_id(it->name); 219 field_trial->set_name_id(it->name);
180 field_trial->set_group_id(it->group); 220 field_trial->set_group_id(it->group);
181 } 221 }
182 } 222 }
183 223
224 void WriteProfilerData(const ProcessDataSnapshot& profiler_data,
225 content::ProcessType process_type,
226 ProfilerEventProto* performance_profile) {
227 for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it =
228 profiler_data.tasks.begin();
229 it != profiler_data.tasks.end(); ++it) {
230 std::string ignored;
231 uint64 birth_thread_name_hash;
232 uint64 exec_thread_name_hash;
233 uint64 source_file_name_hash;
234 uint64 source_function_name_hash;
235 MetricsLogBase::CreateHashes(it->birth.thread_name,
236 &ignored, &birth_thread_name_hash);
237 MetricsLogBase::CreateHashes(it->death_thread_name,
238 &ignored, &exec_thread_name_hash);
239 MetricsLogBase::CreateHashes(it->birth.location.function_name,
240 &ignored, &source_file_name_hash);
241 MetricsLogBase::CreateHashes(it->birth.location.file_name,
242 &ignored, &source_function_name_hash);
243
244 const tracked_objects::DeathDataSnapshot& death_data = it->death_data;
245 ProfilerEventProto::TrackedObject* tracked_object =
246 performance_profile->add_tracked_object();
247 tracked_object->set_birth_thread_name_hash(birth_thread_name_hash);
248 tracked_object->set_exec_thread_name_hash(exec_thread_name_hash);
249 tracked_object->set_source_file_name_hash(source_file_name_hash);
250 tracked_object->set_source_function_name_hash(source_function_name_hash);
251 tracked_object->set_source_line_number(it->birth.location.line_number);
252 tracked_object->set_exec_count(death_data.count);
253 tracked_object->set_exec_time_total(death_data.run_duration_sum);
254 tracked_object->set_exec_time_sampled(death_data.run_duration_sample);
255 tracked_object->set_queue_time_total(death_data.queue_duration_sum);
256 tracked_object->set_queue_time_sampled(death_data.queue_duration_sample);
257 tracked_object->set_process_type(AsProtobufProcessType(process_type));
258 tracked_object->set_process_id(profiler_data.process_id);
259 }
260 }
261
184 } // namespace 262 } // namespace
185 263
186 static base::LazyInstance<std::string>::Leaky 264 static base::LazyInstance<std::string>::Leaky
187 g_version_extension = LAZY_INSTANCE_INITIALIZER; 265 g_version_extension = LAZY_INSTANCE_INITIALIZER;
188 266
189 MetricsLog::MetricsLog(const std::string& client_id, int session_id) 267 MetricsLog::MetricsLog(const std::string& client_id, int session_id)
190 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {} 268 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
191 269
192 MetricsLog::~MetricsLog() {} 270 MetricsLog::~MetricsLog() {}
193 271
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 hardware->set_screen_count(GetScreenCount()); 775 hardware->set_screen_count(GetScreenCount());
698 776
699 bool write_as_xml = false; 777 bool write_as_xml = false;
700 WritePluginList(plugin_list, write_as_xml); 778 WritePluginList(plugin_list, write_as_xml);
701 779
702 std::vector<NameGroupId> field_trial_ids; 780 std::vector<NameGroupId> field_trial_ids;
703 GetFieldTrialIds(&field_trial_ids); 781 GetFieldTrialIds(&field_trial_ids);
704 WriteFieldTrials(field_trial_ids, system_profile); 782 WriteFieldTrials(field_trial_ids, system_profile);
705 } 783 }
706 784
785 void MetricsLog::RecordProfilerData(
786 const tracked_objects::ProcessDataSnapshot& process_data,
787 content::ProcessType process_type) {
788 DCHECK(!locked());
789
790 if (tracked_objects::GetAlternateTimeSource()) {
791 // We currently only support the default time source, wall clock time.
792 return;
793 }
794
795 ProfilerEventProto* profile;
796 if (!uma_proto()->profiler_event_size()) {
797 // For the first process's data, add a new field to the protocol buffer.
798 profile = uma_proto()->add_profiler_event();
799 profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE);
800 profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME);
801 } else {
802 // For the remaining calls, re-use the existing field.
803 profile = uma_proto()->mutable_profiler_event(0);
804 }
805
806 WriteProfilerData(process_data, process_type, profile);
807 }
808
707 void MetricsLog::WriteAllProfilesMetrics( 809 void MetricsLog::WriteAllProfilesMetrics(
708 const DictionaryValue& all_profiles_metrics) { 810 const DictionaryValue& all_profiles_metrics) {
709 const std::string profile_prefix(prefs::kProfilePrefix); 811 const std::string profile_prefix(prefs::kProfilePrefix);
710 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys(); 812 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
711 i != all_profiles_metrics.end_keys(); ++i) { 813 i != all_profiles_metrics.end_keys(); ++i) {
712 const std::string& key_name = *i; 814 const std::string& key_name = *i;
713 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) { 815 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
714 DictionaryValue* profile; 816 DictionaryValue* profile;
715 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name, 817 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
716 &profile)) 818 &profile))
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 i != log.result.end(); ++i) { 933 i != log.result.end(); ++i) {
832 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion(); 934 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
833 suggestion->set_provider(AsOmniboxEventProviderType(i->provider)); 935 suggestion->set_provider(AsOmniboxEventProviderType(i->provider));
834 suggestion->set_result_type(AsOmniboxEventResultType(i->type)); 936 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
835 suggestion->set_relevance(i->relevance); 937 suggestion->set_relevance(i->relevance);
836 suggestion->set_is_starred(i->starred); 938 suggestion->set_is_starred(i->starred);
837 } 939 }
838 940
839 ++num_events_; 941 ++num_events_;
840 } 942 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698