Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 5 |
| 6 #include <base/logging.h> | |
| 6 #include <gflags/gflags.h> | 7 #include <gflags/gflags.h> |
| 8 #include <rootdev/rootdev.h> | |
| 7 | 9 |
| 8 #include "metrics_daemon.h" | 10 #include "metrics_daemon.h" |
| 9 | 11 |
| 10 DEFINE_bool(daemon, true, "run as daemon (use -nodaemon for debugging)"); | 12 DEFINE_bool(daemon, true, "run as daemon (use -nodaemon for debugging)"); |
| 11 | 13 |
| 12 // Path to disk stats. This may be system dependent. | 14 // Return the path to the disk stats in the sysfs. |
| 13 const char kMetricsMainDiskStatsPath[] = "/sys/class/block/sda/stat"; | 15 static |
| 16 const std::string MetricsMainDiskStatsPath() { | |
| 17 char dev_path_cstr[PATH_MAX]; | |
| 18 int ret; | |
|
petkov
2011/02/26 00:26:46
per style, variables should be declared close to t
| |
| 19 std::string stat_path = "/sys/class/block/"; | |
| 20 std::string dev_prefix = "/dev/"; | |
| 21 std::string dev_path; | |
| 22 std::string dev_name; | |
| 23 | |
| 24 ret = rootdev(dev_path_cstr, sizeof(dev_path_cstr), true, true); | |
|
petkov
2011/02/26 00:26:46
int ret = ...
| |
| 25 if (ret != 0) { | |
| 26 LOG(WARNING) << "error " << ret << " determining root device"; | |
| 27 return ""; | |
| 28 } | |
| 29 dev_path = dev_path_cstr; | |
| 30 // Check that rootdev begins with "/dev/". | |
| 31 if (dev_path.compare(0, dev_prefix.length(), dev_prefix) != 0) { | |
|
petkov
2011/02/26 00:26:46
if (base::StartsWithASCII(dev_path, dev_prefix, fa
| |
| 32 LOG(WARNING) << "unexpected root device " << dev_path; | |
| 33 return ""; | |
| 34 } | |
| 35 // Get the device name, e.g. "sda" from "/dev/sda". | |
| 36 dev_name = dev_path.substr(dev_prefix.length()); | |
| 37 // Create the full path of the stat file, e.g. "/sys/class/block/sda/stat" | |
| 38 return stat_path.append(dev_name.append("/stat")); | |
|
petkov
2011/02/26 00:26:46
This is simpler and doesn't need a comment or stat
| |
| 39 } | |
| 14 | 40 |
| 15 int main(int argc, char** argv) { | 41 int main(int argc, char** argv) { |
| 16 google::ParseCommandLineFlags(&argc, &argv, true); | 42 google::ParseCommandLineFlags(&argc, &argv, true); |
| 17 MetricsLibrary metrics_lib; | 43 MetricsLibrary metrics_lib; |
| 18 metrics_lib.Init(); | 44 metrics_lib.Init(); |
| 19 MetricsDaemon daemon; | 45 MetricsDaemon daemon; |
| 20 daemon.Init(false, &metrics_lib, kMetricsMainDiskStatsPath); | 46 daemon.Init(false, &metrics_lib, MetricsMainDiskStatsPath()); |
| 21 daemon.Run(FLAGS_daemon); | 47 daemon.Run(FLAGS_daemon); |
| 22 } | 48 } |
| OLD | NEW |