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

Commit 6c9fbb9a authored by Bertrand SIMONNET's avatar Bertrand SIMONNET
Browse files

metricsd: Replace scoped_ptr with unique_ptr.

scoped_ptr are a chromism. We should use unique_ptr instead.

Bug: 25958769
Test: unit tests.

Change-Id: Ie23ae2ef42f66dcc76f45a9dafa66c8ceb0a2d90
parent 8a1b764d
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -16,11 +16,12 @@

#include "averaged_statistics_collector.h"

#include <memory>

#include <inttypes.h>

#include <base/files/file_util.h>
#include <base/files/scoped_temp_dir.h>
#include <base/memory/scoped_ptr.h>
#include <base/strings/stringprintf.h>
#include <gtest/gtest.h>

@@ -62,7 +63,7 @@ class AveragedStatisticsTest : public testing::Test {
  }

  // Collector used for tests.
  scoped_ptr<AveragedStatisticsCollector> collector_;
  std::unique_ptr<AveragedStatisticsCollector> collector_;

  // Temporary directory used for tests.
  base::ScopedTempDir temp_dir_;
+2 −2
Original line number Diff line number Diff line
@@ -19,10 +19,10 @@
#ifndef METRICS_TIMER_H_
#define METRICS_TIMER_H_

#include <memory>
#include <string>

#include <base/macros.h>
#include <base/memory/scoped_ptr.h>
#include <base/time/time.h>
#include <gtest/gtest_prod.h>  // for FRIEND_TEST

@@ -121,7 +121,7 @@ class Timer : public TimerInterface {
  TimerState timer_state_;

  // Wrapper for the calls to the system clock.
  scoped_ptr<ClockWrapper> clock_wrapper_;
  std::unique_ptr<ClockWrapper> clock_wrapper_;

  DISALLOW_COPY_AND_ASSIGN(Timer);
};
+5 −3
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@
#include <sysexits.h>
#include <time.h>

#include <memory>

#include <base/bind.h>
#include <base/files/file_path.h>
#include <base/files/file_util.h>
@@ -665,7 +667,7 @@ void MetricsCollector::SendKernelCrashesCumulativeCountStats() {
}

