Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6cfd64e authored by Bertrand SIMONNET's avatar Bertrand SIMONNET Committed by chrome-internal-fetch
Browse files

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: default avatarBertrand Simonnet <bsimonnet@chromium.org>
Commit-Queue: Bertrand Simonnet <bsimonnet@chromium.org>
Tested-by: default avatarBertrand Simonnet <bsimonnet@chromium.org>
Reviewed-by: default avatarLuigi Semenzato <semenzato@chromium.org>
parent 5984b211
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -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;
+3 −3
Original line number Diff line number Diff line
@@ -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_
+3 −4
Original line number Diff line number Diff line
@@ -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);
}

+1 −1
Original line number Diff line number Diff line
@@ -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";
+32 −52
Original line number Diff line number Diff line
@@ -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));
}
Loading