metrics: fix lint warnings

This CL solve the cros lint warnings.
This is mostly due to:
* header guards
* include path
* few google style guide warnings

BUG=chromium:389229
TEST=FEATURES=test emerge-amd64-generic metrics

Change-Id: Ibbfcd2c88926bcc0c1ce9275b4ad0fb0748cd4de
Reviewed-on: https://chromium-review.googlesource.com/207248
Reviewed-by: Bertrand Simonnet <bsimonnet@chromium.org>
Commit-Queue: Bertrand Simonnet <bsimonnet@chromium.org>
Tested-by: Bertrand Simonnet <bsimonnet@chromium.org>
Reviewed-by: Luigi Semenzato <semenzato@chromium.org>
This commit is contained in:
Bertrand SIMONNET 2014-07-09 16:35:23 -07:00 committed by chrome-internal-fetch
parent 5984b2116c
commit e6cfd64e6a
13 changed files with 61 additions and 80 deletions

View file

@ -6,8 +6,10 @@
// C wrapper to libmetrics
//
#include "c_metrics_library.h"
#include "metrics_library.h"
#include <string>
#include "metrics/c_metrics_library.h"
#include "metrics/metrics_library.h"
extern "C" CMetricsLibrary CMetricsLibraryNew(void) {
MetricsLibrary* lib = new MetricsLibrary;

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef C_METRICS_LIBRARY_H_
#define C_METRICS_LIBRARY_H_
#ifndef METRICS_C_METRICS_LIBRARY_H_
#define METRICS_C_METRICS_LIBRARY_H_
#if defined(__cplusplus)
extern "C" {
@ -46,4 +46,4 @@ int CMetricsLibraryAreMetricsEnabled(CMetricsLibrary handle);
#if defined(__cplusplus)
}
#endif
#endif // C_METRICS_LIBRARY_H_
#endif // METRICS_C_METRICS_LIBRARY_H_

View file

@ -5,7 +5,7 @@
#include <cstdio>
#include <cstdlib>
#include "metrics_library.h"
#include "metrics/metrics_library.h"
enum Mode {
kModeSendSample,
@ -36,8 +36,7 @@ void ShowUsage() {
" -s: send a sparse histogram sample\n"
" -t: convert sample from double seconds to int milliseconds\n"
" -u: send a user action to Chrome\n"
" -v: send a Platform.CrOSEvent enum histogram sample\n"
);
" -v: send a Platform.CrOSEvent enum histogram sample\n");
exit(1);
}
@ -193,7 +192,7 @@ int main(int argc, char** argv) {
ShowUsage();
}
switch(mode) {
switch (mode) {
case kModeSendSample:
case kModeSendEnumSample:
case kModeSendSparseSample:

View file

@ -10,7 +10,7 @@
#include <gflags/gflags.h>
#include <rootdev/rootdev.h>
#include "metrics_daemon.h"
#include "metrics/metrics_daemon.h"
const char kScalingMaxFreqPath[] =
"/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq";

View file

@ -17,9 +17,9 @@
#include <chromeos/dbus/service_constants.h>
#include <gtest/gtest.h>
#include "metrics_daemon.h"
#include "metrics_library_mock.h"
#include "persistent_integer_mock.h"
#include "metrics/metrics_daemon.h"
#include "metrics/metrics_library_mock.h"
#include "metrics/persistent_integer_mock.h"
using base::FilePath;
using base::StringPrintf;
@ -39,7 +39,6 @@ static const char kFakeDiskStatsFormat[] =
" 1793 1788 %" PRIu64 "d 105580 "
" 196 175 %" PRIu64 "d 30290 "
" 0 44060 135850\n";
static string kFakeDiskStats[2];
static const uint64 kFakeReadSectors[] = {80000, 100000};
static const uint64 kFakeWriteSectors[] = {3000, 4000};
@ -49,14 +48,17 @@ static const char kFakeCpuinfoMaxFreqPath[] = "fake-cpuinfo-max-freq";
class MetricsDaemonTest : public testing::Test {
protected:
std::string kFakeDiskStats0;
std::string kFakeDiskStats1;
virtual void SetUp() {
kFakeDiskStats[0] = base::StringPrintf(kFakeDiskStatsFormat,
kFakeDiskStats0 = base::StringPrintf(kFakeDiskStatsFormat,
kFakeReadSectors[0],
kFakeWriteSectors[0]);
kFakeDiskStats[1] = base::StringPrintf(kFakeDiskStatsFormat,
kFakeDiskStats1 = base::StringPrintf(kFakeDiskStatsFormat,
kFakeReadSectors[1],
kFakeWriteSectors[1]);
CreateFakeDiskStatsFile(kFakeDiskStats[0].c_str());
CreateFakeDiskStatsFile(kFakeDiskStats0.c_str());
CreateUint64ValueFile(base::FilePath(kFakeCpuinfoMaxFreqPath), 10000000);
CreateUint64ValueFile(base::FilePath(kFakeScalingMaxFreqPath), 10000000);
@ -85,7 +87,6 @@ class MetricsDaemonTest : public testing::Test {
unclean_shutdown_interval_mock_ =
new StrictMock<PersistentIntegerMock>("4.mock");
daemon_.unclean_shutdown_interval_.reset(unclean_shutdown_interval_mock_);
}
virtual void TearDown() {
@ -259,7 +260,7 @@ TEST_F(MetricsDaemonTest, SendSample) {
TEST_F(MetricsDaemonTest, ReportDiskStats) {
uint64 read_sectors_now, write_sectors_now;
CreateFakeDiskStatsFile(kFakeDiskStats[1].c_str());
CreateFakeDiskStatsFile(kFakeDiskStats1.c_str());
daemon_.DiskStatsReadStats(&read_sectors_now, &write_sectors_now);
EXPECT_EQ(read_sectors_now, kFakeReadSectors[1]);
EXPECT_EQ(write_sectors_now, kFakeWriteSectors[1]);
@ -277,46 +278,28 @@ TEST_F(MetricsDaemonTest, ReportDiskStats) {
}
TEST_F(MetricsDaemonTest, ProcessMeminfo) {
string meminfo = "\
MemTotal: 2000000 kB\n\
MemFree: 500000 kB\n\
Buffers: 1000000 kB\n\
Cached: 213652 kB\n\
SwapCached: 0 kB\n\
Active: 133400 kB\n\
Inactive: 183396 kB\n\
Active(anon): 92984 kB\n\
Inactive(anon): 58860 kB\n\
Active(file): 40416 kB\n\
Inactive(file): 124536 kB\n\
Unevictable: 0 kB\n\
Mlocked: 0 kB\n\
SwapTotal: 0 kB\n\
SwapFree: 0 kB\n\
Dirty: 40 kB\n\
Writeback: 0 kB\n\
AnonPages: 92652 kB\n\
Mapped: 59716 kB\n\
Shmem: 59196 kB\n\
Slab: 16656 kB\n\
SReclaimable: 6132 kB\n\
SUnreclaim: 10524 kB\n\
KernelStack: 1648 kB\n\
PageTables: 2780 kB\n\
NFS_Unstable: 0 kB\n\
Bounce: 0 kB\n\
WritebackTmp: 0 kB\n\
CommitLimit: 970656 kB\n\
Committed_AS: 1260528 kB\n\
VmallocTotal: 122880 kB\n\
VmallocUsed: 12144 kB\n\
VmallocChunk: 103824 kB\n\
DirectMap4k: 9636 kB\n\
DirectMap2M: 1955840 kB\n\
";
string meminfo =
"MemTotal: 2000000 kB\nMemFree: 500000 kB\n"
"Buffers: 1000000 kB\nCached: 213652 kB\n"
"SwapCached: 0 kB\nActive: 133400 kB\n"
"Inactive: 183396 kB\nActive(anon): 92984 kB\n"
"Inactive(anon): 58860 kB\nActive(file): 40416 kB\n"
"Inactive(file): 124536 kB\nUnevictable: 0 kB\n"
"Mlocked: 0 kB\nSwapTotal: 0 kB\n"
"SwapFree: 0 kB\nDirty: 40 kB\n"
"Writeback: 0 kB\nAnonPages: 92652 kB\n"
"Mapped: 59716 kB\nShmem: 59196 kB\n"
"Slab: 16656 kB\nSReclaimable: 6132 kB\n"
"SUnreclaim: 10524 kB\nKernelStack: 1648 kB\n"
"PageTables: 2780 kB\nNFS_Unstable: 0 kB\n"
"Bounce: 0 kB\nWritebackTmp: 0 kB\n"
"CommitLimit: 970656 kB\nCommitted_AS: 1260528 kB\n"
"VmallocTotal: 122880 kB\nVmallocUsed: 12144 kB\n"
"VmallocChunk: 103824 kB\nDirectMap4k: 9636 kB\n"
"DirectMap2M: 1955840 kB\n";
// All enum calls must report percents.
EXPECT_CALL(metrics_lib_, SendEnumToUMA(_, _, 100))
.Times(AtLeast(1));
EXPECT_CALL(metrics_lib_, SendEnumToUMA(_, _, 100)).Times(AtLeast(1));
// Check that MemFree is correctly computed at 25%.
EXPECT_CALL(metrics_lib_, SendEnumToUMA("Platform.MeminfoMemFree", 25, 100))
.Times(AtLeast(1));
@ -332,10 +315,7 @@ DirectMap2M: 1955840 kB\n\
}
TEST_F(MetricsDaemonTest, ProcessMeminfo2) {
string meminfo = "\
MemTotal: 2000000 kB\n\
MemFree: 1000000 kB\n\
";
string meminfo = "MemTotal: 2000000 kB\nMemFree: 1000000 kB\n";
// Not enough fields.
EXPECT_FALSE(daemon_.ProcessMeminfo(meminfo));
}

View file

@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef METRICS_LIBRARY_MOCK_H_
#define METRICS_LIBRARY_MOCK_H_
#ifndef METRICS_METRICS_LIBRARY_MOCK_H_
#define METRICS_METRICS_LIBRARY_MOCK_H_
#include <string>
#include "metrics_library.h"
#include "metrics/metrics_library.h"
#include <gmock/gmock.h>
@ -22,4 +22,4 @@ class MetricsLibraryMock : public MetricsLibraryInterface {
MOCK_METHOD1(SendUserActionToUMA, bool(const std::string& action));
};
#endif // METRICS_LIBRARY_MOCK_H_
#endif // METRICS_METRICS_LIBRARY_MOCK_H_

View file

@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "persistent_integer.h"
#include "metrics/persistent_integer.h"
#include <fcntl.h>
#include <base/logging.h>
#include <base/posix/eintr_wrapper.h>
#include "metrics_library.h"
#include "metrics/metrics_library.h"
namespace {

View file

@ -16,7 +16,7 @@ namespace chromeos_metrics {
class PersistentInteger {
public:
PersistentInteger(const std::string& name);
explicit PersistentInteger(const std::string& name);
// Virtual only because of mock.
virtual ~PersistentInteger();
@ -61,6 +61,6 @@ class PersistentInteger {
static bool testing_;
};
}
} // namespace chromeos_metrics
#endif // METRICS_PERSISTENT_INTEGER_H_

View file

@ -9,13 +9,14 @@
#include <gmock/gmock.h>
#include "persistent_integer.h"
#include "metrics/persistent_integer.h"
namespace chromeos_metrics {
class PersistentIntegerMock : public PersistentInteger {
public:
PersistentIntegerMock(const std::string& name) : PersistentInteger(name) {}
explicit PersistentIntegerMock(const std::string& name)
: PersistentInteger(name) {}
MOCK_METHOD1(Add, void(int64 count));
};

View file

@ -16,7 +16,6 @@ const char kBackingFilePattern[] = "*.pibakf";
using chromeos_metrics::PersistentInteger;
class PersistentIntegerTest : public testing::Test {
virtual void SetUp() OVERRIDE {
// Set testing mode.
chromeos_metrics::PersistentInteger::SetTestingMode(true);

View file

@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "timer.h"
#include "metrics/timer.h"
#include <string>
#include <base/memory/scoped_ptr.h>
#include "metrics_library.h"
#include "metrics/metrics_library.h"
namespace chromeos_metrics {

View file

@ -11,7 +11,7 @@
#include <base/basictypes.h>
#include <gmock/gmock.h>
#include "timer.h"
#include "metrics/timer.h"
namespace chromeos_metrics {
@ -26,7 +26,7 @@ class TimerMock : public Timer {
class TimerReporterMock : public TimerReporter {
public:
TimerReporterMock() : TimerReporter("",0,0,0) {}
TimerReporterMock() : TimerReporter("", 0, 0, 0) {}
MOCK_METHOD0(Start, bool());
MOCK_METHOD0(Stop, bool());
MOCK_METHOD0(Reset, bool());

View file

@ -6,9 +6,9 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "metrics_library_mock.h"
#include "timer.h"
#include "timer_mock.h"
#include "metrics/metrics_library_mock.h"
#include "metrics/timer.h"
#include "metrics/timer_mock.h"
using ::testing::_;
using ::testing::Return;