Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: metrics_daemon_test.cc

Issue 6804014: Add meminfo UMA collection. (Closed) Base URL: http://git.chromium.org/git/metrics.git@master
Patch Set: more fixes Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « metrics_daemon.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <utime.h> 5 #include <utime.h>
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include <base/file_util.h> 10 #include <base/file_util.h>
11 #include <base/stringprintf.h> 11 #include <base/stringprintf.h>
12 #include <gtest/gtest.h> 12 #include <gtest/gtest.h>
13 13
14 #include "counter_mock.h" 14 #include "counter_mock.h"
15 #include "metrics_daemon.h" 15 #include "metrics_daemon.h"
16 #include "metrics_library_mock.h" 16 #include "metrics_library_mock.h"
17 17
18 using base::Time; 18 using base::Time;
19 using base::TimeTicks; 19 using base::TimeTicks;
20 using chromeos_metrics::FrequencyCounter; 20 using chromeos_metrics::FrequencyCounter;
21 using chromeos_metrics::FrequencyCounterMock; 21 using chromeos_metrics::FrequencyCounterMock;
22 using chromeos_metrics::TaggedCounterMock; 22 using chromeos_metrics::TaggedCounterMock;
23 using chromeos_metrics::TaggedCounterReporter; 23 using chromeos_metrics::TaggedCounterReporter;
24 using chromeos_metrics::TaggedCounterReporterMock; 24 using chromeos_metrics::TaggedCounterReporterMock;
25 using std::string; 25 using std::string;
26 using std::vector; 26 using std::vector;
27 using ::testing::_; 27 using ::testing::_;
28 using ::testing::Return; 28 using ::testing::Return;
29 using ::testing::StrictMock; 29 using ::testing::StrictMock;
30 using ::testing::AtLeast;
30 31
31 static const int kSecondsPerDay = 24 * 60 * 60; 32 static const int kSecondsPerDay = 24 * 60 * 60;
32 33
33 static const char kTestDir[] = "test"; 34 static const char kTestDir[] = "test";
34 static const char kLastFile[] = "test/last"; 35 static const char kLastFile[] = "test/last";
35 static const char kCurrentFile[] = "test/current"; 36 static const char kCurrentFile[] = "test/current";
36 static const char kFakeDiskStatsPath[] = "fake-disk-stats"; 37 static const char kFakeDiskStatsPath[] = "fake-disk-stats";
37 static const char kFakeDiskStatsFormat[] = 38 static const char kFakeDiskStatsFormat[] =
38 " 1793 1788 %d 105580 " 39 " 1793 1788 %d 105580 "
39 " 196 175 %d 30290 " 40 " 196 175 %d 30290 "
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 EXPECT_CALL(metrics_lib_, 572 EXPECT_CALL(metrics_lib_,
572 SendToUMA(_, (kFakeReadSectors[1] - kFakeReadSectors[0]) / 30, 573 SendToUMA(_, (kFakeReadSectors[1] - kFakeReadSectors[0]) / 30,
573 _, _, _)); 574 _, _, _));
574 EXPECT_CALL(metrics_lib_, 575 EXPECT_CALL(metrics_lib_,
575 SendToUMA(_, (kFakeWriteSectors[1] - kFakeWriteSectors[0]) / 30, 576 SendToUMA(_, (kFakeWriteSectors[1] - kFakeWriteSectors[0]) / 30,
576 _, _, _)); 577 _, _, _));
577 daemon_.DiskStatsCallback(); 578 daemon_.DiskStatsCallback();
578 EXPECT_TRUE(ds_state != daemon_.diskstats_state_); 579 EXPECT_TRUE(ds_state != daemon_.diskstats_state_);
579 } 580 }
580 581
582 TEST_F(MetricsDaemonTest, ProcessMeminfo) {
583 const char* meminfo = "\
584 MemTotal: 2000000 kB\n\
585 MemFree: 1000000 kB\n\
586 Buffers: 10492 kB\n\
587 Cached: 213652 kB\n\
588 SwapCached: 0 kB\n\
589 Active: 133400 kB\n\
590 Inactive: 183396 kB\n\
591 Active(anon): 92984 kB\n\
592 Inactive(anon): 58860 kB\n\
593 Active(file): 40416 kB\n\
594 Inactive(file): 124536 kB\n\
595 Unevictable: 0 kB\n\
596 Mlocked: 0 kB\n\
597 SwapTotal: 0 kB\n\
598 SwapFree: 0 kB\n\
599 Dirty: 40 kB\n\
600 Writeback: 0 kB\n\
601 AnonPages: 92652 kB\n\
602 Mapped: 59716 kB\n\
603 Shmem: 59196 kB\n\
604 Slab: 16656 kB\n\
605 SReclaimable: 6132 kB\n\
606 SUnreclaim: 10524 kB\n\
607 KernelStack: 1648 kB\n\
608 PageTables: 2780 kB\n\
609 NFS_Unstable: 0 kB\n\
610 Bounce: 0 kB\n\
611 WritebackTmp: 0 kB\n\
612 CommitLimit: 970656 kB\n\
613 Committed_AS: 1260528 kB\n\
614 VmallocTotal: 122880 kB\n\
615 VmallocUsed: 12144 kB\n\
616 VmallocChunk: 103824 kB\n\
617 DirectMap4k: 9636 kB\n\
618 DirectMap2M: 1955840 kB\n\
619 ";
620 EXPECT_CALL(metrics_lib_, SendEnumToUMA(_, _, 100))
621 .Times(AtLeast(1));
622 EXPECT_CALL(metrics_lib_, SendToUMA(_, _, _, _, _))
623 .Times(AtLeast(1));
624 EXPECT_CALL(metrics_lib_, SendToUMA("NFS_Unstable", _, _, _, _))
625 .Times(0);
626 EXPECT_CALL(metrics_lib_, SendEnumToUMA("NFS_Unstable", _, _))
627 .Times(0);
628 EXPECT_TRUE(daemon_.ProcessMeminfo(meminfo));
629 }
630
631 TEST_F(MetricsDaemonTest, ProcessMeminfo2) {
632 const char* meminfo = "\
633 MemTotal: 2000000 kB\n\
634 MemFree: 1000000 kB\n\
635 ";
636 /* Not enough fields */
637 EXPECT_CALL(metrics_lib_, SendEnumToUMA(_, 50, 100))
638 .Times(1);
639 EXPECT_FALSE(daemon_.ProcessMeminfo(meminfo));
640 }
641
581 int main(int argc, char** argv) { 642 int main(int argc, char** argv) {
582 testing::InitGoogleTest(&argc, argv); 643 testing::InitGoogleTest(&argc, argv);
583 return RUN_ALL_TESTS(); 644 return RUN_ALL_TESTS();
584 } 645 }
OLDNEW
« no previous file with comments | « metrics_daemon.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698