cros: Change how multi-profile is enabled.
[chromium-blink-merge.git] / chrome / browser / metrics / metrics_log_unittest.cc
blob4624364111d7dc7de79fa4fee4fbc7a17b073329
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"
7 #include <string>
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"
39 #include "url/gurl.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 #endif // OS_CHROMEOS
46 using base::TimeDelta;
47 using metrics::ProfilerEventProto;
48 using tracked_objects::ProcessDataSnapshot;
49 using tracked_objects::TaskSnapshot;
51 namespace {
53 const char kClientId[] = "bogus client ID";
54 const int64 kInstallDate = 1373051956;
55 const int64 kInstallDateExpected = 1373050800; // Computed from kInstallDate.
56 const int64 kEnabledDate = 1373001211;
57 const int64 kEnabledDateExpected = 1373000400; // Computed from kEnabledDate.
58 const int kSessionId = 127;
59 const int kScreenWidth = 1024;
60 const int kScreenHeight = 768;
61 const int kScreenCount = 3;
62 const float kScreenScaleFactor = 2;
63 const char kBrandForTesting[] = "brand_for_testing";
64 const chrome_variations::ActiveGroupId kFieldTrialIds[] = {
65 {37, 43},
66 {13, 47},
67 {23, 17}
69 const chrome_variations::ActiveGroupId kSyntheticTrials[] = {
70 {55, 15},
71 {66, 16}
74 #if defined(ENABLE_PLUGINS)
75 content::WebPluginInfo CreateFakePluginInfo(
76 const std::string& name,
77 const base::FilePath::CharType* path,
78 const std::string& version,
79 bool is_pepper) {
80 content::WebPluginInfo plugin(base::UTF8ToUTF16(name),
81 base::FilePath(path),
82 base::UTF8ToUTF16(version),
83 base::string16());
84 if (is_pepper)
85 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS;
86 else
87 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_NPAPI;
88 return plugin;
90 #endif // defined(ENABLE_PLUGINS)
92 class TestMetricsLog : public MetricsLog {
93 public:
94 TestMetricsLog(const std::string& client_id, int session_id)
95 : MetricsLog(client_id, session_id),
96 prefs_(&scoped_prefs_),
97 brand_for_testing_(kBrandForTesting) {
98 chrome::RegisterLocalState(scoped_prefs_.registry());
99 InitPrefs();
101 // Creates a TestMetricsLog that will use |prefs| as the fake local state.
102 // Useful for tests that need to re-use the local state prefs between logs.
103 TestMetricsLog(const std::string& client_id,
104 int session_id,
105 TestingPrefServiceSimple* prefs)
106 : MetricsLog(client_id, session_id),
107 prefs_(prefs),
108 brand_for_testing_(kBrandForTesting) {
109 InitPrefs();
111 virtual ~TestMetricsLog() {}
113 virtual PrefService* GetPrefService() OVERRIDE {
114 return prefs_;
117 const metrics::ChromeUserMetricsExtension& uma_proto() const {
118 return *MetricsLog::uma_proto();
121 const metrics::SystemProfileProto& system_profile() const {
122 return uma_proto().system_profile();
125 private:
126 void InitPrefs() {
127 prefs_->SetInt64(prefs::kInstallDate, kInstallDate);
128 prefs_->SetString(prefs::kMetricsClientIDTimestamp,
129 base::Int64ToString(kEnabledDate));
130 #if defined(OS_CHROMEOS)
131 prefs_->SetInteger(prefs::kStabilityChildProcessCrashCount, 10);
132 prefs_->SetInteger(prefs::kStabilityOtherUserCrashCount, 11);
133 prefs_->SetInteger(prefs::kStabilityKernelCrashCount, 12);
134 prefs_->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 13);
135 #endif // OS_CHROMEOS
138 virtual void GetFieldTrialIds(
139 std::vector<chrome_variations::ActiveGroupId>* field_trial_ids) const
140 OVERRIDE {
141 ASSERT_TRUE(field_trial_ids->empty());
143 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) {
144 field_trial_ids->push_back(kFieldTrialIds[i]);
148 virtual gfx::Size GetScreenSize() const OVERRIDE {
149 return gfx::Size(kScreenWidth, kScreenHeight);
152 virtual float GetScreenDeviceScaleFactor() const OVERRIDE {
153 return kScreenScaleFactor;
156 virtual int GetScreenCount() const OVERRIDE {
157 return kScreenCount;
160 virtual void WriteBluetoothProto(
161 metrics::SystemProfileProto::Hardware* hardware) OVERRIDE {
164 // Scoped PrefsService, which may not be used if |prefs_ != &scoped_prefs|.
165 TestingPrefServiceSimple scoped_prefs_;
166 // Weak pointer to the PrefsService used by this log.
167 TestingPrefServiceSimple* prefs_;
169 google_util::BrandForTesting brand_for_testing_;
171 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog);
174 } // namespace
176 class MetricsLogTest : public testing::Test {
177 public:
178 MetricsLogTest() {}
180 protected:
181 virtual void SetUp() OVERRIDE {
182 #if defined(OS_CHROMEOS)
183 // Enable multi-profiles.
184 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles);
185 #endif // OS_CHROMEOS
188 // Check that the values in |system_values| correspond to the test data
189 // defined at the top of this file.
190 void CheckSystemProfile(const metrics::SystemProfileProto& system_profile) {
191 EXPECT_EQ(kInstallDateExpected, system_profile.install_date());
192 EXPECT_EQ(kEnabledDateExpected, system_profile.uma_enabled_date());
194 ASSERT_EQ(arraysize(kFieldTrialIds) + arraysize(kSyntheticTrials),
195 static_cast<size_t>(system_profile.field_trial_size()));
196 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) {
197 const metrics::SystemProfileProto::FieldTrial& field_trial =
198 system_profile.field_trial(i);
199 EXPECT_EQ(kFieldTrialIds[i].name, field_trial.name_id());
200 EXPECT_EQ(kFieldTrialIds[i].group, field_trial.group_id());
202 // Verify the right data is present for the synthetic trials.
203 for (size_t i = 0; i < arraysize(kSyntheticTrials); ++i) {
204 const metrics::SystemProfileProto::FieldTrial& field_trial =
205 system_profile.field_trial(i + arraysize(kFieldTrialIds));
206 EXPECT_EQ(kSyntheticTrials[i].name, field_trial.name_id());
207 EXPECT_EQ(kSyntheticTrials[i].group, field_trial.group_id());
210 EXPECT_EQ(kBrandForTesting, system_profile.brand_code());
212 const metrics::SystemProfileProto::Hardware& hardware =
213 system_profile.hardware();
214 EXPECT_EQ(kScreenWidth, hardware.primary_screen_width());
215 EXPECT_EQ(kScreenHeight, hardware.primary_screen_height());
216 EXPECT_EQ(kScreenScaleFactor, hardware.primary_screen_scale_factor());
217 EXPECT_EQ(kScreenCount, hardware.screen_count());
219 EXPECT_TRUE(hardware.has_cpu());
220 EXPECT_TRUE(hardware.cpu().has_vendor_name());
221 EXPECT_TRUE(hardware.cpu().has_signature());
223 // TODO(isherman): Verify other data written into the protobuf as a result
224 // of this call.
227 private:
228 content::TestBrowserThreadBundle thread_bundle_;
230 DISALLOW_COPY_AND_ASSIGN(MetricsLogTest);
233 TEST_F(MetricsLogTest, RecordEnvironment) {
234 TestMetricsLog log(kClientId, kSessionId);
236 std::vector<content::WebPluginInfo> plugins;
237 GoogleUpdateMetrics google_update_metrics;
238 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
239 // Add two synthetic trials.
240 synthetic_trials.push_back(kSyntheticTrials[0]);
241 synthetic_trials.push_back(kSyntheticTrials[1]);
243 log.RecordEnvironment(plugins, google_update_metrics, synthetic_trials);
244 // Check that the system profile on the log has the correct values set.
245 CheckSystemProfile(log.system_profile());
247 // Check that the system profile has also been written to prefs.
248 PrefService* local_state = log.GetPrefService();
249 const std::string base64_system_profile =
250 local_state->GetString(prefs::kStabilitySavedSystemProfile);
251 EXPECT_FALSE(base64_system_profile.empty());
252 std::string serialied_system_profile;
253 EXPECT_TRUE(base::Base64Decode(base64_system_profile,
254 &serialied_system_profile));
255 SystemProfileProto decoded_system_profile;
256 EXPECT_TRUE(decoded_system_profile.ParseFromString(serialied_system_profile));
257 CheckSystemProfile(decoded_system_profile);
260 TEST_F(MetricsLogTest, LoadSavedEnvironmentFromPrefs) {
261 const char* kSystemProfilePref = prefs::kStabilitySavedSystemProfile;
262 const char* kSystemProfileHashPref = prefs::kStabilitySavedSystemProfileHash;
264 TestingPrefServiceSimple prefs;
265 chrome::RegisterLocalState(prefs.registry());
267 // The pref value is empty, so loading it from prefs should fail.
269 TestMetricsLog log(kClientId, kSessionId, &prefs);
270 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs());
273 // Do a RecordEnvironment() call and check whether the pref is recorded.
275 TestMetricsLog log(kClientId, kSessionId, &prefs);
276 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
277 GoogleUpdateMetrics(),
278 std::vector<chrome_variations::ActiveGroupId>());
279 EXPECT_FALSE(prefs.GetString(kSystemProfilePref).empty());
280 EXPECT_FALSE(prefs.GetString(kSystemProfileHashPref).empty());
284 TestMetricsLog log(kClientId, kSessionId, &prefs);
285 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs());
286 // Check some values in the system profile.
287 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date());
288 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date());
289 // Ensure that the call cleared the prefs.
290 EXPECT_TRUE(prefs.GetString(kSystemProfilePref).empty());
291 EXPECT_TRUE(prefs.GetString(kSystemProfileHashPref).empty());
294 // Ensure that a non-matching hash results in the pref being invalid.
296 TestMetricsLog log(kClientId, kSessionId, &prefs);
297 // Call RecordEnvironment() to record the pref again.
298 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
299 GoogleUpdateMetrics(),
300 std::vector<chrome_variations::ActiveGroupId>());
304 // Set the hash to a bad value.
305 prefs.SetString(kSystemProfileHashPref, "deadbeef");
306 TestMetricsLog log(kClientId, kSessionId, &prefs);
307 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs());
308 // Ensure that the prefs are cleared, even if the call failed.
309 EXPECT_TRUE(prefs.GetString(kSystemProfilePref).empty());
310 EXPECT_TRUE(prefs.GetString(kSystemProfileHashPref).empty());
314 TEST_F(MetricsLogTest, InitialLogStabilityMetrics) {
315 TestMetricsLog log(kClientId, kSessionId);
316 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
317 GoogleUpdateMetrics(),
318 std::vector<chrome_variations::ActiveGroupId>());
319 log.RecordStabilityMetrics(base::TimeDelta(), MetricsLog::INITIAL_LOG);
320 const metrics::SystemProfileProto_Stability& stability =
321 log.system_profile().stability();
322 // Required metrics:
323 EXPECT_TRUE(stability.has_launch_count());
324 EXPECT_TRUE(stability.has_crash_count());
325 // Initial log metrics:
326 EXPECT_TRUE(stability.has_incomplete_shutdown_count());
327 EXPECT_TRUE(stability.has_breakpad_registration_success_count());
328 EXPECT_TRUE(stability.has_breakpad_registration_failure_count());
329 EXPECT_TRUE(stability.has_debugger_present_count());
330 EXPECT_TRUE(stability.has_debugger_not_present_count());
333 TEST_F(MetricsLogTest, OngoingLogStabilityMetrics) {
334 TestMetricsLog log(kClientId, kSessionId);
335 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
336 GoogleUpdateMetrics(),
337 std::vector<chrome_variations::ActiveGroupId>());
338 log.RecordStabilityMetrics(base::TimeDelta(), MetricsLog::ONGOING_LOG);
339 const metrics::SystemProfileProto_Stability& stability =
340 log.system_profile().stability();
341 // Required metrics:
342 EXPECT_TRUE(stability.has_launch_count());
343 EXPECT_TRUE(stability.has_crash_count());
344 // Initial log metrics:
345 EXPECT_FALSE(stability.has_incomplete_shutdown_count());
346 EXPECT_FALSE(stability.has_breakpad_registration_success_count());
347 EXPECT_FALSE(stability.has_breakpad_registration_failure_count());
348 EXPECT_FALSE(stability.has_debugger_present_count());
349 EXPECT_FALSE(stability.has_debugger_not_present_count());
352 #if defined(ENABLE_PLUGINS)
353 TEST_F(MetricsLogTest, Plugins) {
354 TestMetricsLog log(kClientId, kSessionId);
356 std::vector<content::WebPluginInfo> plugins;
357 plugins.push_back(CreateFakePluginInfo("p1", FILE_PATH_LITERAL("p1.plugin"),
358 "1.5", true));
359 plugins.push_back(CreateFakePluginInfo("p2", FILE_PATH_LITERAL("p2.plugin"),
360 "2.0", false));
361 log.RecordEnvironment(plugins, GoogleUpdateMetrics(),
362 std::vector<chrome_variations::ActiveGroupId>());
364 const metrics::SystemProfileProto& system_profile = log.system_profile();
365 ASSERT_EQ(2, system_profile.plugin_size());
366 EXPECT_EQ("p1", system_profile.plugin(0).name());
367 EXPECT_EQ("p1.plugin", system_profile.plugin(0).filename());
368 EXPECT_EQ("1.5", system_profile.plugin(0).version());
369 EXPECT_TRUE(system_profile.plugin(0).is_pepper());
370 EXPECT_EQ("p2", system_profile.plugin(1).name());
371 EXPECT_EQ("p2.plugin", system_profile.plugin(1).filename());
372 EXPECT_EQ("2.0", system_profile.plugin(1).version());
373 EXPECT_FALSE(system_profile.plugin(1).is_pepper());
375 // Now set some plugin stability stats for p2 and verify they're recorded.
376 scoped_ptr<base::DictionaryValue> plugin_dict(new base::DictionaryValue);
377 plugin_dict->SetString(prefs::kStabilityPluginName, "p2");
378 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, 1);
379 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, 2);
380 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, 3);
381 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, 4);
383 ListPrefUpdate update(log.GetPrefService(), prefs::kStabilityPluginStats);
384 update.Get()->Append(plugin_dict.release());
387 log.RecordStabilityMetrics(base::TimeDelta(), MetricsLog::ONGOING_LOG);
388 const metrics::SystemProfileProto_Stability& stability =
389 log.system_profile().stability();
390 ASSERT_EQ(1, stability.plugin_stability_size());
391 EXPECT_EQ("p2", stability.plugin_stability(0).plugin().name());
392 EXPECT_EQ("p2.plugin", stability.plugin_stability(0).plugin().filename());
393 EXPECT_EQ("2.0", stability.plugin_stability(0).plugin().version());
394 EXPECT_FALSE(stability.plugin_stability(0).plugin().is_pepper());
395 EXPECT_EQ(1, stability.plugin_stability(0).launch_count());
396 EXPECT_EQ(2, stability.plugin_stability(0).crash_count());
397 EXPECT_EQ(3, stability.plugin_stability(0).instance_count());
398 EXPECT_EQ(4, stability.plugin_stability(0).loading_error_count());
400 #endif // defined(ENABLE_PLUGINS)
402 // Test that we properly write profiler data to the log.
403 TEST_F(MetricsLogTest, RecordProfilerData) {
404 TestMetricsLog log(kClientId, kSessionId);
405 EXPECT_EQ(0, log.uma_proto().profiler_event_size());
408 ProcessDataSnapshot process_data;
409 process_data.process_id = 177;
410 process_data.tasks.push_back(TaskSnapshot());
411 process_data.tasks.back().birth.location.file_name = "file";
412 process_data.tasks.back().birth.location.function_name = "function";
413 process_data.tasks.back().birth.location.line_number = 1337;
414 process_data.tasks.back().birth.thread_name = "birth_thread";
415 process_data.tasks.back().death_data.count = 37;
416 process_data.tasks.back().death_data.run_duration_sum = 31;
417 process_data.tasks.back().death_data.run_duration_max = 17;
418 process_data.tasks.back().death_data.run_duration_sample = 13;
419 process_data.tasks.back().death_data.queue_duration_sum = 8;
420 process_data.tasks.back().death_data.queue_duration_max = 5;
421 process_data.tasks.back().death_data.queue_duration_sample = 3;
422 process_data.tasks.back().death_thread_name = "Still_Alive";
423 process_data.tasks.push_back(TaskSnapshot());
424 process_data.tasks.back().birth.location.file_name = "file2";
425 process_data.tasks.back().birth.location.function_name = "function2";
426 process_data.tasks.back().birth.location.line_number = 1773;
427 process_data.tasks.back().birth.thread_name = "birth_thread2";
428 process_data.tasks.back().death_data.count = 19;
429 process_data.tasks.back().death_data.run_duration_sum = 23;
430 process_data.tasks.back().death_data.run_duration_max = 11;
431 process_data.tasks.back().death_data.run_duration_sample = 7;
432 process_data.tasks.back().death_data.queue_duration_sum = 0;
433 process_data.tasks.back().death_data.queue_duration_max = 0;
434 process_data.tasks.back().death_data.queue_duration_sample = 0;
435 process_data.tasks.back().death_thread_name = "death_thread";
437 log.RecordProfilerData(process_data, content::PROCESS_TYPE_BROWSER);
438 ASSERT_EQ(1, log.uma_proto().profiler_event_size());
439 EXPECT_EQ(ProfilerEventProto::STARTUP_PROFILE,
440 log.uma_proto().profiler_event(0).profile_type());
441 EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME,
442 log.uma_proto().profiler_event(0).time_source());
444 ASSERT_EQ(2, log.uma_proto().profiler_event(0).tracked_object_size());
446 const ProfilerEventProto::TrackedObject* tracked_object =
447 &log.uma_proto().profiler_event(0).tracked_object(0);
448 EXPECT_EQ(GG_UINT64_C(10123486280357988687),
449 tracked_object->source_file_name_hash());
450 EXPECT_EQ(GG_UINT64_C(13962325592283560029),
451 tracked_object->source_function_name_hash());
452 EXPECT_EQ(1337, tracked_object->source_line_number());
453 EXPECT_EQ(GG_UINT64_C(3400908935414830400),
454 tracked_object->birth_thread_name_hash());
455 EXPECT_EQ(37, tracked_object->exec_count());
456 EXPECT_EQ(31, tracked_object->exec_time_total());
457 EXPECT_EQ(13, tracked_object->exec_time_sampled());
458 EXPECT_EQ(8, tracked_object->queue_time_total());
459 EXPECT_EQ(3, tracked_object->queue_time_sampled());
460 EXPECT_EQ(GG_UINT64_C(10151977472163283085),
461 tracked_object->exec_thread_name_hash());
462 EXPECT_EQ(177U, tracked_object->process_id());
463 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER,
464 tracked_object->process_type());
466 tracked_object = &log.uma_proto().profiler_event(0).tracked_object(1);
467 EXPECT_EQ(GG_UINT64_C(2025659946535236365),
468 tracked_object->source_file_name_hash());
469 EXPECT_EQ(GG_UINT64_C(55232426147951219),
470 tracked_object->source_function_name_hash());
471 EXPECT_EQ(1773, tracked_object->source_line_number());
472 EXPECT_EQ(GG_UINT64_C(15727396632046120663),
473 tracked_object->birth_thread_name_hash());
474 EXPECT_EQ(19, tracked_object->exec_count());
475 EXPECT_EQ(23, tracked_object->exec_time_total());
476 EXPECT_EQ(7, tracked_object->exec_time_sampled());
477 EXPECT_EQ(0, tracked_object->queue_time_total());
478 EXPECT_EQ(0, tracked_object->queue_time_sampled());
479 EXPECT_EQ(GG_UINT64_C(14275151213201158253),
480 tracked_object->exec_thread_name_hash());
481 EXPECT_EQ(177U, tracked_object->process_id());
482 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER,
483 tracked_object->process_type());
487 ProcessDataSnapshot process_data;
488 process_data.process_id = 1177;
489 process_data.tasks.push_back(TaskSnapshot());
490 process_data.tasks.back().birth.location.file_name = "file3";
491 process_data.tasks.back().birth.location.function_name = "function3";
492 process_data.tasks.back().birth.location.line_number = 7331;
493 process_data.tasks.back().birth.thread_name = "birth_thread3";
494 process_data.tasks.back().death_data.count = 137;
495 process_data.tasks.back().death_data.run_duration_sum = 131;
496 process_data.tasks.back().death_data.run_duration_max = 117;
497 process_data.tasks.back().death_data.run_duration_sample = 113;
498 process_data.tasks.back().death_data.queue_duration_sum = 108;
499 process_data.tasks.back().death_data.queue_duration_max = 105;
500 process_data.tasks.back().death_data.queue_duration_sample = 103;
501 process_data.tasks.back().death_thread_name = "death_thread3";
503 log.RecordProfilerData(process_data, content::PROCESS_TYPE_RENDERER);
504 ASSERT_EQ(1, log.uma_proto().profiler_event_size());
505 EXPECT_EQ(ProfilerEventProto::STARTUP_PROFILE,
506 log.uma_proto().profiler_event(0).profile_type());
507 EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME,
508 log.uma_proto().profiler_event(0).time_source());
509 ASSERT_EQ(3, log.uma_proto().profiler_event(0).tracked_object_size());
511 const ProfilerEventProto::TrackedObject* tracked_object =
512 &log.uma_proto().profiler_event(0).tracked_object(2);
513 EXPECT_EQ(GG_UINT64_C(2686523203278102732),
514 tracked_object->source_file_name_hash());
515 EXPECT_EQ(GG_UINT64_C(5081672290546182009),
516 tracked_object->source_function_name_hash());
517 EXPECT_EQ(7331, tracked_object->source_line_number());
518 EXPECT_EQ(GG_UINT64_C(8768512930949373716),
519 tracked_object->birth_thread_name_hash());
520 EXPECT_EQ(137, tracked_object->exec_count());
521 EXPECT_EQ(131, tracked_object->exec_time_total());
522 EXPECT_EQ(113, tracked_object->exec_time_sampled());
523 EXPECT_EQ(108, tracked_object->queue_time_total());
524 EXPECT_EQ(103, tracked_object->queue_time_sampled());
525 EXPECT_EQ(GG_UINT64_C(7246674144371406371),
526 tracked_object->exec_thread_name_hash());
527 EXPECT_EQ(1177U, tracked_object->process_id());
528 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER,
529 tracked_object->process_type());
533 #if defined(OS_CHROMEOS)
534 TEST_F(MetricsLogTest, MultiProfileUserCount) {
535 std::string user1("user1@example.com");
536 std::string user2("user2@example.com");
537 std::string user3("user3@example.com");
539 // |scoped_enabler| takes over the lifetime of |user_manager|.
540 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager();
541 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager);
542 user_manager->AddKioskAppUser(user1);
543 user_manager->AddKioskAppUser(user2);
544 user_manager->AddKioskAppUser(user3);
546 user_manager->LoginUser(user1);
547 user_manager->LoginUser(user3);
549 TestMetricsLog log(kClientId, kSessionId);
550 std::vector<content::WebPluginInfo> plugins;
551 GoogleUpdateMetrics google_update_metrics;
552 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
553 log.RecordEnvironment(plugins, google_update_metrics, synthetic_trials);
554 EXPECT_EQ(2u, log.system_profile().multi_profile_user_count());
557 TEST_F(MetricsLogTest, MultiProfileCountInvalidated) {
558 std::string user1("user1@example.com");
559 std::string user2("user2@example.com");
560 std::string user3("user3@example.com");
562 // |scoped_enabler| takes over the lifetime of |user_manager|.
563 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager();
564 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager);
565 user_manager->AddKioskAppUser(user1);
566 user_manager->AddKioskAppUser(user2);
567 user_manager->AddKioskAppUser(user3);
569 user_manager->LoginUser(user1);
571 TestMetricsLog log(kClientId, kSessionId);
572 EXPECT_EQ(1u, log.system_profile().multi_profile_user_count());
574 user_manager->LoginUser(user2);
575 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
576 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
577 GoogleUpdateMetrics(), synthetic_trials);
578 EXPECT_EQ(0u, log.system_profile().multi_profile_user_count());
580 #endif // OS_CHROMEOS