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

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

Issue 10169039: Revert 133773 - [UMA] Add performance profile data to UMA uploads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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
« no previous file with comments | « chrome/browser/metrics/metrics_log.h ('k') | chrome/browser/metrics/metrics_log_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
16 #include "base/string_number_conversions.h" 15 #include "base/string_number_conversions.h"
17 #include "base/string_util.h" 16 #include "base/string_util.h"
18 #include "base/sys_info.h" 17 #include "base/sys_info.h"
19 #include "base/third_party/nspr/prtime.h" 18 #include "base/third_party/nspr/prtime.h"
20 #include "base/time.h" 19 #include "base/time.h"
21 #include "base/tracked_objects.h"
22 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
23 #include "chrome/browser/autocomplete/autocomplete.h" 21 #include "chrome/browser/autocomplete/autocomplete.h"
24 #include "chrome/browser/autocomplete/autocomplete_match.h" 22 #include "chrome/browser/autocomplete/autocomplete_match.h"
25 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/plugin_prefs.h" 24 #include "chrome/browser/plugin_prefs.h"
27 #include "chrome/browser/prefs/pref_service.h" 25 #include "chrome/browser/prefs/pref_service.h"
28 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
29 #include "chrome/common/chrome_version_info.h" 27 #include "chrome/common/chrome_version_info.h"
30 #include "chrome/common/logging_chrome.h" 28 #include "chrome/common/logging_chrome.h"
31 #include "chrome/common/metrics/proto/omnibox_event.pb.h" 29 #include "chrome/common/metrics/proto/omnibox_event.pb.h"
32 #include "chrome/common/metrics/proto/profiler_event.pb.h"
33 #include "chrome/common/metrics/proto/system_profile.pb.h" 30 #include "chrome/common/metrics/proto/system_profile.pb.h"
34 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
35 #include "content/public/browser/content_browser_client.h" 32 #include "content/public/browser/content_browser_client.h"
36 #include "content/public/browser/gpu_data_manager.h" 33 #include "content/public/browser/gpu_data_manager.h"
34 #include "content/public/common/gpu_info.h"
37 #include "content/public/common/content_client.h" 35 #include "content/public/common/content_client.h"
38 #include "content/public/common/gpu_info.h"
39 #include "googleurl/src/gurl.h" 36 #include "googleurl/src/gurl.h"
40 #include "ui/gfx/screen.h" 37 #include "ui/gfx/screen.h"
41 #include "webkit/plugins/webplugininfo.h" 38 #include "webkit/plugins/webplugininfo.h"
42 39
43 #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) 40 #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name)
44 41
45 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx 42 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
46 #if defined(OS_WIN) 43 #if defined(OS_WIN)
47 extern "C" IMAGE_DOS_HEADER __ImageBase; 44 extern "C" IMAGE_DOS_HEADER __ImageBase;
48 #endif 45 #endif
49 46
50 using content::GpuDataManager; 47 using content::GpuDataManager;
51 using metrics::OmniboxEventProto; 48 using metrics::OmniboxEventProto;
52 using metrics::ProfilerEventProto;
53 using metrics::SystemProfileProto; 49 using metrics::SystemProfileProto;
54 using tracked_objects::ProcessDataSnapshot;
55 typedef base::FieldTrial::NameGroupId NameGroupId; 50 typedef base::FieldTrial::NameGroupId NameGroupId;
56 51
57 namespace { 52 namespace {
58 53
59 // Returns the date at which the current metrics client ID was created as 54 // Returns the date at which the current metrics client ID was created as
60 // a string containing milliseconds since the epoch, or "0" if none was found. 55 // a string containing milliseconds since the epoch, or "0" if none was found.
61 std::string GetInstallDate(PrefService* pref) { 56 std::string GetInstallDate(PrefService* pref) {
62 if (!pref) { 57 if (!pref) {
63 NOTREACHED(); 58 NOTREACHED();
64 return "0"; 59 return "0";
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 case AutocompleteMatch::SEARCH_OTHER_ENGINE: 134 case AutocompleteMatch::SEARCH_OTHER_ENGINE:
140 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE; 135 return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
141 case AutocompleteMatch::EXTENSION_APP: 136 case AutocompleteMatch::EXTENSION_APP:
142 return OmniboxEventProto::Suggestion::EXTENSION_APP; 137 return OmniboxEventProto::Suggestion::EXTENSION_APP;
143 default: 138 default:
144 NOTREACHED(); 139 NOTREACHED();
145 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE; 140 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
146 } 141 }
147 } 142 }
148 143
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
184 // Returns the plugin preferences corresponding for this user, if available. 144 // Returns the plugin preferences corresponding for this user, if available.
185 // If multiple user profiles are loaded, returns the preferences corresponding 145 // If multiple user profiles are loaded, returns the preferences corresponding
186 // to an arbitrary one of the profiles. 146 // to an arbitrary one of the profiles.
187 PluginPrefs* GetPluginPrefs() { 147 PluginPrefs* GetPluginPrefs() {
188 ProfileManager* profile_manager = g_browser_process->profile_manager(); 148 ProfileManager* profile_manager = g_browser_process->profile_manager();
189 149
190 if (!profile_manager) { 150 if (!profile_manager) {
191 // The profile manager can be NULL when testing. 151 // The profile manager can be NULL when testing.
192 return NULL; 152 return NULL;
193 } 153 }
(...skipping 20 matching lines...) Expand all
214 SystemProfileProto* system_profile) { 174 SystemProfileProto* system_profile) {
215 for (std::vector<NameGroupId>::const_iterator it = field_trial_ids.begin(); 175 for (std::vector<NameGroupId>::const_iterator it = field_trial_ids.begin();
216 it != field_trial_ids.end(); ++it) { 176 it != field_trial_ids.end(); ++it) {
217 SystemProfileProto::FieldTrial* field_trial = 177 SystemProfileProto::FieldTrial* field_trial =
218 system_profile->add_field_trial(); 178 system_profile->add_field_trial();
219 field_trial->set_name_id(it->name); 179 field_trial->set_name_id(it->name);
220 field_trial->set_group_id(it->group); 180 field_trial->set_group_id(it->group);
221 } 181 }
222 } 182 }
223 183
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
262 } // namespace 184 } // namespace
263 185
264 static base::LazyInstance<std::string>::Leaky 186 static base::LazyInstance<std::string>::Leaky
265 g_version_extension = LAZY_INSTANCE_INITIALIZER; 187 g_version_extension = LAZY_INSTANCE_INITIALIZER;
266 188
267 MetricsLog::MetricsLog(const std::string& client_id, int session_id) 189 MetricsLog::MetricsLog(const std::string& client_id, int session_id)
268 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {} 190 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
269 191
270 MetricsLog::~MetricsLog() {} 192 MetricsLog::~MetricsLog() {}
271 193
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 hardware->set_screen_count(GetScreenCount()); 697 hardware->set_screen_count(GetScreenCount());
776 698
777 bool write_as_xml = false; 699 bool write_as_xml = false;
778 WritePluginList(plugin_list, write_as_xml); 700 WritePluginList(plugin_list, write_as_xml);
779 701
780 std::vector<NameGroupId> field_trial_ids; 702 std::vector<NameGroupId> field_trial_ids;
781 GetFieldTrialIds(&field_trial_ids); 703 GetFieldTrialIds(&field_trial_ids);
782 WriteFieldTrials(field_trial_ids, system_profile); 704 WriteFieldTrials(field_trial_ids, system_profile);
783 } 705 }
784 706
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
809 void MetricsLog::WriteAllProfilesMetrics( 707 void MetricsLog::WriteAllProfilesMetrics(
810 const DictionaryValue& all_profiles_metrics) { 708 const DictionaryValue& all_profiles_metrics) {
811 const std::string profile_prefix(prefs::kProfilePrefix); 709 const std::string profile_prefix(prefs::kProfilePrefix);
812 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys(); 710 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
813 i != all_profiles_metrics.end_keys(); ++i) { 711 i != all_profiles_metrics.end_keys(); ++i) {
814 const std::string& key_name = *i; 712 const std::string& key_name = *i;
815 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) { 713 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
816 DictionaryValue* profile; 714 DictionaryValue* profile;
817 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name, 715 if (all_profiles_metrics.GetDictionaryWithoutPathExpansion(key_name,
818 &profile)) 716 &profile))
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 i != log.result.end(); ++i) { 839 i != log.result.end(); ++i) {
942 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion(); 840 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
943 suggestion->set_provider(AsOmniboxEventProviderType(i->provider)); 841 suggestion->set_provider(AsOmniboxEventProviderType(i->provider));
944 suggestion->set_result_type(AsOmniboxEventResultType(i->type)); 842 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
945 suggestion->set_relevance(i->relevance); 843 suggestion->set_relevance(i->relevance);
946 suggestion->set_is_starred(i->starred); 844 suggestion->set_is_starred(i->starred);
947 } 845 }
948 846
949 ++num_events_; 847 ++num_events_;
950 } 848 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_log.h ('k') | chrome/browser/metrics/metrics_log_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698