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[PATH_MAX]; | |
18 int ret = rootdev(dev_path, sizeof(dev_path), true, true); | |
19 if (ret != 0) { | |
20 LOG(WARNING) << "error " << ret << " determining root device"; | |
21 return ""; | |
22 } | |
23 if (strcmp(dev_path, "/dev/sda") == 0) { | |
petkov
2011/02/18 04:52:00
this is probably ok as is... just a suggestion tho
| |
24 return "/sys/class/block/sda/stat"; | |
25 } else if (strcmp(dev_path, "/dev/mmcblk0") == 0) { | |
26 return "/sys/class/block/mmcblk0/stat"; | |
27 } else { | |
28 LOG(WARNING) << "unknown root device " << dev_path; | |
29 return ""; | |
30 } | |
31 } | |
14 | 32 |
15 int main(int argc, char** argv) { | 33 int main(int argc, char** argv) { |
16 google::ParseCommandLineFlags(&argc, &argv, true); | 34 google::ParseCommandLineFlags(&argc, &argv, true); |
17 MetricsLibrary metrics_lib; | 35 MetricsLibrary metrics_lib; |
18 metrics_lib.Init(); | 36 metrics_lib.Init(); |
19 MetricsDaemon daemon; | 37 MetricsDaemon daemon; |
20 daemon.Init(false, &metrics_lib, kMetricsMainDiskStatsPath); | 38 daemon.Init(false, &metrics_lib, MetricsMainDiskStatsPath()); |
21 daemon.Run(FLAGS_daemon); | 39 daemon.Run(FLAGS_daemon); |
22 } | 40 } |
OLD | NEW |