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