Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / metrics / metrics_log_unittest.cc
blobd95203f8bd31305d92cc0445e9973fab79bdf4e0
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/metrics/field_trial.h"
13 #include "base/port.h"
14 #include "base/prefs/pref_service.h"
15 #include "base/prefs/scoped_user_pref_update.h"
16 #include "base/prefs/testing_pref_service.h"
17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h"
20 #include "base/strings/utf_string_conversions.h"
21 #include "base/threading/sequenced_worker_pool.h"
22 #include "base/time/time.h"
23 #include "base/tracked_objects.h"
24 #include "chrome/browser/google/google_util.h"
25 #include "chrome/browser/prefs/browser_prefs.h"
26 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/metrics/proto/profiler_event.pb.h"
28 #include "chrome/common/metrics/proto/system_profile.pb.h"
29 #include "chrome/common/metrics/variations/variations_util.h"
30 #include "chrome/common/pref_names.h"
31 #include "chrome/installer/util/google_update_settings.h"
32 #include "components/variations/entropy_provider.h"
33 #include "components/variations/metrics_util.h"
34 #include "content/public/browser/browser_thread.h"
35 #include "content/public/common/process_type.h"
36 #include "content/public/common/webplugininfo.h"
37 #include "content/public/test/test_browser_thread_bundle.h"
38 #include "content/public/test/test_utils.h"
39 #include "testing/gtest/include/gtest/gtest.h"
40 #include "ui/gfx/size.h"
41 #include "url/gurl.h"
43 #if defined(OS_CHROMEOS)
44 #include "chrome/browser/chromeos/login/fake_user_manager.h"
45 #include "chrome/browser/chromeos/login/user_manager.h"
46 #endif // OS_CHROMEOS
48 using base::TimeDelta;
49 using metrics::ProfilerEventProto;
50 using tracked_objects::ProcessDataSnapshot;
51 using tracked_objects::TaskSnapshot;
53 namespace {
55 const char kClientId[] = "bogus client ID";
56 const int64 kInstallDate = 1373051956;
57 const int64 kInstallDateExpected = 1373050800; // Computed from kInstallDate.
58 const int64 kEnabledDate = 1373001211;
59 const int64 kEnabledDateExpected = 1373000400; // Computed from kEnabledDate.
60 const int kSessionId = 127;
61 const int kScreenWidth = 1024;
62 const int kScreenHeight = 768;
63 const int kScreenCount = 3;
64 const float kScreenScaleFactor = 2;
65 const char kBrandForTesting[] = "brand_for_testing";
66 const chrome_variations::ActiveGroupId kFieldTrialIds[] = {
67 {37, 43},
68 {13, 47},
69 {23, 17}
71 const chrome_variations::ActiveGroupId kSyntheticTrials[] = {
72 {55, 15},
73 {66, 16}
76 #if defined(ENABLE_PLUGINS)
77 content::WebPluginInfo CreateFakePluginInfo(
78 const std::string& name,
79 const base::FilePath::CharType* path,
80 const std::string& version,
81 bool is_pepper) {
82 content::WebPluginInfo plugin(base::UTF8ToUTF16(name),
83 base::FilePath(path),
84 base::UTF8ToUTF16(version),
85 base::string16());
86 if (is_pepper)
87 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS;
88 else
89 plugin.type = content::WebPluginInfo::PLUGIN_TYPE_NPAPI;
90 return plugin;
92 #endif // defined(ENABLE_PLUGINS)
94 class TestMetricsLog : public MetricsLog {
95 public:
96 TestMetricsLog(const std::string& client_id, int session_id)
97 : MetricsLog(client_id, session_id),
98 prefs_(&scoped_prefs_),
99 brand_for_testing_(kBrandForTesting) {
100 chrome::RegisterLocalState(scoped_prefs_.registry());
101 InitPrefs();
103 // Creates a TestMetricsLog that will use |prefs| as the fake local state.
104 // Useful for tests that need to re-use the local state prefs between logs.
105 TestMetricsLog(const std::string& client_id,
106 int session_id,
107 TestingPrefServiceSimple* prefs)
108 : MetricsLog(client_id, session_id),
109 prefs_(prefs),
110 brand_for_testing_(kBrandForTesting) {
111 InitPrefs();
113 virtual ~TestMetricsLog() {}
115 virtual PrefService* GetPrefService() OVERRIDE {
116 return prefs_;
119 const metrics::ChromeUserMetricsExtension& uma_proto() const {
120 return *MetricsLog::uma_proto();
123 const metrics::SystemProfileProto& system_profile() const {
124 return uma_proto().system_profile();
127 private:
128 void InitPrefs() {
129 prefs_->SetInt64(prefs::kInstallDate, kInstallDate);
130 prefs_->SetString(prefs::kMetricsClientIDTimestamp,
131 base::Int64ToString(kEnabledDate));
132 #if defined(OS_CHROMEOS)
133 prefs_->SetInteger(prefs::kStabilityChildProcessCrashCount, 10);
134 prefs_->SetInteger(prefs::kStabilityOtherUserCrashCount, 11);
135 prefs_->SetInteger(prefs::kStabilityKernelCrashCount, 12);
136 prefs_->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 13);
137 #endif // OS_CHROMEOS
140 virtual void GetFieldTrialIds(
141 std::vector<chrome_variations::ActiveGroupId>* field_trial_ids) const
142 OVERRIDE {
143 ASSERT_TRUE(field_trial_ids->empty());
145 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) {
146 field_trial_ids->push_back(kFieldTrialIds[i]);
150 virtual gfx::Size GetScreenSize() const OVERRIDE {
151 return gfx::Size(kScreenWidth, kScreenHeight);
154 virtual float GetScreenDeviceScaleFactor() const OVERRIDE {
155 return kScreenScaleFactor;
158 virtual int GetScreenCount() const OVERRIDE {
159 return kScreenCount;
162 virtual void WriteBluetoothProto(
163 metrics::SystemProfileProto::Hardware* hardware) OVERRIDE {
166 // Scoped PrefsService, which may not be used if |prefs_ != &scoped_prefs|.
167 TestingPrefServiceSimple scoped_prefs_;
168 // Weak pointer to the PrefsService used by this log.
169 TestingPrefServiceSimple* prefs_;
171 google_util::BrandForTesting brand_for_testing_;
173 DISALLOW_COPY_AND_ASSIGN(TestMetricsLog);
176 } // namespace
178 class MetricsLogTest : public testing::Test {
179 public:
180 MetricsLogTest() {}
182 protected:
183 virtual void SetUp() OVERRIDE {
184 #if defined(OS_CHROMEOS)
185 // Enable multi-profiles.
186 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles);
187 field_trial_list_.reset(new base::FieldTrialList(
188 new metrics::SHA1EntropyProvider("42")));
189 base::FieldTrialList::CreateTrialsFromString(
190 "ChromeOSUseMultiProfiles/Enable/",
191 base::FieldTrialList::ACTIVATE_TRIALS);
192 #endif // OS_CHROMEOS
195 // Check that the values in |system_values| correspond to the test data
196 // defined at the top of this file.
197 void CheckSystemProfile(const metrics::SystemProfileProto& system_profile) {
198 EXPECT_EQ(kInstallDateExpected, system_profile.install_date());
199 EXPECT_EQ(kEnabledDateExpected, system_profile.uma_enabled_date());
201 ASSERT_EQ(arraysize(kFieldTrialIds) + arraysize(kSyntheticTrials),
202 static_cast<size_t>(system_profile.field_trial_size()));
203 for (size_t i = 0; i < arraysize(kFieldTrialIds); ++i) {
204 const metrics::SystemProfileProto::FieldTrial& field_trial =
205 system_profile.field_trial(i);
206 EXPECT_EQ(kFieldTrialIds[i].name, field_trial.name_id());
207 EXPECT_EQ(kFieldTrialIds[i].group, field_trial.group_id());
209 // Verify the right data is present for the synthetic trials.
210 for (size_t i = 0; i < arraysize(kSyntheticTrials); ++i) {
211 const metrics::SystemProfileProto::FieldTrial& field_trial =
212 system_profile.field_trial(i + arraysize(kFieldTrialIds));
213 EXPECT_EQ(kSyntheticTrials[i].name, field_trial.name_id());
214 EXPECT_EQ(kSyntheticTrials[i].group, field_trial.group_id());
217 EXPECT_EQ(kBrandForTesting, system_profile.brand_code());
219 const metrics::SystemProfileProto::Hardware& hardware =
220 system_profile.hardware();
221 EXPECT_EQ(kScreenWidth, hardware.primary_screen_width());
222 EXPECT_EQ(kScreenHeight, hardware.primary_screen_height());
223 EXPECT_EQ(kScreenScaleFactor, hardware.primary_screen_scale_factor());
224 EXPECT_EQ(kScreenCount, hardware.screen_count());
226 EXPECT_TRUE(hardware.has_cpu());
227 EXPECT_TRUE(hardware.cpu().has_vendor_name());
228 EXPECT_TRUE(hardware.cpu().has_signature());
230 // TODO(isherman): Verify other data written into the protobuf as a result
231 // of this call.
234 private:
235 content::TestBrowserThreadBundle thread_bundle_;
237 #if defined(OS_CHROMEOS)
238 scoped_ptr<base::FieldTrialList> field_trial_list_;
239 #endif // OS_CHROMEOS
242 TEST_F(MetricsLogTest, RecordEnvironment) {
243 TestMetricsLog log(kClientId, kSessionId);
245 std::vector<content::WebPluginInfo> plugins;
246 GoogleUpdateMetrics google_update_metrics;
247 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
248 // Add two synthetic trials.
249 synthetic_trials.push_back(kSyntheticTrials[0]);
250 synthetic_trials.push_back(kSyntheticTrials[1]);
252 log.RecordEnvironment(plugins, google_update_metrics, synthetic_trials);
253 // Check that the system profile on the log has the correct values set.
254 CheckSystemProfile(log.system_profile());
256 // Check that the system profile has also been written to prefs.
257 PrefService* local_state = log.GetPrefService();
258 const std::string base64_system_profile =
259 local_state->GetString(prefs::kStabilitySavedSystemProfile);
260 EXPECT_FALSE(base64_system_profile.empty());
261 std::string serialied_system_profile;
262 EXPECT_TRUE(base::Base64Decode(base64_system_profile,
263 &serialied_system_profile));
264 SystemProfileProto decoded_system_profile;
265 EXPECT_TRUE(decoded_system_profile.ParseFromString(serialied_system_profile));
266 CheckSystemProfile(decoded_system_profile);
269 TEST_F(MetricsLogTest, LoadSavedEnvironmentFromPrefs) {
270 const char* kSystemProfilePref = prefs::kStabilitySavedSystemProfile;
271 const char* kSystemProfileHashPref = prefs::kStabilitySavedSystemProfileHash;
273 TestingPrefServiceSimple prefs;
274 chrome::RegisterLocalState(prefs.registry());
276 // The pref value is empty, so loading it from prefs should fail.
278 TestMetricsLog log(kClientId, kSessionId, &prefs);
279 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs());
282 // Do a RecordEnvironment() call and check whether the pref is recorded.
284 TestMetricsLog log(kClientId, kSessionId, &prefs);
285 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
286 GoogleUpdateMetrics(),
287 std::vector<chrome_variations::ActiveGroupId>());
288 EXPECT_FALSE(prefs.GetString(kSystemProfilePref).empty());
289 EXPECT_FALSE(prefs.GetString(kSystemProfileHashPref).empty());
293 TestMetricsLog log(kClientId, kSessionId, &prefs);
294 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs());
295 // Check some values in the system profile.
296 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date());
297 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date());
298 // Ensure that the call cleared the prefs.
299 EXPECT_TRUE(prefs.GetString(kSystemProfilePref).empty());
300 EXPECT_TRUE(prefs.GetString(kSystemProfileHashPref).empty());
303 // Ensure that a non-matching hash results in the pref being invalid.
305 TestMetricsLog log(kClientId, kSessionId, &prefs);
306 // Call RecordEnvironment() to record the pref again.
307 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
308 GoogleUpdateMetrics(),
309 std::vector<chrome_variations::ActiveGroupId>());
313 // Set the hash to a bad value.
314 prefs.SetString(kSystemProfileHashPref, "deadbeef");
315 TestMetricsLog log(kClientId, kSessionId, &prefs);
316 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs());
317 // Ensure that the prefs are cleared, even if the call failed.
318 EXPECT_TRUE(prefs.GetString(kSystemProfilePref).empty());
319 EXPECT_TRUE(prefs.GetString(kSystemProfileHashPref).empty());
323 TEST_F(MetricsLogTest, InitialLogStabilityMetrics) {
324 TestMetricsLog log(kClientId, kSessionId);
325 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
326 GoogleUpdateMetrics(),
327 std::vector<chrome_variations::ActiveGroupId>());
328 log.RecordStabilityMetrics(base::TimeDelta(), MetricsLog::INITIAL_LOG);
329 const metrics::SystemProfileProto_Stability& stability =
330 log.system_profile().stability();
331 // Required metrics:
332 EXPECT_TRUE(stability.has_launch_count());
333 EXPECT_TRUE(stability.has_crash_count());
334 // Initial log metrics:
335 EXPECT_TRUE(stability.has_incomplete_shutdown_count());
336 EXPECT_TRUE(stability.has_breakpad_registration_success_count());
337 EXPECT_TRUE(stability.has_breakpad_registration_failure_count());
338 EXPECT_TRUE(stability.has_debugger_present_count());
339 EXPECT_TRUE(stability.has_debugger_not_present_count());
342 TEST_F(MetricsLogTest, OngoingLogStabilityMetrics) {
343 TestMetricsLog log(kClientId, kSessionId);
344 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
345 GoogleUpdateMetrics(),
346 std::vector<chrome_variations::ActiveGroupId>());
347 log.RecordStabilityMetrics(base::TimeDelta(), MetricsLog::ONGOING_LOG);
348 const metrics::SystemProfileProto_Stability& stability =
349 log.system_profile().stability();
350 // Required metrics:
351 EXPECT_TRUE(stability.has_launch_count());
352 EXPECT_TRUE(stability.has_crash_count());
353 // Initial log metrics:
354 EXPECT_FALSE(stability.has_incomplete_shutdown_count());
355 EXPECT_FALSE(stability.has_breakpad_registration_success_count());
356 EXPECT_FALSE(stability.has_breakpad_registration_failure_count());
357 EXPECT_FALSE(stability.has_debugger_present_count());
358 EXPECT_FALSE(stability.has_debugger_not_present_count());
361 #if defined(ENABLE_PLUGINS)
362 TEST_F(MetricsLogTest, Plugins) {
363 TestMetricsLog log(kClientId, kSessionId);
365 std::vector<content::WebPluginInfo> plugins;
366 plugins.push_back(CreateFakePluginInfo("p1", FILE_PATH_LITERAL("p1.plugin"),
367 "1.5", true));
368 plugins.push_back(CreateFakePluginInfo("p2", FILE_PATH_LITERAL("p2.plugin"),
369 "2.0", false));
370 log.RecordEnvironment(plugins, GoogleUpdateMetrics(),
371 std::vector<chrome_variations::ActiveGroupId>());
373 const metrics::SystemProfileProto& system_profile = log.system_profile();
374 ASSERT_EQ(2, system_profile.plugin_size());
375 EXPECT_EQ("p1", system_profile.plugin(0).name());
376 EXPECT_EQ("p1.plugin", system_profile.plugin(0).filename());
377 EXPECT_EQ("1.5", system_profile.plugin(0).version());
378 EXPECT_TRUE(system_profile.plugin(0).is_pepper());
379 EXPECT_EQ("p2", system_profile.plugin(1).name());
380 EXPECT_EQ("p2.plugin", system_profile.plugin(1).filename());
381 EXPECT_EQ("2.0", system_profile.plugin(1).version());
382 EXPECT_FALSE(system_profile.plugin(1).is_pepper());
384 // Now set some plugin stability stats for p2 and verify they're recorded.
385 scoped_ptr<base::DictionaryValue> plugin_dict(new base::DictionaryValue);
386 plugin_dict->SetString(prefs::kStabilityPluginName, "p2");
387 plugin_dict->SetInteger(prefs::kStabilityPluginLaunches, 1);
388 plugin_dict->SetInteger(prefs::kStabilityPluginCrashes, 2);
389 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, 3);
390 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, 4);
392 ListPrefUpdate update(log.GetPrefService(), prefs::kStabilityPluginStats);
393 update.Get()->Append(plugin_dict.release());
396 log.RecordStabilityMetrics(base::TimeDelta(), MetricsLog::ONGOING_LOG);
397 const metrics::SystemProfileProto_Stability& stability =
398 log.system_profile().stability();
399 ASSERT_EQ(1, stability.plugin_stability_size());
400 EXPECT_EQ("p2", stability.plugin_stability(0).plugin().name());
401 EXPECT_EQ("p2.plugin", stability.plugin_stability(0).plugin().filename());
402 EXPECT_EQ("2.0", stability.plugin_stability(0).plugin().version());
403 EXPECT_FALSE(stability.plugin_stability(0).plugin().is_pepper());
404 EXPECT_EQ(1, stability.plugin_stability(0).launch_count());
405 EXPECT_EQ(2, stability.plugin_stability(0).crash_count());
406 EXPECT_EQ(3, stability.plugin_stability(0).instance_count());
407 EXPECT_EQ(4, stability.plugin_stability(0).loading_error_count());
409 #endif // defined(ENABLE_PLUGINS)
411 // Test that we properly write profiler data to the log.
412 TEST_F(MetricsLogTest, RecordProfilerData) {
413 TestMetricsLog log(kClientId, kSessionId);
414 EXPECT_EQ(0, log.uma_proto().profiler_event_size());
417 ProcessDataSnapshot process_data;
418 process_data.process_id = 177;
419 process_data.tasks.push_back(TaskSnapshot());
420 process_data.tasks.back().birth.location.file_name = "file";
421 process_data.tasks.back().birth.location.function_name = "function";
422 process_data.tasks.back().birth.location.line_number = 1337;
423 process_data.tasks.back().birth.thread_name = "birth_thread";
424 process_data.tasks.back().death_data.count = 37;
425 process_data.tasks.back().death_data.run_duration_sum = 31;
426 process_data.tasks.back().death_data.run_duration_max = 17;
427 process_data.tasks.back().death_data.run_duration_sample = 13;
428 process_data.tasks.back().death_data.queue_duration_sum = 8;
429 process_data.tasks.back().death_data.queue_duration_max = 5;
430 process_data.tasks.back().death_data.queue_duration_sample = 3;
431 process_data.tasks.back().death_thread_name = "Still_Alive";
432 process_data.tasks.push_back(TaskSnapshot());
433 process_data.tasks.back().birth.location.file_name = "file2";
434 process_data.tasks.back().birth.location.function_name = "function2";
435 process_data.tasks.back().birth.location.line_number = 1773;
436 process_data.tasks.back().birth.thread_name = "birth_thread2";
437 process_data.tasks.back().death_data.count = 19;
438 process_data.tasks.back().death_data.run_duration_sum = 23;
439 process_data.tasks.back().death_data.run_duration_max = 11;
440 process_data.tasks.back().death_data.run_duration_sample = 7;
441 process_data.tasks.back().death_data.queue_duration_sum = 0;
442 process_data.tasks.back().death_data.queue_duration_max = 0;
443 process_data.tasks.back().death_data.queue_duration_sample = 0;
444 process_data.tasks.back().death_thread_name = "death_thread";
446 log.RecordProfilerData(process_data, content::PROCESS_TYPE_BROWSER);
447 ASSERT_EQ(1, log.uma_proto().profiler_event_size());
448 EXPECT_EQ(ProfilerEventProto::STARTUP_PROFILE,
449 log.uma_proto().profiler_event(0).profile_type());
450 EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME,
451 log.uma_proto().profiler_event(0).time_source());
453 ASSERT_EQ(2, log.uma_proto().profiler_event(0).tracked_object_size());
455 const ProfilerEventProto::TrackedObject* tracked_object =
456 &log.uma_proto().profiler_event(0).tracked_object(0);
457 EXPECT_EQ(GG_UINT64_C(10123486280357988687),
458 tracked_object->source_file_name_hash());
459 EXPECT_EQ(GG_UINT64_C(13962325592283560029),
460 tracked_object->source_function_name_hash());
461 EXPECT_EQ(1337, tracked_object->source_line_number());
462 EXPECT_EQ(GG_UINT64_C(3400908935414830400),
463 tracked_object->birth_thread_name_hash());
464 EXPECT_EQ(37, tracked_object->exec_count());
465 EXPECT_EQ(31, tracked_object->exec_time_total());
466 EXPECT_EQ(13, tracked_object->exec_time_sampled());
467 EXPECT_EQ(8, tracked_object->queue_time_total());
468 EXPECT_EQ(3, tracked_object->queue_time_sampled());
469 EXPECT_EQ(GG_UINT64_C(10151977472163283085),
470 tracked_object->exec_thread_name_hash());
471 EXPECT_EQ(177U, tracked_object->process_id());
472 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER,
473 tracked_object->process_type());
475 tracked_object = &log.uma_proto().profiler_event(0).tracked_object(1);
476 EXPECT_EQ(GG_UINT64_C(2025659946535236365),
477 tracked_object->source_file_name_hash());
478 EXPECT_EQ(GG_UINT64_C(55232426147951219),
479 tracked_object->source_function_name_hash());
480 EXPECT_EQ(1773, tracked_object->source_line_number());
481 EXPECT_EQ(GG_UINT64_C(15727396632046120663),
482 tracked_object->birth_thread_name_hash());
483 EXPECT_EQ(19, tracked_object->exec_count());
484 EXPECT_EQ(23, tracked_object->exec_time_total());
485 EXPECT_EQ(7, tracked_object->exec_time_sampled());
486 EXPECT_EQ(0, tracked_object->queue_time_total());
487 EXPECT_EQ(0, tracked_object->queue_time_sampled());
488 EXPECT_EQ(GG_UINT64_C(14275151213201158253),
489 tracked_object->exec_thread_name_hash());
490 EXPECT_EQ(177U, tracked_object->process_id());
491 EXPECT_EQ(ProfilerEventProto::TrackedObject::BROWSER,
492 tracked_object->process_type());
496 ProcessDataSnapshot process_data;
497 process_data.process_id = 1177;
498 process_data.tasks.push_back(TaskSnapshot());
499 process_data.tasks.back().birth.location.file_name = "file3";
500 process_data.tasks.back().birth.location.function_name = "function3";
501 process_data.tasks.back().birth.location.line_number = 7331;
502 process_data.tasks.back().birth.thread_name = "birth_thread3";
503 process_data.tasks.back().death_data.count = 137;
504 process_data.tasks.back().death_data.run_duration_sum = 131;
505 process_data.tasks.back().death_data.run_duration_max = 117;
506 process_data.tasks.back().death_data.run_duration_sample = 113;
507 process_data.tasks.back().death_data.queue_duration_sum = 108;
508 process_data.tasks.back().death_data.queue_duration_max = 105;
509 process_data.tasks.back().death_data.queue_duration_sample = 103;
510 process_data.tasks.back().death_thread_name = "death_thread3";
512 log.RecordProfilerData(process_data, content::PROCESS_TYPE_RENDERER);
513 ASSERT_EQ(1, log.uma_proto().profiler_event_size());
514 EXPECT_EQ(ProfilerEventProto::STARTUP_PROFILE,
515 log.uma_proto().profiler_event(0).profile_type());
516 EXPECT_EQ(ProfilerEventProto::WALL_CLOCK_TIME,
517 log.uma_proto().profiler_event(0).time_source());
518 ASSERT_EQ(3, log.uma_proto().profiler_event(0).tracked_object_size());
520 const ProfilerEventProto::TrackedObject* tracked_object =
521 &log.uma_proto().profiler_event(0).tracked_object(2);
522 EXPECT_EQ(GG_UINT64_C(2686523203278102732),
523 tracked_object->source_file_name_hash());
524 EXPECT_EQ(GG_UINT64_C(5081672290546182009),
525 tracked_object->source_function_name_hash());
526 EXPECT_EQ(7331, tracked_object->source_line_number());
527 EXPECT_EQ(GG_UINT64_C(8768512930949373716),
528 tracked_object->birth_thread_name_hash());
529 EXPECT_EQ(137, tracked_object->exec_count());
530 EXPECT_EQ(131, tracked_object->exec_time_total());
531 EXPECT_EQ(113, tracked_object->exec_time_sampled());
532 EXPECT_EQ(108, tracked_object->queue_time_total());
533 EXPECT_EQ(103, tracked_object->queue_time_sampled());
534 EXPECT_EQ(GG_UINT64_C(7246674144371406371),
535 tracked_object->exec_thread_name_hash());
536 EXPECT_EQ(1177U, tracked_object->process_id());
537 EXPECT_EQ(ProfilerEventProto::TrackedObject::RENDERER,
538 tracked_object->process_type());
542 #if defined(OS_CHROMEOS)
543 TEST_F(MetricsLogTest, MultiProfileUserCount) {
544 std::string user1("user1@example.com");
545 std::string user2("user2@example.com");
546 std::string user3("user3@example.com");
548 // |scoped_enabler| takes over the lifetime of |user_manager|.
549 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager();
550 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager);
551 user_manager->AddKioskAppUser(user1);
552 user_manager->AddKioskAppUser(user2);
553 user_manager->AddKioskAppUser(user3);
555 user_manager->LoginUser(user1);
556 user_manager->LoginUser(user3);
558 TestMetricsLog log(kClientId, kSessionId);
559 std::vector<content::WebPluginInfo> plugins;
560 GoogleUpdateMetrics google_update_metrics;
561 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
562 log.RecordEnvironment(plugins, google_update_metrics, synthetic_trials);
563 EXPECT_EQ(2u, log.system_profile().multi_profile_user_count());
566 TEST_F(MetricsLogTest, MultiProfileCountInvalidated) {
567 std::string user1("user1@example.com");
568 std::string user2("user2@example.com");
569 std::string user3("user3@example.com");
571 // |scoped_enabler| takes over the lifetime of |user_manager|.
572 chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager();
573 chromeos::ScopedUserManagerEnabler scoped_enabler(user_manager);
574 user_manager->AddKioskAppUser(user1);
575 user_manager->AddKioskAppUser(user2);
576 user_manager->AddKioskAppUser(user3);
578 user_manager->LoginUser(user1);
580 TestMetricsLog log(kClientId, kSessionId);
581 EXPECT_EQ(1u, log.system_profile().multi_profile_user_count());
583 user_manager->LoginUser(user2);
584 std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
585 log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
586 GoogleUpdateMetrics(), synthetic_trials);
587 EXPECT_EQ(0u, log.system_profile().multi_profile_user_count());
589 #endif // OS_CHROMEOS