void MetricsCollector::SendAndResetDailyUseSample(
    const scoped_ptr<PersistentInteger>& use) {
    const unique_ptr<PersistentInteger>& use) {
  SendSample(use->Name(),
             use->GetAndClear(),
             1,                        // value of first bucket
@@ -674,7 +676,7 @@ void MetricsCollector::SendAndResetDailyUseSample(
}

void MetricsCollector::SendAndResetCrashIntervalSample(
    const scoped_ptr<PersistentInteger>& interval) {
    const unique_ptr<PersistentInteger>& interval) {
  SendSample(interval->Name(),
             interval->GetAndClear(),
             1,                        // value of first bucket
@@ -683,7 +685,7 @@ void MetricsCollector::SendAndResetCrashIntervalSample(
}

void MetricsCollector::SendAndResetCrashFrequencySample(
    const scoped_ptr<PersistentInteger>& frequency) {
    const unique_ptr<PersistentInteger>& frequency) {
  SendSample(frequency->Name(),
             frequency->GetAndClear(),
             1,                        // value of first bucket
+29 −29
Original line number Diff line number Diff line
@@ -20,11 +20,11 @@
#include <stdint.h>

#include <map>
#include <memory>
#include <string>
#include <vector>

#include <base/files/file_path.h>
#include <base/memory/scoped_ptr.h>
#include <base/time/time.h>
#include <brillo/daemons/dbus_daemon.h>
#include <libweaved/command.h>
@@ -38,6 +38,7 @@
#include "persistent_integer.h"

using chromeos_metrics::PersistentInteger;
using std::unique_ptr;

class MetricsCollector : public brillo::DBusDaemon {
 public:
@@ -151,18 +152,17 @@ class MetricsCollector : public brillo::DBusDaemon {

  // Sends a sample representing the number of seconds of active use
  // for a 24-hour period and reset |use|.
  void SendAndResetDailyUseSample(
      const scoped_ptr<PersistentInteger>& use);
  void SendAndResetDailyUseSample(const unique_ptr<PersistentInteger>& use);

  // Sends a sample representing a time interval between two crashes of the
  // same type and reset |interval|.
  void SendAndResetCrashIntervalSample(
      const scoped_ptr<PersistentInteger>& interval);
      const unique_ptr<PersistentInteger>& interval);

  // Sends a sample representing a frequency of crashes of some type and reset
  // |frequency|.
  void SendAndResetCrashFrequencySample(
      const scoped_ptr<PersistentInteger>& frequency);
      const unique_ptr<PersistentInteger>& frequency);

  // Initializes vm and disk stats reporting.
  void StatsReporterInit();
@@ -241,36 +241,36 @@ class MetricsCollector : public brillo::DBusDaemon {
  base::TimeDelta latest_cpu_use_microseconds_;

  // Persistent values and accumulators for crash statistics.
  scoped_ptr<PersistentInteger> daily_cycle_;
  scoped_ptr<PersistentInteger> weekly_cycle_;
  scoped_ptr<PersistentInteger> version_cycle_;
  unique_ptr<PersistentInteger> daily_cycle_;
  unique_ptr<PersistentInteger> weekly_cycle_;
  unique_ptr<PersistentInteger> version_cycle_;

  // Active use accumulated in a day.
  scoped_ptr<PersistentInteger> daily_active_use_;
  unique_ptr<PersistentInteger> daily_active_use_;
  // Active use accumulated since the latest version update.
  scoped_ptr<PersistentInteger> version_cumulative_active_use_;
  unique_ptr<PersistentInteger> version_cumulative_active_use_;

  // The CPU time accumulator.  This contains the CPU time, in milliseconds,
  // used by the system since the most recent OS version update.
  scoped_ptr<PersistentInteger> version_cumulative_cpu_use_;

  scoped_ptr<PersistentInteger> user_crash_interval_;
  scoped_ptr<PersistentInteger> kernel_crash_interval_;
  scoped_ptr<PersistentInteger> unclean_shutdown_interval_;

  scoped_ptr<PersistentInteger> any_crashes_daily_count_;
  scoped_ptr<PersistentInteger> any_crashes_weekly_count_;
  scoped_ptr<PersistentInteger> user_crashes_daily_count_;
  scoped_ptr<PersistentInteger> user_crashes_weekly_count_;
  scoped_ptr<PersistentInteger> kernel_crashes_daily_count_;
  scoped_ptr<PersistentInteger> kernel_crashes_weekly_count_;
  scoped_ptr<PersistentInteger> kernel_crashes_version_count_;
  scoped_ptr<PersistentInteger> unclean_shutdowns_daily_count_;
  scoped_ptr<PersistentInteger> unclean_shutdowns_weekly_count_;

  scoped_ptr<CpuUsageCollector> cpu_usage_collector_;
  scoped_ptr<DiskUsageCollector> disk_usage_collector_;
  scoped_ptr<AveragedStatisticsCollector> averaged_stats_collector_;
  unique_ptr<PersistentInteger> version_cumulative_cpu_use_;

  unique_ptr<PersistentInteger> user_crash_interval_;
  unique_ptr<PersistentInteger> kernel_crash_interval_;
  unique_ptr<PersistentInteger> unclean_shutdown_interval_;

  unique_ptr<PersistentInteger> any_crashes_daily_count_;
  unique_ptr<PersistentInteger> any_crashes_weekly_count_;
  unique_ptr<PersistentInteger> user_crashes_daily_count_;
  unique_ptr<PersistentInteger> user_crashes_weekly_count_;
  unique_ptr<PersistentInteger> kernel_crashes_daily_count_;
  unique_ptr<PersistentInteger> kernel_crashes_weekly_count_;
  unique_ptr<PersistentInteger> kernel_crashes_version_count_;
  unique_ptr<PersistentInteger> unclean_shutdowns_daily_count_;
  unique_ptr<PersistentInteger> unclean_shutdowns_weekly_count_;

  unique_ptr<CpuUsageCollector> cpu_usage_collector_;
  unique_ptr<DiskUsageCollector> disk_usage_collector_;
  unique_ptr<AveragedStatisticsCollector> averaged_stats_collector_;

  std::unique_ptr<weaved::Device> device_;
};
+3 −2
Original line number Diff line number Diff line
@@ -14,12 +14,13 @@
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include <memory>

#include <base/compiler_specific.h>
#include <base/files/file_enumerator.h>
#include <base/files/file_util.h>
#include <base/files/scoped_temp_dir.h>
#include <gtest/gtest.h>

#include "persistent_integer.h"

@@ -38,7 +39,7 @@ class PersistentIntegerTest : public testing::Test {
};

TEST_F(PersistentIntegerTest, BasicChecks) {
  scoped_ptr<PersistentInteger> pi(
  std::unique_ptr<PersistentInteger> pi(
      new PersistentInteger(kBackingFileName, temp_dir_.path()));

  // Test initialization.
Loading