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
3 // found in the LICENSE file.
5 #include "chrome/browser/metrics/metrics_log.h"
9 #include "base/base64.h"
10 #include "base/basictypes.h"
11 #include "base/command_line.h"
12 #include "base/port.h"
13 #include "base/prefs/pref_service.h"
14 #include "base/prefs/scoped_user_pref_update.h"
15 #include "base/prefs/testing_pref_service.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h"
19 #include "base/strings/utf_string_conversions.h"
20 #include "base/threading/sequenced_worker_pool.h"
21 #include "base/time/time.h"
22 #include "base/tracked_objects.h"
23 #include "chrome/browser/google/google_util.h"
24 #include "chrome/browser/prefs/browser_prefs.h"
25 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/metrics/proto/profiler_event.pb.h"
27 #include "chrome/common/metrics/proto/system_profile.pb.h"
28 #include "chrome/common/metrics/variations/variations_util.h"
29 #include "chrome/common/pref_names.h"
30 #include "chrome/installer/util/google_update_settings.h"
31 #include "components/variations/metrics_util.h"
32 #include "content/public/browser/browser_thread.h"
33 #include "content/public/common/process_type.h"
34 #include "content/public/common/webplugininfo.h"
35 #include "content/public/test/test_browser_thread_bundle.h"
36 #include "content/public/test/test_utils.h"
37 #include "testing/gtest/include/gtest/gtest.h"
38 #include "ui/gfx/size.h"
41 #if defined(OS_CHROMEOS)
42 #include "chrome/browser/chromeos/login/fake_user_manager.h"
43 #include "chrome/browser/chromeos/login/user_manager.h"
44 #include "chrome/browser/metrics/metrics_log_chromeos.h"
47 using base::TimeDelta;
48 using metrics::ProfilerEventProto;
49 using tracked_objects::ProcessDataSnapshot;
50 using tracked_objects::TaskSnapshot;
54 const char kClientId[] = "bogus client ID";
55 const int64 kInstallDate = 1373051956;
56 const int64 kInstallDateExpected = 1373050800; // Computed from kInstallDate.
57 const int64 kEnabledDate = 1373001211;
58 const int64 kEnabledDateExpected = 1373000400; // Computed from kEnabledDate.
59 const int kSessionId = 127;
60 const int kScreenWidth = 1024;
61 const int kScreenHeight = 768;
62 const int kScreenCount = 3;
63 const float kScreenScaleFactor = 2;
64 const char kBrandForTesting[] = "brand_for_testing";
65 const chrome_variations::ActiveGroupId kFieldTrialIds[] = {
70 const chrome_variations::ActiveGroupId kSyntheticTrials[] = {
75 #if defined(ENABLE_PLUGINS)
76 content::WebPluginInfo CreateFakePluginInfo(
77 const std::string& name,
78 const base::FilePath::CharType* path,
79 const std::string& version,
81 content::WebPluginInfo plugin(base::UTF8ToUTF16(name),
83 base::UTF8ToUTF16(version),
86 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS;
88 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_NPAPI;
91 #endif // defined(ENABLE_PLUGINS)
93 #if defined(OS_CHROMEOS)
94 class TestMetricsLogChromeOS : public MetricsLogChromeOS {
96 explicit TestMetricsLogChromeOS(
97 metrics::ChromeUserMetricsExtension* uma_proto)
98 : MetricsLogChromeOS(uma_proto) {
102 // Don't touch bluetooth information, as it won't be correctly initialized.
103 virtual void WriteBluetoothProto() OVERRIDE {
106 #endif // OS_CHROMEOS
108 class TestMetricsLog : public MetricsLog {
110 TestMetricsLog(const std::string& client_id, int session_id)
111 : MetricsLog(client_id, session_id),
112 prefs_(&scoped_prefs_),
113 brand_for_testing_(kBrandForTesting) {
114 #if defined(OS_CHROMEOS)
115 metrics_log_chromeos_.reset(new TestMetricsLogChromeOS(
116 MetricsLog::uma_proto()));
117 #endif // OS_CHROMEOS
118 chrome::RegisterLocalState(scoped_prefs_.registry());
121 // Creates a TestMetricsLog that will use |prefs| as the fake local state.
122 // Useful for tests that need to re-use the local state prefs between logs.
123 TestMetricsLog(const std::string& client_id,
125 TestingPrefServiceSimple* prefs)
126 : MetricsLog(client_id, session_id),
128 brand_for_testing_(kBrandForTesting) {
129 #if defined(OS_CHROMEOS)
130 metrics_log_chromeos_.reset(new TestMetricsLogChromeOS(
131 MetricsLog::uma_proto()));
132 #endif // OS_CHROMEOS
135 virtual ~TestMetricsLog() {}
137 virtual PrefService* GetPrefService() OVERRIDE {
141 const metrics::ChromeUserMetricsExtension& uma_proto() const {
142 return *MetricsLog::uma_proto();
145 const metrics::SystemProfileProto& system_profile() const {
146 return uma_proto().system_profile();
151 prefs_->SetInt64(prefs::kInstallDate, kInstallDate);
152 prefs_->SetString(prefs::kMetricsClientIDTimestamp,
153 base::Int64ToString(kEnabledDate));
154 #if defined(OS_CHROMEOS)
155 prefs_->SetInteger(prefs::kStabilityChildProcessCrashCount, 10);
156 prefs_->SetInteger(prefs::kStabilityOtherUserCrashCount, 11);
157 prefs_->SetInteger(prefs::kStabilityKernelCrashCount, 12);
158 prefs_->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 13);
159 #endif // OS_CHROMEOS
162 virtual void GetFieldTrialIds(
163 std::vector<chrome_variations::ActiveGroupId>* field_trial_ids) const
165 ASSERT_TRUE(field_trial_ids->empty());
167 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) {
168 field_trial_ids->push_back(kFieldTrialIds[i]);
172 virtual gfx::Size GetScreenSize() const OVERRIDE {
173 return gfx::Size(kScreenWidth, kScreenHeight);
176 virtual float GetScreenDeviceScaleFactor() const OVERRIDE {
177 return kScreenScaleFactor;
180 virtual int GetScreenCount() const OVERRIDE {
184 // Scoped PrefsService, which may not be used if |prefs_ != &scoped_prefs|.
185 TestingPrefServiceSimple scoped_prefs_;
186 // Weak pointer to the PrefsService used by this log.
187 TestingPrefServiceSimple* prefs_;
189 google_util::BrandForTesting brand_for_testing_;
191 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog);
196 class MetricsLogTest : public testing::Test {
201 virtual void SetUp() OVERRIDE {
202 #if defined(OS_CHROMEOS)
203 // Enable multi-profiles.
204 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles);
205 #endif // OS_CHROMEOS
208 // Check that the values in |system_values| correspond to the test data
209 // defined at the top of this file.
210 void CheckSystemProfile(const metrics::SystemProfileProto& system_profile) {
211 EXPECT_EQ(kInstallDateExpected, system_profile.install_date());
212 EXPECT_EQ(kEnabledDateExpected, system_profile.uma_enabled_date());
214 ASSERT_EQ(arraysize(kFieldTrialIds) + arraysize(kSyntheticTrials),
215 static_cast<size_t>(system_profile.field_trial_size()));
216 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) {
217 const metrics::SystemProfileProto::FieldTrial& field_trial =
218 system_profile.field_trial(i);
219 EXPECT_EQ(kFieldTrialIds[i].name, field_trial.name_id());
220 EXPECT_EQ(kFieldTrialIds[i].group, field_trial.group_id());
222 // Verify the right data is present for the synthetic trials.
223 for (size_t i = 0; i < arraysize(kSyntheticTrials); ++i) {
224 const metrics::SystemProfileProto::FieldTrial& field_trial =
225 system_profile.field_trial(i + arraysize(kFieldTrialIds));
226 EXPECT_EQ(kSyntheticTrials[i].name, field_trial.name_id());
227 EXPECT_EQ(kSyntheticTrials[i].group, field_trial.group_id());
230 EXPECT_EQ(kBrandForTesting, system_profile.brand_code());
232 const metrics::SystemProfileProto::Hardware& hardware =
233 system_profile.hardware();
234 EXPECT_EQ(kScreenWidth, hardware.primary_screen_width());
235 EXPECT_EQ(kScreenHeight, hardware.primary_screen_height());
236 EXPECT_EQ(kScreenScaleFactor, hardware.primary_screen_scale_factor());
237 EXPECT_EQ(kScreenCount, hardware.screen_count());
239 EXPECT_TRUE(hardware.has_cpu());
240 EXPECT_TRUE(hardware.cpu().has_vendor_name());
241 EXPECT_TRUE(hardware.cpu().has_signature());
243 // TODO(isherman): Verify other data written into the protobuf as a result
248 content::TestBrowserThreadBundle thread_bundle_;
250 DISALLOW_COPY_AND_ASSIGN(MetricsLogTest);
253 TEST_F(MetricsLogTest, RecordEnvironment) {
254 TestMetricsLog log(kClientId, kSessionId);
256 std::vector<content::WebPluginInfo> plugins;
257 GoogleUpdateMetrics google_update_metrics;
258 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
259 // Add two synthetic trials.
260 synthetic_trials.push_back(kSyntheticTrials[0]);
261 synthetic_trials.push_back(kSyntheticTrials[1]);
263 log.RecordEnvironment(plugins, google_update_metrics, synthetic_trials);
264 // Check that the system profile on the log has the correct values set.
265 CheckSystemProfile(log.system_profile());
267 // Check that the system profile has also been written to prefs.
268 PrefService* local_state = log.GetPrefService();
269 const std::string base64_system_profile =
270 local_state->GetString(prefs::kStabilitySavedSystemProfile);
271 EXPECT_FALSE(base64_system_profile.empty());
272 std::string serialied_system_profile;
273 EXPECT_TRUE(base::Base64Decode(base64_system_profile,
274 &serialied_system_profile));
275 SystemProfileProto decoded_system_profile;
276 EXPECT_TRUE(decoded_system_profile.ParseFromString(serialied_system_profile));
277 CheckSystemProfile(decoded_system_profile);
280 TEST_F(MetricsLogTest, LoadSavedEnvironmentFromPrefs) {
281 const char* kSystemProfilePref = prefs::kStabilitySavedSystemProfile;
282 const char* kSystemProfileHashPref = prefs::kStabilitySavedSystemProfileHash;
284 TestingPrefServiceSimple prefs;
285 chrome::RegisterLocalState(prefs.registry());
287 // The pref value is empty, so loading it from prefs should fail.
289 TestMetricsLog log(kClientId, kSessionId, &prefs);
290 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs());
293 // Do a RecordEnvironment() call and check whether the pref is recorded.
295 TestMetricsLog log(kClientId, kSessionId, &prefs);
296 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
297 GoogleUpdateMetrics(),
298 std::vector<chrome_variations::ActiveGroupId>());
299 EXPECT_FALSE(prefs.GetString(kSystemProfilePref).empty());
300 EXPECT_FALSE(prefs.GetString(kSystemProfileHashPref).empty());
304 TestMetricsLog log(kClientId, kSessionId, &prefs);
305 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs());
306 // Check some values in the system profile.
307 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date());
308 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date());
309 // Ensure that the call cleared the prefs.
310 EXPECT_TRUE(prefs.GetString(kSystemProfilePref).empty());
311 EXPECT_TRUE(prefs.GetString(kSystemProfileHashPref).empty());
314 // Ensure that a non-matching hash results in the pref being invalid.
316 TestMetricsLog log(kClientId, kSessionId, &prefs);
317 // Call RecordEnvironment() to record the pref again.
318 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
319 GoogleUpdateMetrics(),
320 std::vector<chrome_variations::ActiveGroupId>());
324 // Set the hash to a bad value.
325 prefs.SetString(kSystemProfileHashPref, "deadbeef");
326 TestMetricsLog log(kClientId, kSessionId, &prefs);
327 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs());
328 // Ensure that the prefs are cleared, even if the call failed.
329 EXPECT_TRUE(prefs.GetString(kSystemProfilePref).empty());
330 EXPECT_TRUE(prefs.GetString(kSystemProfileHashPref).empty());
334 TEST_F(MetricsLogTest, InitialLogStabilityMetrics) {
335 TestMetricsLog log(kClientId, kSessionId);
336 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
337 GoogleUpdateMetrics(),
338 std::vector<chrome_variations::ActiveGroupId>());
339 log.RecordStabilityMetrics(base::TimeDelta(), MetricsLog::INITIAL_LOG);
340 const metrics::SystemProfileProto_Stability& stability =
341 log.system_profile().stability();
343 EXPECT_TRUE(stability.has_launch_count());
344 EXPECT_TRUE(stability.has_crash_count());
345 // Initial log metrics:
346 EXPECT_TRUE(stability.has_incomplete_shutdown_count());
347 EXPECT_TRUE(stability.has_breakpad_registration_success_count());
348 EXPECT_TRUE(stability.has_breakpad_registration_failure_count());
349 EXPECT_TRUE(stability.has_debugger_present_count());
350 EXPECT_TRUE(stability.has_debugger_not_present_count());
353 TEST_F(MetricsLogTest, OngoingLogStabilityMetrics) {
354 TestMetricsLog log(kClientId, kSessionId);
355 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
356 GoogleUpdateMetrics(),
357 std::vector<chrome_variations::ActiveGroupId>());
358 log.RecordStabilityMetrics(base::TimeDelta(), MetricsLog::ONGOING_LOG);
359 const metrics::SystemProfileProto_Stability& stability =
360 log.system_profile().stability();
362 EXPECT_TRUE(stability.has_launch_count());
363 EXPECT_TRUE(stability.has_crash_count());
364 // Initial log metrics:
365 EXPECT_FALSE(stability.has_incomplete_shutdown_count());
366 EXPECT_FALSE(stability.has_breakpad_registration_success_count());
367 EXPECT_FALSE(stability.has_breakpad_registration_failure_count());
368 EXPECT_FALSE(stability.has_debugger_present_count());
369 EXPECT_FALSE(stability.has_debugger_not_present_count());
372 #if defined(ENABLE_PLUGINS)
373 TEST_F(MetricsLogTest, Plugins) {
374 TestMetricsLog log(kClientId, kSessionId);
376 std::vector<content::WebPluginInfo> plugins;
377 plugins.push_back(CreateFakePluginInfo("p1", FILE_PATH_LITERAL("p1.plugin"),
379 plugins.push_back(CreateFakePluginInfo("p2", FILE_PATH_LITERAL("p2.plugin"),
381 log.RecordEnvironment(plugins, GoogleUpdateMetrics(),
382 std::vector<chrome_variations::ActiveGroupId>());
384 const metrics::SystemProfileProto& system_profile = log.system_profile();
385 ASSERT_EQ(2, system_profile.plugin_size());
386 EXPECT_EQ("p1", system_profile.plugin(0).name());
387 EXPECT_EQ("p1.plugin", system_profile.plugin(0).filename());
388 EXPECT_EQ("1.5", system_profile.plugin(0).version());
389 EXPECT_TRUE(system_profile.plugin(0).is_pepper());
390 EXPECT_EQ("p2", system_profile.plugin(1).name());
391 EXPECT_EQ("p2.plugin", system_profile.plugin(1).filename());
392 EXPECT_EQ("2.0", system_profile.plugin(1).version());
393 EXPECT_FALSE(system_profile.plugin(1).is_pepper());
395 // Now set some plugin stability stats for p2 and verify they're recorded.
396 scoped_ptr<base::DictionaryValue> plugin_dict(new base::DictionaryValue);
397 plugin_dict->SetString(prefs::kStabilityPluginName, "p2");
398 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, 1);
399 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, 2);
400 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, 3);
401 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, 4);
403 ListPrefUpdate update(log.GetPrefService(), prefs::kStabilityPluginStats);
404 update.Get()->Append(plugin_dict.release());
407 log.RecordStabilityMetrics(base::TimeDelta(), MetricsLog::ONGOING_LOG);
408 const metrics::SystemProfileProto_Stability& stability =
409 log.system_profile().stability();
410 ASSERT_EQ(1, stability.plugin_stability_size());
411 EXPECT_EQ("p2", stability.plugin_stability(0).plugin().name());
412 EXPECT_EQ("p2.plugin", stability.plugin_stability(0).plugin().filename());
413 EXPECT_EQ("2.0", stability.plugin_stability(0).plugin().version());
414 EXPECT_FALSE(stability.plugin_stability(0).plugin().is_pepper());
415 EXPECT_EQ(1, stability.plugin_stability(0).launch_count());
416 EXPECT_EQ(2, stability.plugin_stability(0).crash_count());
417 EXPECT_EQ(3, stability.plugin_stability(0).instance_count());
418 EXPECT_EQ(4, stability.plugin_stability(0).loading_error_count());
420 #endif // defined(ENABLE_PLUGINS)
422 // Test that we properly write profiler data to the log.
423 TEST_F(MetricsLogTest, RecordProfilerData) {
424 TestMetricsLog log(kClientId, kSessionId);
425 EXPECT_EQ(0, log.uma_proto().profiler_event_size());
428 ProcessDataSnapshot process_data;
429 process_data.process_id = 177;
430 process_data.tasks.push_back(TaskSnapshot());
431 process_data.tasks.back().birth.location.file_name = "file";
432 process_data.tasks.back().birth.location.function_name = "function";
433 process_data.tasks.back().birth.location.line_number = 1337;
434 process_data.tasks.back().birth.thread_name = "birth_thread";
435 process_data.tasks.back().death_data.count = 37;
436 process_data.tasks.back().death_data.run_duration_sum = 31;
437 process_data.tasks.back().death_data.run_duration_max = 17;
438 process_data.tasks.back().death_data.run_duration_sample = 13;
439 process_data.tasks.back().death_data.queue_duration_sum = 8;
440 process_data.tasks.back().death_data.queue_duration_max = 5;
441 process_data.tasks.back().death_data.queue_duration_sample = 3;
442 process_data.tasks.back().death_thread_name = "Still_Alive";
443 process_data.tasks.push_back(TaskSnapshot());
444 process_data.tasks.back().birth.location.file_name = "file2";
445 process_data.tasks.back().birth.location.function_name = "function2";
446 process_data.tasks.back().birth.location.line_number = 1773;
447 process_data.tasks.back().birth.thread_name = "birth_thread2";
448 process_data.tasks.back().death_data.count = 19;
449 process_data.tasks.back().death_data.run_duration_sum = 23;
450 process_data.tasks.back().death_data.run_duration_max = 11;
451 process_data.tasks.back().death_data.run_duration_sample = 7;
452 process_data.tasks.back().death_data.queue_duration_sum = 0;
453 process_data.tasks.back().death_data.queue_duration_max = 0;
454 process_data.tasks.back().death_data.queue_duration_sample = 0;
455 process_data.tasks.back().death_thread_name = "death_thread";
457 log.RecordProfilerData(process_data, content::PROCESS_TYPE_BROWSER);
458 ASSERT_EQ(1, log.uma_proto().profiler_event_size());
459 EXPECT_EQ(ProfilerEventProto::STARTUP_PROFILE,
460 log.uma_proto().profiler_event(0).profile_type());
461 EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME,
462 log.uma_proto().profiler_event(0).time_source());
464 ASSERT_EQ(2, log.uma_proto().profiler_event(0).tracked_object_size());
466 const ProfilerEventProto::TrackedObject* tracked_object =
467 &log.uma_proto().profiler_event(0).tracked_object(0);
468 EXPECT_EQ(GG_UINT64_C(10123486280357988687),
469 tracked_object->source_file_name_hash());
470 EXPECT_EQ(GG_UINT64_C(13962325592283560029),
471 tracked_object->source_function_name_hash());
472 EXPECT_EQ(1337, tracked_object->source_line_number());
473 EXPECT_EQ(GG_UINT64_C(3400908935414830400),
474 tracked_object->birth_thread_name_hash());
475 EXPECT_EQ(37, tracked_object->exec_count());
476 EXPECT_EQ(31, tracked_object->exec_time_total());
477 EXPECT_EQ(13, tracked_object->exec_time_sampled());
478 EXPECT_EQ(8, tracked_object->queue_time_total());
479 EXPECT_EQ(3, tracked_object->queue_time_sampled());
480 EXPECT_EQ(GG_UINT64_C(10151977472163283085),
481 tracked_object->exec_thread_name_hash());
482 EXPECT_EQ(177U, tracked_object->process_id());
483 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER,
484 tracked_object->process_type());
486 tracked_object = &log.uma_proto().profiler_event(0).tracked_object(1);
487 EXPECT_EQ(GG_UINT64_C(2025659946535236365),
488 tracked_object->source_file_name_hash());
489 EXPECT_EQ(GG_UINT64_C(55232426147951219),
490 tracked_object->source_function_name_hash());
491 EXPECT_EQ(1773, tracked_object->source_line_number());
492 EXPECT_EQ(GG_UINT64_C(1518842999910132863),
493 tracked_object->birth_thread_name_hash());
494 EXPECT_EQ(19, tracked_object->exec_count());
495 EXPECT_EQ(23, tracked_object->exec_time_total());
496 EXPECT_EQ(7, tracked_object->exec_time_sampled());
497 EXPECT_EQ(0, tracked_object->queue_time_total());
498 EXPECT_EQ(0, tracked_object->queue_time_sampled());
499 EXPECT_EQ(GG_UINT64_C(14275151213201158253),
500 tracked_object->exec_thread_name_hash());
501 EXPECT_EQ(177U, tracked_object->process_id());
502 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER,
503 tracked_object->process_type());
507 ProcessDataSnapshot process_data;
508 process_data.process_id = 1177;
509 process_data.tasks.push_back(TaskSnapshot());
510 process_data.tasks.back().birth.location.file_name = "file3";
511 process_data.tasks.back().birth.location.function_name = "function3";
512 process_data.tasks.back().birth.location.line_number = 7331;
513 process_data.tasks.back().birth.thread_name = "birth_thread3";
514 process_data.tasks.back().death_data.count = 137;
515 process_data.tasks.back().death_data.run_duration_sum = 131;
516 process_data.tasks.back().death_data.run_duration_max = 117;
517 process_data.tasks.back().death_data.run_duration_sample = 113;
518 process_data.tasks.back().death_data.queue_duration_sum = 108;
519 process_data.tasks.back().death_data.queue_duration_max = 105;
520 process_data.tasks.back().death_data.queue_duration_sample = 103;
521 process_data.tasks.back().death_thread_name = "death_thread3";
523 log.RecordProfilerData(process_data, content::PROCESS_TYPE_RENDERER);
524 ASSERT_EQ(1, log.uma_proto().profiler_event_size());
525 EXPECT_EQ(ProfilerEventProto::STARTUP_PROFILE,
526 log.uma_proto().profiler_event(0).profile_type());
527 EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME,
528 log.uma_proto().profiler_event(0).time_source());
529 ASSERT_EQ(3, log.uma_proto().profiler_event(0).tracked_object_size());
531 const ProfilerEventProto::TrackedObject* tracked_object =
532 &log.uma_proto().profiler_event(0).tracked_object(2);
533 EXPECT_EQ(GG_UINT64_C(2686523203278102732),
534 tracked_object->source_file_name_hash());
535 EXPECT_EQ(GG_UINT64_C(5081672290546182009),
536 tracked_object->source_function_name_hash());
537 EXPECT_EQ(7331, tracked_object->source_line_number());
538 EXPECT_EQ(GG_UINT64_C(1518842999910132863),
539 tracked_object->birth_thread_name_hash());
540 EXPECT_EQ(137, tracked_object->exec_count());
541 EXPECT_EQ(131, tracked_object->exec_time_total());
542 EXPECT_EQ(113, tracked_object->exec_time_sampled());
543 EXPECT_EQ(108, tracked_object->queue_time_total());
544 EXPECT_EQ(103, tracked_object->queue_time_sampled());
545 EXPECT_EQ(GG_UINT64_C(2203893603452504755),
546 tracked_object->exec_thread_name_hash());
547 EXPECT_EQ(1177U, tracked_object->process_id());
548 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER,
549 tracked_object->process_type());
553 #if defined(OS_CHROMEOS)
554 TEST_F(MetricsLogTest, MultiProfileUserCount) {
555 std::string user1("user1@example.com");
556 std::string user2("user2@example.com");
557 std::string user3("user3@example.com");
559 // |scoped_enabler| takes over the lifetime of |user_manager|.
560 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager();
561 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager);
562 user_manager->AddKioskAppUser(user1);
563 user_manager->AddKioskAppUser(user2);
564 user_manager->AddKioskAppUser(user3);
566 user_manager->LoginUser(user1);
567 user_manager->LoginUser(user3);
569 TestMetricsLog log(kClientId, kSessionId);
570 std::vector<content::WebPluginInfo> plugins;
571 GoogleUpdateMetrics google_update_metrics;
572 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
573 log.RecordEnvironment(plugins, google_update_metrics, synthetic_trials);
574 EXPECT_EQ(2u, log.system_profile().multi_profile_user_count());
577 TEST_F(MetricsLogTest, MultiProfileCountInvalidated) {
578 std::string user1("user1@example.com");
579 std::string user2("user2@example.com");
580 std::string user3("user3@example.com");
582 // |scoped_enabler| takes over the lifetime of |user_manager|.
583 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager();
584 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager);
585 user_manager->AddKioskAppUser(user1);
586 user_manager->AddKioskAppUser(user2);
587 user_manager->AddKioskAppUser(user3);
589 user_manager->LoginUser(user1);
591 TestMetricsLog log(kClientId, kSessionId);
592 EXPECT_EQ(1u, log.system_profile().multi_profile_user_count());
594 user_manager->LoginUser(user2);
595 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
596 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
597 GoogleUpdateMetrics(), synthetic_trials);
598 EXPECT_EQ(0u, log.system_profile().multi_profile_user_count());
600 #endif // OS_CHROMEOS