diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-24 22:06:49 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-24 22:06:49 +0000 |
commit | 1a838cc4824267a5282c6f4eb748e4cb5d8749f4 (patch) | |
tree | 7f7d901b9de92f18cac382cb999a194c0f9322ea | |
parent | 768ff9204ffa2ffc490eeec19236de1921da94aa (diff) | |
download | chromium_src-1a838cc4824267a5282c6f4eb748e4cb5d8749f4.zip chromium_src-1a838cc4824267a5282c6f4eb748e4cb5d8749f4.tar.gz chromium_src-1a838cc4824267a5282c6f4eb748e4cb5d8749f4.tar.bz2 |
Revert 133773 - [UMA] Add performance profile data to UMA uploads.
BUG=103480
TEST=unit_test --gtest_filter=MetricsLogTest.*
Review URL: http://codereview.chromium.org/9702015
TBR=isherman@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10169039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133779 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/profiler/alternate_timer.cc | 15 | ||||
-rw-r--r-- | base/profiler/alternate_timer.h | 21 | ||||
-rw-r--r-- | base/tracked_objects.cc | 18 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_log.cc | 104 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_log.h | 11 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_log_unittest.cc | 133 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_service.cc | 45 | ||||
-rw-r--r-- | chrome/browser/metrics/metrics_service.h | 33 |
8 files changed, 53 insertions, 327 deletions
diff --git a/base/profiler/alternate_timer.cc b/base/profiler/alternate_timer.cc index abf9180..05a983c 100644 --- a/base/profiler/alternate_timer.cc +++ b/base/profiler/alternate_timer.cc @@ -6,25 +6,20 @@ #include "base/logging.h" -namespace { - -tracked_objects::NowFunction* g_time_function = NULL; - -} // anonymous namespace - namespace tracked_objects { +static NowFunction* g_time_function = NULL; + const char kAlternateProfilerTime[] = "CHROME_PROFILER_TIME"; // Set an alternate timer function to replace the OS time function when // profiling. void SetAlternateTimeSource(NowFunction* now_function) { - DCHECK_EQ(reinterpret_cast<NowFunction*>(NULL), g_time_function); + DCHECK_EQ(g_time_function, reinterpret_cast<NowFunction*>(NULL)); g_time_function = now_function; } -NowFunction* GetAlternateTimeSource() { +extern NowFunction* GetAlternateTimeSource() { return g_time_function; } - -} // namespace tracked_objects +} // tracked_objects diff --git a/base/profiler/alternate_timer.h b/base/profiler/alternate_timer.h index 778dc62..883b24f 100644 --- a/base/profiler/alternate_timer.h +++ b/base/profiler/alternate_timer.h @@ -5,31 +5,32 @@ // This is a glue file, which allows third party code to call into our profiler // without having to include most any functions from base. + #ifndef BASE_PROFILER_ALTERNATE_TIMER_H_ #define BASE_PROFILER_ALTERNATE_TIMER_H_ -#include "base/base_export.h" - namespace tracked_objects { // Provide type for an alternate timer function. typedef unsigned int NowFunction(); -// Environment variable name that is used to activate alternate timer profiling -// (such as using TCMalloc allocations to provide a pseudo-timer) for tasks -// instead of wall clock profiling. -extern const char kAlternateProfilerTime[]; - // Set an alternate timer function to replace the OS time function when // profiling. Typically this is called by an allocator that is providing a // function that indicates how much memory has been allocated on any given // thread. -void SetAlternateTimeSource(NowFunction* now_function); +extern void SetAlternateTimeSource(NowFunction* now_function); // Gets the pointer to a function that was set via SetAlternateTimeSource(). // Returns NULL if no set was done prior to calling GetAlternateTimeSource. -BASE_EXPORT NowFunction* GetAlternateTimeSource(); +extern NowFunction* GetAlternateTimeSource(); + +// Environment variable name that is used to activate alternate timer profiling +// (such as using TCMalloc allocations to provide a pseudo-timer) for tasks +// instead of wall clock profiling. +extern const char kAlternateProfilerTime[]; + + -} // namespace tracked_objects +} // tracked_objects #endif // BASE_PROFILER_ALTERNATE_TIMER_H_ diff --git a/base/tracked_objects.cc b/base/tracked_objects.cc index ae508c4..fe3f712 100644 --- a/base/tracked_objects.cc +++ b/base/tracked_objects.cc @@ -648,9 +648,21 @@ void ThreadData::Reset() { } static void OptionallyInitializeAlternateTimer() { - NowFunction* alternate_time_source = GetAlternateTimeSource(); - if (alternate_time_source) - ThreadData::SetAlternateTimeSource(alternate_time_source); + char* alternate_selector = getenv(kAlternateProfilerTime); + if (!alternate_selector) + return; + switch (*alternate_selector) { + case '0': // This is the default value, and uses the wall clock time. + break; + case '1': { + // Use the TCMalloc allocations-on-thread as a pseudo-time. + ThreadData::SetAlternateTimeSource(GetAlternateTimeSource()); + break; + } + default: + NOTREACHED(); + break; + } } bool ThreadData::Initialize() { diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc index 47071fa..58cdfa1 100644 --- a/chrome/browser/metrics/metrics_log.cc +++ b/chrome/browser/metrics/metrics_log.cc @@ -12,13 +12,11 @@ #include "base/lazy_instance.h" #include "base/memory/scoped_ptr.h" #include "base/perftimer.h" -#include "base/profiler/alternate_timer.h" #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/sys_info.h" #include "base/third_party/nspr/prtime.h" #include "base/time.h" -#include "base/tracked_objects.h" #include "base/utf_string_conversions.h" #include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/autocomplete/autocomplete_match.h" @@ -29,13 +27,12 @@ #include "chrome/common/chrome_version_info.h" #include "chrome/common/logging_chrome.h" #include "chrome/common/metrics/proto/omnibox_event.pb.h" -#include "chrome/common/metrics/proto/profiler_event.pb.h" #include "chrome/common/metrics/proto/system_profile.pb.h" #include "chrome/common/pref_names.h" #include "content/public/browser/content_browser_client.h" #include "content/public/browser/gpu_data_manager.h" -#include "content/public/common/content_client.h" #include "content/public/common/gpu_info.h" +#include "content/public/common/content_client.h" #include "googleurl/src/gurl.h" #include "ui/gfx/screen.h" #include "webkit/plugins/webplugininfo.h" @@ -49,9 +46,7 @@ extern "C" IMAGE_DOS_HEADER __ImageBase; using content::GpuDataManager; using metrics::OmniboxEventProto; -using metrics::ProfilerEventProto; using metrics::SystemProfileProto; -using tracked_objects::ProcessDataSnapshot; typedef base::FieldTrial::NameGroupId NameGroupId; namespace { @@ -146,41 +141,6 @@ OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType( } } -ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType( - content::ProcessType process_type) { - switch (process_type) { - case content::PROCESS_TYPE_BROWSER: - return ProfilerEventProto::TrackedObject::BROWSER; - case content::PROCESS_TYPE_RENDERER: - return ProfilerEventProto::TrackedObject::RENDERER; - case content::PROCESS_TYPE_PLUGIN: - return ProfilerEventProto::TrackedObject::PLUGIN; - case content::PROCESS_TYPE_WORKER: - return ProfilerEventProto::TrackedObject::WORKER; - case content::PROCESS_TYPE_NACL_LOADER: - return ProfilerEventProto::TrackedObject::NACL_LOADER; - case content::PROCESS_TYPE_UTILITY: - return ProfilerEventProto::TrackedObject::UTILITY; - case content::PROCESS_TYPE_PROFILE_IMPORT: - return ProfilerEventProto::TrackedObject::PROFILE_IMPORT; - case content::PROCESS_TYPE_ZYGOTE: - return ProfilerEventProto::TrackedObject::ZYGOTE; - case content::PROCESS_TYPE_SANDBOX_HELPER: - return ProfilerEventProto::TrackedObject::SANDBOX_HELPER; - case content::PROCESS_TYPE_NACL_BROKER: - return ProfilerEventProto::TrackedObject::NACL_BROKER; - case content::PROCESS_TYPE_GPU: - return ProfilerEventProto::TrackedObject::GPU; - case content::PROCESS_TYPE_PPAPI_PLUGIN: - return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN; - case content::PROCESS_TYPE_PPAPI_BROKER: - return ProfilerEventProto::TrackedObject::PPAPI_BROKER; - default: - NOTREACHED(); - return ProfilerEventProto::TrackedObject::UNKNOWN; - } -} - // Returns the plugin preferences corresponding for this user, if available. // If multiple user profiles are loaded, returns the preferences corresponding // to an arbitrary one of the profiles. @@ -221,44 +181,6 @@ void WriteFieldTrials(const std::vector<NameGroupId>& field_trial_ids, } } -void WriteProfilerData(const ProcessDataSnapshot& profiler_data, - content::ProcessType process_type, - ProfilerEventProto* performance_profile) { - for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it = - profiler_data.tasks.begin(); - it != profiler_data.tasks.end(); ++it) { - std::string ignored; - uint64 birth_thread_name_hash; - uint64 exec_thread_name_hash; - uint64 source_file_name_hash; - uint64 source_function_name_hash; - MetricsLogBase::CreateHashes(it->birth.thread_name, - &ignored, &birth_thread_name_hash); - MetricsLogBase::CreateHashes(it->death_thread_name, - &ignored, &exec_thread_name_hash); - MetricsLogBase::CreateHashes(it->birth.location.function_name, - &ignored, &source_file_name_hash); - MetricsLogBase::CreateHashes(it->birth.location.file_name, - &ignored, &source_function_name_hash); - - const tracked_objects::DeathDataSnapshot& death_data = it->death_data; - ProfilerEventProto::TrackedObject* tracked_object = - performance_profile->add_tracked_object(); - tracked_object->set_birth_thread_name_hash(birth_thread_name_hash); - tracked_object->set_exec_thread_name_hash(exec_thread_name_hash); - tracked_object->set_source_file_name_hash(source_file_name_hash); - tracked_object->set_source_function_name_hash(source_function_name_hash); - tracked_object->set_source_line_number(it->birth.location.line_number); - tracked_object->set_exec_count(death_data.count); - tracked_object->set_exec_time_total(death_data.run_duration_sum); - tracked_object->set_exec_time_sampled(death_data.run_duration_sample); - tracked_object->set_queue_time_total(death_data.queue_duration_sum); - tracked_object->set_queue_time_sampled(death_data.queue_duration_sample); - tracked_object->set_process_type(AsProtobufProcessType(process_type)); - tracked_object->set_process_id(profiler_data.process_id); - } -} - } // namespace static base::LazyInstance<std::string>::Leaky @@ -782,30 +704,6 @@ void MetricsLog::RecordEnvironmentProto( WriteFieldTrials(field_trial_ids, system_profile); } -void MetricsLog::RecordProfilerData( - const tracked_objects::ProcessDataSnapshot& process_data, - content::ProcessType process_type) { - DCHECK(!locked()); - - if (tracked_objects::GetAlternateTimeSource()) { - // We currently only support the default time source, wall clock time. - return; - } - - ProfilerEventProto* profile; - if (!uma_proto()->profiler_event_size()) { - // For the first process's data, add a new field to the protocol buffer. - profile = uma_proto()->add_profiler_event(); - profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE); - profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME); - } else { - // For the remaining calls, re-use the existing field. - profile = uma_proto()->mutable_profiler_event(0); - } - - WriteProfilerData(process_data, process_type, profile); -} - void MetricsLog::WriteAllProfilesMetrics( const DictionaryValue& all_profiles_metrics) { const std::string profile_prefix(prefs::kProfilePrefix); diff --git a/chrome/browser/metrics/metrics_log.h b/chrome/browser/metrics/metrics_log.h index b219685..400a2c6 100644 --- a/chrome/browser/metrics/metrics_log.h +++ b/chrome/browser/metrics/metrics_log.h @@ -15,7 +15,6 @@ #include "base/basictypes.h" #include "base/metrics/field_trial.h" #include "chrome/common/metrics/metrics_log_base.h" -#include "content/public/common/process_type.h" #include "ui/gfx/size.h" struct AutocompleteLog; @@ -25,10 +24,6 @@ namespace base { class DictionaryValue; } -namespace tracked_objects { -struct ProcessDataSnapshot; -} - namespace webkit { struct WebPluginInfo; } @@ -77,12 +72,6 @@ class MetricsLog : public MetricsLogBase { // user uses the Omnibox to open a URL. void RecordOmniboxOpenedURL(const AutocompleteLog& log); - // Records the passed profiled data, which should be a snapshot of the - // browser's profiled performance during startup for a single process. - void RecordProfilerData( - const tracked_objects::ProcessDataSnapshot& process_data, - content::ProcessType process_type); - // Record recent delta for critical stability metrics. We can't wait for a // restart to gather these, as that delay biases our observation away from // users that run happily for a looooong time. We send increments with each diff --git a/chrome/browser/metrics/metrics_log_unittest.cc b/chrome/browser/metrics/metrics_log_unittest.cc index 6abe9f8..0365465 100644 --- a/chrome/browser/metrics/metrics_log_unittest.cc +++ b/chrome/browser/metrics/metrics_log_unittest.cc @@ -8,11 +8,9 @@ #include "base/stringprintf.h" #include "base/string_util.h" #include "base/time.h" -#include "base/tracked_objects.h" #include "chrome/browser/metrics/metrics_log.h" #include "chrome/browser/prefs/browser_prefs.h" #include "chrome/browser/prefs/pref_service.h" -#include "chrome/common/metrics/proto/profiler_event.pb.h" #include "chrome/common/metrics/proto/system_profile.pb.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_pref_service.h" @@ -22,9 +20,6 @@ #include "webkit/plugins/webplugininfo.h" using base::TimeDelta; -using metrics::ProfilerEventProto; -using tracked_objects::ProcessDataSnapshot; -using tracked_objects::TaskSnapshot; namespace { @@ -58,12 +53,8 @@ class TestMetricsLog : public MetricsLog { return &prefs_; } - const metrics::ChromeUserMetricsExtension& uma_proto() const { - return *MetricsLog::uma_proto(); - } - const metrics::SystemProfileProto& system_profile() const { - return uma_proto().system_profile(); + return uma_proto()->system_profile(); } private: @@ -129,128 +120,6 @@ TEST_F(MetricsLogTest, RecordEnvironment) { TestRecordEnvironment(true); } -// Test that we properly write profiler data to the log. -TEST_F(MetricsLogTest, RecordProfilerData) { - TestMetricsLog log(kClientId, kSessionId); - EXPECT_EQ(0, log.uma_proto().profiler_event_size()); - - { - ProcessDataSnapshot process_data; - process_data.process_id = 177; - process_data.tasks.push_back(TaskSnapshot()); - process_data.tasks.back().birth.location.file_name = "file"; - process_data.tasks.back().birth.location.function_name = "function"; - process_data.tasks.back().birth.location.line_number = 1337; - process_data.tasks.back().birth.thread_name = "birth_thread"; - process_data.tasks.back().death_data.count = 37; - process_data.tasks.back().death_data.run_duration_sum = 31; - process_data.tasks.back().death_data.run_duration_max = 17; - process_data.tasks.back().death_data.run_duration_sample = 13; - process_data.tasks.back().death_data.queue_duration_sum = 8; - process_data.tasks.back().death_data.queue_duration_max = 5; - process_data.tasks.back().death_data.queue_duration_sample = 3; - process_data.tasks.back().death_thread_name = "Still_Alive"; - process_data.tasks.push_back(TaskSnapshot()); - process_data.tasks.back().birth.location.file_name = "file2"; - process_data.tasks.back().birth.location.function_name = "function2"; - process_data.tasks.back().birth.location.line_number = 1773; - process_data.tasks.back().birth.thread_name = "birth_thread2"; - process_data.tasks.back().death_data.count = 19; - process_data.tasks.back().death_data.run_duration_sum = 23; - process_data.tasks.back().death_data.run_duration_max = 11; - process_data.tasks.back().death_data.run_duration_sample = 7; - process_data.tasks.back().death_data.queue_duration_sum = 0; - process_data.tasks.back().death_data.queue_duration_max = 0; - process_data.tasks.back().death_data.queue_duration_sample = 0; - process_data.tasks.back().death_thread_name = "death_thread"; - - log.RecordProfilerData(process_data, content::PROCESS_TYPE_BROWSER); - ASSERT_EQ(1, log.uma_proto().profiler_event_size()); - EXPECT_EQ(ProfilerEventProto::STARTUP_PROFILE, - log.uma_proto().profiler_event(0).profile_type()); - EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME, - log.uma_proto().profiler_event(0).time_source()); - - ASSERT_EQ(2, log.uma_proto().profiler_event(0).tracked_object_size()); - - const ProfilerEventProto::TrackedObject* tracked_object = - &log.uma_proto().profiler_event(0).tracked_object(0); - EXPECT_EQ(13962325592283560029U, tracked_object->source_file_name_hash()); - EXPECT_EQ(10123486280357988687U, - tracked_object->source_function_name_hash()); - EXPECT_EQ(1337, tracked_object->source_line_number()); - EXPECT_EQ(3400908935414830400U, tracked_object->birth_thread_name_hash()); - EXPECT_EQ(37, tracked_object->exec_count()); - EXPECT_EQ(31, tracked_object->exec_time_total()); - EXPECT_EQ(13, tracked_object->exec_time_sampled()); - EXPECT_EQ(8, tracked_object->queue_time_total()); - EXPECT_EQ(3, tracked_object->queue_time_sampled()); - EXPECT_EQ(10151977472163283085U, tracked_object->exec_thread_name_hash()); - EXPECT_EQ(177U, tracked_object->process_id()); - EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER, - tracked_object->process_type()); - - tracked_object = &log.uma_proto().profiler_event(0).tracked_object(1); - EXPECT_EQ(55232426147951219U, tracked_object->source_file_name_hash()); - EXPECT_EQ(2025659946535236365U, - tracked_object->source_function_name_hash()); - EXPECT_EQ(1773, tracked_object->source_line_number()); - EXPECT_EQ(15727396632046120663U, tracked_object->birth_thread_name_hash()); - EXPECT_EQ(19, tracked_object->exec_count()); - EXPECT_EQ(23, tracked_object->exec_time_total()); - EXPECT_EQ(7, tracked_object->exec_time_sampled()); - EXPECT_EQ(0, tracked_object->queue_time_total()); - EXPECT_EQ(0, tracked_object->queue_time_sampled()); - EXPECT_EQ(14275151213201158253U, tracked_object->exec_thread_name_hash()); - EXPECT_EQ(177U, tracked_object->process_id()); - EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER, - tracked_object->process_type()); - } - - { - ProcessDataSnapshot process_data; - process_data.process_id = 1177; - process_data.tasks.push_back(TaskSnapshot()); - process_data.tasks.back().birth.location.file_name = "file3"; - process_data.tasks.back().birth.location.function_name = "function3"; - process_data.tasks.back().birth.location.line_number = 7331; - process_data.tasks.back().birth.thread_name = "birth_thread3"; - process_data.tasks.back().death_data.count = 137; - process_data.tasks.back().death_data.run_duration_sum = 131; - process_data.tasks.back().death_data.run_duration_max = 117; - process_data.tasks.back().death_data.run_duration_sample = 113; - process_data.tasks.back().death_data.queue_duration_sum = 108; - process_data.tasks.back().death_data.queue_duration_max = 105; - process_data.tasks.back().death_data.queue_duration_sample = 103; - process_data.tasks.back().death_thread_name = "death_thread3"; - - log.RecordProfilerData(process_data, content::PROCESS_TYPE_RENDERER); - ASSERT_EQ(1, log.uma_proto().profiler_event_size()); - EXPECT_EQ(ProfilerEventProto::STARTUP_PROFILE, - log.uma_proto().profiler_event(0).profile_type()); - EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME, - log.uma_proto().profiler_event(0).time_source()); - ASSERT_EQ(3, log.uma_proto().profiler_event(0).tracked_object_size()); - - const ProfilerEventProto::TrackedObject* tracked_object = - &log.uma_proto().profiler_event(0).tracked_object(2); - EXPECT_EQ(5081672290546182009U, tracked_object->source_file_name_hash()); - EXPECT_EQ(2686523203278102732U, - tracked_object->source_function_name_hash()); - EXPECT_EQ(7331, tracked_object->source_line_number()); - EXPECT_EQ(8768512930949373716U, tracked_object->birth_thread_name_hash()); - EXPECT_EQ(137, tracked_object->exec_count()); - EXPECT_EQ(131, tracked_object->exec_time_total()); - EXPECT_EQ(113, tracked_object->exec_time_sampled()); - EXPECT_EQ(108, tracked_object->queue_time_total()); - EXPECT_EQ(103, tracked_object->queue_time_sampled()); - EXPECT_EQ(7246674144371406371U, tracked_object->exec_thread_name_hash()); - EXPECT_EQ(1177U, tracked_object->process_id()); - EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER, - tracked_object->process_type()); - } -} - #if defined(OS_CHROMEOS) TEST_F(MetricsLogTest, ChromeOSStabilityData) { TestMetricsLog log(kClientId, kSessionId); diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc index 89eb0c2..25d0af7 100644 --- a/chrome/browser/metrics/metrics_service.cc +++ b/chrome/browser/metrics/metrics_service.cc @@ -152,7 +152,6 @@ #include "base/string_number_conversions.h" #include "base/threading/platform_thread.h" #include "base/threading/thread.h" -#include "base/tracked_objects.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "chrome/browser/bookmarks/bookmark_model.h" @@ -165,7 +164,6 @@ #include "chrome/browser/metrics/metrics_log.h" #include "chrome/browser/metrics/metrics_log_serializer.h" #include "chrome/browser/metrics/metrics_reporting_scheduler.h" -#include "chrome/browser/metrics/tracking_synchronizer.h" #include "chrome/browser/net/http_pipelining_compatibility_client.h" #include "chrome/browser/net/network_stats.h" #include "chrome/browser/prefs/pref_service.h" @@ -775,7 +773,7 @@ void MetricsService::InitTaskGetHardwareClass( void MetricsService::OnInitTaskGotHardwareClass( const std::string& hardware_class) { - DCHECK_EQ(INIT_TASK_SCHEDULED, state_); + DCHECK_EQ(state_, INIT_TASK_SCHEDULED); hardware_class_ = hardware_class; // Start the next part of the init task: loading plugin information. @@ -786,31 +784,11 @@ void MetricsService::OnInitTaskGotHardwareClass( void MetricsService::OnInitTaskGotPluginInfo( const std::vector<webkit::WebPluginInfo>& plugins) { - DCHECK_EQ(INIT_TASK_SCHEDULED, state_); + DCHECK_EQ(state_, INIT_TASK_SCHEDULED); plugins_ = plugins; - // Start the next part of the init task: fetching performance data. This will - // call into |FinishedReceivingProfilerData()| when the task completes. - chrome_browser_metrics::TrackingSynchronizer::FetchProfilerDataAsynchronously( - self_ptr_factory_.GetWeakPtr()); -} - -void MetricsService::ReceivedProfilerData( - const tracked_objects::ProcessDataSnapshot& process_data, - content::ProcessType process_type) { - DCHECK_EQ(INIT_TASK_SCHEDULED, state_); - - // Upon the first callback, create the initial log so that we can immediately - // save the profiler data. - if (!initial_log_.get()) - initial_log_.reset(new MetricsLog(client_id_, session_id_)); - - initial_log_->RecordProfilerData(process_data, process_type); -} - -void MetricsService::FinishedReceivingProfilerData() { - DCHECK_EQ(INIT_TASK_SCHEDULED, state_); - state_ = INIT_TASK_DONE; + if (state_ == INIT_TASK_SCHEDULED) + state_ = INIT_TASK_DONE; } std::string MetricsService::GenerateClientID() { @@ -1036,7 +1014,7 @@ void MetricsService::MakeStagedLog() { // anything, because the server will tell us whether it wants to hear // from us. PrepareInitialLog(); - DCHECK_EQ(INIT_TASK_DONE, state_); + DCHECK(state_ == INIT_TASK_DONE); log_manager_.LoadPersistedUnsentLogs(); state_ = INITIAL_LOG_READY; break; @@ -1064,17 +1042,16 @@ void MetricsService::MakeStagedLog() { } void MetricsService::PrepareInitialLog() { - DCHECK_EQ(INIT_TASK_DONE, state_); + DCHECK(state_ == INIT_TASK_DONE); - DCHECK(initial_log_.get()); - initial_log_->set_hardware_class(hardware_class_); - initial_log_->RecordEnvironment(plugins_, profile_dictionary_.get()); + MetricsLog* log = new MetricsLog(client_id_, session_id_); + log->set_hardware_class(hardware_class_); // Adds to initial log. + log->RecordEnvironment(plugins_, profile_dictionary_.get()); // Histograms only get written to the current log, so make the new log current // before writing them. log_manager_.PauseCurrentLog(); - log_manager_.BeginLoggingWithLog(initial_log_.release(), - MetricsLogManager::INITIAL_LOG); + log_manager_.BeginLoggingWithLog(log, MetricsLogManager::INITIAL_LOG); RecordCurrentHistograms(); log_manager_.FinishCurrentLog(); log_manager_.ResumePausedLog(); @@ -1279,7 +1256,7 @@ void MetricsService::OnURLFetchComplete(const content::URLFetcher* source) { log_manager_.DiscardStagedLog(); if (log_manager_.has_unsent_logs()) - DCHECK_LT(state_, SENDING_CURRENT_LOGS); + DCHECK(state_ < SENDING_CURRENT_LOGS); } // Error 400 indicates a problem with the log, not with the server, so diff --git a/chrome/browser/metrics/metrics_service.h b/chrome/browser/metrics/metrics_service.h index cfe1943..229921d 100644 --- a/chrome/browser/metrics/metrics_service.h +++ b/chrome/browser/metrics/metrics_service.h @@ -15,14 +15,15 @@ #include "base/basictypes.h" #include "base/gtest_prod_util.h" +#include "base/memory/weak_ptr.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/process_util.h" -#include "chrome/browser/metrics/tracking_synchronizer_observer.h" #include "chrome/common/metrics/metrics_service_base.h" +#include "content/public/common/process_type.h" +#include "content/public/common/url_fetcher_delegate.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" -#include "content/public/common/url_fetcher_delegate.h" #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/external_metrics.h" @@ -30,7 +31,6 @@ class BookmarkModel; class BookmarkNode; -class MetricsLog; class MetricsReportingScheduler; class PrefService; class Profile; @@ -53,19 +53,14 @@ namespace prerender { bool IsOmniboxEnabled(Profile* profile); } -namespace tracked_objects { -struct ProcessDataSnapshot; -} - namespace webkit { struct WebPluginInfo; } -class MetricsService - : public chrome_browser_metrics::TrackingSynchronizerObserver, - public content::NotificationObserver, - public content::URLFetcherDelegate, - public MetricsServiceBase { + +class MetricsService : public content::NotificationObserver, + public content::URLFetcherDelegate, + public MetricsServiceBase { public: MetricsService(); virtual ~MetricsService(); @@ -166,18 +161,11 @@ class MetricsService // loading plugin information. void OnInitTaskGotHardwareClass(const std::string& hardware_class); - // Callback from PluginService::GetPlugins() that continues the init task by - // loading profiler data. + // Callback from PluginService::GetPlugins() that moves the state to + // INIT_TASK_DONE. void OnInitTaskGotPluginInfo( const std::vector<webkit::WebPluginInfo>& plugins); - // TrackingSynchronizerObserver: - virtual void ReceivedProfilerData( - const tracked_objects::ProcessDataSnapshot& process_data, - content::ProcessType process_type) OVERRIDE; - // Callback that moves the state to INIT_TASK_DONE. - virtual void FinishedReceivingProfilerData() OVERRIDE; - // When we start a new version of Chromium (different from our last run), we // need to discard the old crash stats so that we don't attribute crashes etc. // in the old version to the current version (via current logs). @@ -359,9 +347,6 @@ class MetricsService // The list of plugins which was retrieved on the file thread. std::vector<webkit::WebPluginInfo> plugins_; - // The initial log, used to record startup metrics. - scoped_ptr<MetricsLog> initial_log_; - // The outstanding transmission appears as a URL Fetch operation. scoped_ptr<content::URLFetcher> current_fetch_xml_; scoped_ptr<content::URLFetcher> current_fetch_proto_; |