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

Commit 9d3a4aea authored by Bertrand SIMONNET's avatar Bertrand SIMONNET
Browse files

metricsd: Use different directories for each daemon.

Instead of using a single directory for both the internal data of
metricsd and metrics_collector and the shared files (metrics samples log
file and the metrics enabled file), we should use separate directory to
allow for a finer access control.

The new structure will be:
* /data/misc/metrics for the files accessible to all daemons reporting
  metrics, metricsd and metrics_collector.
* /data/misc/metricsd for the private files of metricsd.
* /data/misc/metrics_collector for the private files of
  metrics_collector.

Bug: 25886951
Test: Unit tests.
Test: Manual: metricsd and metrics_collector run without errors.

Change-Id: I006d19f45f5f419d2b08744126c2e2a0b899c9fa
parent a7bc1c14
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -18,7 +18,10 @@
#define METRICS_CONSTANTS_H_

namespace metrics {
static const char kMetricsDirectory[] = "/data/misc/metrics/";
static const char kSharedMetricsDirectory[] = "/data/misc/metrics/";
static const char kMetricsdDirectory[] = "/data/misc/metricsd/";
static const char kMetricsCollectorDirectory[] =
    "/data/misc/metrics_collector/";
static const char kMetricsEventsFileName[] = "uma-events";
static const char kMetricsGUIDFileName[] = "Sysinfo.GUID";
static const char kMetricsServer[] = "https://clients4.google.com/uma/v2";
+2 −2
Original line number Diff line number Diff line
@@ -140,8 +140,8 @@ static int IsGuestMode() {
}

static int DumpLogs() {
  base::FilePath events_file = base::FilePath(
      metrics::kMetricsDirectory).Append(metrics::kMetricsEventsFileName);
  base::FilePath events_file = base::FilePath(metrics::kSharedMetricsDirectory)
                                   .Append(metrics::kMetricsEventsFileName);
  printf("Metrics from %s\n\n", events_file.value().data());

  ScopedVector<metrics::MetricSample> metrics;
+35 −32
Original line number Diff line number Diff line
@@ -151,50 +151,52 @@ uint32_t MetricsCollector::GetOsVersionHash() {

void MetricsCollector::Init(bool testing, MetricsLibraryInterface* metrics_lib,
                            const string& diskstats_path,
                            const base::FilePath& metrics_directory) {
                            const base::FilePath& private_metrics_directory,
                            const base::FilePath& shared_metrics_directory) {
  CHECK(metrics_lib);
  testing_ = testing;
  metrics_directory_ = metrics_directory;
  shared_metrics_directory_ = shared_metrics_directory;
  metrics_lib_ = metrics_lib;

  daily_active_use_.reset(
      new PersistentInteger("Platform.UseTime.PerDay", metrics_directory_));
  version_cumulative_active_use_.reset(
      new PersistentInteger("Platform.CumulativeUseTime", metrics_directory_));
  version_cumulative_cpu_use_.reset(
      new PersistentInteger("Platform.CumulativeCpuTime", metrics_directory_));
  daily_active_use_.reset(new PersistentInteger("Platform.UseTime.PerDay",
                                                private_metrics_directory));
  version_cumulative_active_use_.reset(new PersistentInteger(
      "Platform.CumulativeUseTime", private_metrics_directory));
  version_cumulative_cpu_use_.reset(new PersistentInteger(
      "Platform.CumulativeCpuTime", private_metrics_directory));

  kernel_crash_interval_.reset(new PersistentInteger(
      "Platform.KernelCrashInterval", metrics_directory_));
      "Platform.KernelCrashInterval", private_metrics_directory));
  unclean_shutdown_interval_.reset(new PersistentInteger(
      "Platform.UncleanShutdownInterval", metrics_directory_));
  user_crash_interval_.reset(
      new PersistentInteger("Platform.UserCrashInterval", metrics_directory_));

  any_crashes_daily_count_.reset(
      new PersistentInteger("Platform.AnyCrashes.PerDay", metrics_directory_));
  any_crashes_weekly_count_.reset(
      new PersistentInteger("Platform.AnyCrashes.PerWeek", metrics_directory_));
  user_crashes_daily_count_.reset(
      new PersistentInteger("Platform.UserCrashes.PerDay", metrics_directory_));
      "Platform.UncleanShutdownInterval", private_metrics_directory));
  user_crash_interval_.reset(new PersistentInteger("Platform.UserCrashInterval",
                                                   private_metrics_directory));

  any_crashes_daily_count_.reset(new PersistentInteger(
      "Platform.AnyCrashes.PerDay", private_metrics_directory));
  any_crashes_weekly_count_.reset(new PersistentInteger(
      "Platform.AnyCrashes.PerWeek", private_metrics_directory));
  user_crashes_daily_count_.reset(new PersistentInteger(
      "Platform.UserCrashes.PerDay", private_metrics_directory));
  user_crashes_weekly_count_.reset(new PersistentInteger(
      "Platform.UserCrashes.PerWeek", metrics_directory_));
      "Platform.UserCrashes.PerWeek", private_metrics_directory));
  kernel_crashes_daily_count_.reset(new PersistentInteger(
      "Platform.KernelCrashes.PerDay", metrics_directory_));
      "Platform.KernelCrashes.PerDay", private_metrics_directory));
  kernel_crashes_weekly_count_.reset(new PersistentInteger(
      "Platform.KernelCrashes.PerWeek", metrics_directory_));
      "Platform.KernelCrashes.PerWeek", private_metrics_directory));
  kernel_crashes_version_count_.reset(new PersistentInteger(
      "Platform.KernelCrashesSinceUpdate", metrics_directory_));
      "Platform.KernelCrashesSinceUpdate", private_metrics_directory));
  unclean_shutdowns_daily_count_.reset(new PersistentInteger(
      "Platform.UncleanShutdown.PerDay", metrics_directory_));
      "Platform.UncleanShutdown.PerDay", private_metrics_directory));
  unclean_shutdowns_weekly_count_.reset(new PersistentInteger(
      "Platform.UncleanShutdowns.PerWeek", metrics_directory_));
      "Platform.UncleanShutdowns.PerWeek", private_metrics_directory));

  daily_cycle_.reset(new PersistentInteger("daily.cycle", metrics_directory_));
  daily_cycle_.reset(
      new PersistentInteger("daily.cycle", private_metrics_directory));
  weekly_cycle_.reset(
      new PersistentInteger("weekly.cycle", metrics_directory_));
      new PersistentInteger("weekly.cycle", private_metrics_directory));
  version_cycle_.reset(
      new PersistentInteger("version.cycle", metrics_directory_));
      new PersistentInteger("version.cycle", private_metrics_directory));

  disk_usage_collector_.reset(new DiskUsageCollector(metrics_lib_));
  averaged_stats_collector_.reset(
@@ -289,8 +291,9 @@ void MetricsCollector::OnEnableMetrics(
  if (!command)
    return;

  if (base::WriteFile(metrics_directory_.Append(metrics::kConsentFileName),
                      "", 0) != 0) {
  if (base::WriteFile(
          shared_metrics_directory_.Append(metrics::kConsentFileName), "", 0) !=
      0) {
    PLOG(ERROR) << "Could not create the consent file.";
    command->Abort("metrics_error", "Could not create the consent file",
                   nullptr);
@@ -307,8 +310,8 @@ void MetricsCollector::OnDisableMetrics(
  if (!command)
    return;

  if (!base::DeleteFile(metrics_directory_.Append(metrics::kConsentFileName),
                        false)) {
  if (!base::DeleteFile(
          shared_metrics_directory_.Append(metrics::kConsentFileName), false)) {
    PLOG(ERROR) << "Could not delete the consent file.";
    command->Abort("metrics_error", "Could not delete the consent file",
                   nullptr);
+4 −3
Original line number Diff line number Diff line
@@ -48,7 +48,8 @@ class MetricsCollector : public brillo::DBusDaemon {
  void Init(bool testing,
            MetricsLibraryInterface* metrics_lib,
            const std::string& diskstats_path,
            const base::FilePath& metrics_directory);
            const base::FilePath& private_metrics_directory,
            const base::FilePath& shared_metrics_directory);

  // Initializes DBus and MessageLoop variables before running the MessageLoop.
  int OnInit() override;
@@ -225,8 +226,8 @@ class MetricsCollector : public brillo::DBusDaemon {
  // Test mode.
  bool testing_;

  // Root of the configuration files to use.
  base::FilePath metrics_directory_;
  // Publicly readable metrics directory.
  base::FilePath shared_metrics_directory_;

  // The metrics library handle.
  MetricsLibraryInterface* metrics_lib_;
+9 −4
Original line number Diff line number Diff line
@@ -51,9 +51,13 @@ const std::string MetricsMainDiskStatsPath() {
int main(int argc, char** argv) {
  DEFINE_bool(foreground, false, "Don't daemonize");

  DEFINE_string(metrics_directory,
                metrics::kMetricsDirectory,
                "Root of the configuration files (testing only)");
  DEFINE_string(private_directory, metrics::kMetricsCollectorDirectory,
                "Path to the private directory used by metrics_collector "
                "(testing only)");
  DEFINE_string(shared_directory, metrics::kSharedMetricsDirectory,
                "Path to the shared metrics directory, used by "
                "metrics_collector, metricsd and all metrics clients "
                "(testing only)");

  DEFINE_bool(logtostderr, false, "Log to standard error");
  DEFINE_bool(logtosyslog, false, "Log to syslog");
@@ -86,7 +90,8 @@ int main(int argc, char** argv) {
  daemon.Init(false,
              &metrics_lib,
              MetricsMainDiskStatsPath(),
              base::FilePath(FLAGS_metrics_directory));
              base::FilePath(FLAGS_private_directory),
              base::FilePath(FLAGS_shared_directory));

  daemon.Run();
}
Loading