metrics: Use integer types from stdint.h

This CL replaces the deprecated int* and uint* types from
'base/basictypes.h' with the int*_t and uint*_t types from 'stdint.h'.

BUG=chromium:401356
TEST=`FEATURES=test emerge-$BOARD metrics`

Change-Id: Ie5a69edba2c8a9d5185bbc548ed70a5b121c3e3b
Reviewed-on: https://chromium-review.googlesource.com/211381
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Tested-by: Ben Chan <benchan@chromium.org>
Commit-Queue: Ben Chan <benchan@chromium.org>
This commit is contained in:
Ben Chan 2014-08-07 00:54:59 -07:00 committed by chrome-internal-fetch
parent 4e59634509
commit f05ab40ab9
9 changed files with 66 additions and 60 deletions

View File

@ -175,7 +175,7 @@ void MetricsDaemon::Run(bool run_as_daemon) {
}
// On OS version change, clear version stats (which are reported daily).
int32 version = GetOsVersionHash();
int32_t version = GetOsVersionHash();
if (version_cycle_->Get() != version) {
version_cycle_->Set(version);
kernel_crashes_version_count_->Set(0);
@ -190,8 +190,8 @@ void MetricsDaemon::RunUploaderTest() {
upload_service_->UploadEvent();
}
uint32 MetricsDaemon::GetOsVersionHash() {
static uint32 cached_version_hash = 0;
uint32_t MetricsDaemon::GetOsVersionHash() {
static uint32_t cached_version_hash = 0;
static bool version_hash_is_cached = false;
if (version_hash_is_cached)
return cached_version_hash;
@ -372,7 +372,7 @@ TimeDelta MetricsDaemon::GetIncrementalCpuUse() {
std::vector<std::string> proc_stat_totals;
base::SplitStringAlongWhitespace(proc_stat_lines[0], &proc_stat_totals);
uint64 user_ticks, user_nice_ticks, system_ticks;
uint64_t user_ticks, user_nice_ticks, system_ticks;
if (proc_stat_totals.size() != kMetricsProcStatFirstLineItemsCount ||
proc_stat_totals[0] != "cpu" ||
!base::StringToUint64(proc_stat_totals[1], &user_ticks) ||
@ -382,7 +382,7 @@ TimeDelta MetricsDaemon::GetIncrementalCpuUse() {
return TimeDelta(base::TimeDelta::FromSeconds(0));
}
uint64 total_cpu_use_ticks = user_ticks + user_nice_ticks + system_ticks;
uint64_t total_cpu_use_ticks = user_ticks + user_nice_ticks + system_ticks;
// Sanity check.
if (total_cpu_use_ticks < latest_cpu_use_ticks_) {
@ -391,7 +391,7 @@ TimeDelta MetricsDaemon::GetIncrementalCpuUse() {
return TimeDelta();
}
uint64 diff = total_cpu_use_ticks - latest_cpu_use_ticks_;
uint64_t diff = total_cpu_use_ticks - latest_cpu_use_ticks_;
latest_cpu_use_ticks_ = total_cpu_use_ticks;
// Use microseconds to avoid significant truncations.
return base::TimeDelta::FromMicroseconds(
@ -470,8 +470,8 @@ void MetricsDaemon::ScheduleStatsCallback(int wait) {
g_timeout_add_seconds(wait, StatsCallbackStatic, this);
}
bool MetricsDaemon::DiskStatsReadStats(uint64* read_sectors,
uint64* write_sectors) {
bool MetricsDaemon::DiskStatsReadStats(uint64_t* read_sectors,
uint64_t* write_sectors) {
int nchars;
int nitems;
bool success = false;
@ -632,7 +632,7 @@ gboolean MetricsDaemon::StatsCallbackStatic(void* handle) {
// Collects disk and vm stats alternating over a short and a long interval.
void MetricsDaemon::StatsCallback() {
uint64 read_sectors_now, write_sectors_now;
uint64_t read_sectors_now, write_sectors_now;
struct VmstatRecord vmstats_now;
double time_now = GetActiveTime();
double delta_time = time_now - stats_initial_time_;
@ -765,7 +765,7 @@ bool MetricsDaemon::MeminfoCallback() {
// static
bool MetricsDaemon::ReadFileToUint64(const base::FilePath& path,
uint64* value) {
uint64_t* value) {
std::string content;
if (!base::ReadFileToString(path, &content)) {
PLOG(WARNING) << "cannot read " << path.MaybeAsASCII();
@ -782,7 +782,7 @@ bool MetricsDaemon::ReadFileToUint64(const base::FilePath& path,
bool MetricsDaemon::ReportZram(const base::FilePath& zram_dir) {
// Data sizes are in bytes. |zero_pages| is in number of pages.
uint64 compr_data_size, orig_data_size, zero_pages;
uint64_t compr_data_size, orig_data_size, zero_pages;
const size_t page_size = 4096;
if (!ReadFileToUint64(zram_dir.Append(kComprDataSizeName),
@ -1014,7 +1014,7 @@ void MetricsDaemon::SendSample(const string& name, int sample,
void MetricsDaemon::SendKernelCrashesCumulativeCountStats() {
// Report the number of crashes for this OS version, but don't clear the
// counter. It is cleared elsewhere on version change.
int64 crashes_count = kernel_crashes_version_count_->Get();
int64_t crashes_count = kernel_crashes_version_count_->Get();
SendSample(kernel_crashes_version_count_->Name(),
crashes_count,
1, // value of first bucket
@ -1022,7 +1022,7 @@ void MetricsDaemon::SendKernelCrashesCumulativeCountStats() {
100); // number of buckets
int64 cpu_use_ms = version_cumulative_cpu_use_->Get();
int64_t cpu_use_ms = version_cumulative_cpu_use_->Get();
SendSample(version_cumulative_cpu_use_->Name(),
cpu_use_ms / 1000, // stat is in seconds
1, // device may be used very little...
@ -1040,7 +1040,7 @@ void MetricsDaemon::SendKernelCrashesCumulativeCountStats() {
100);
}
int64 active_use_seconds = version_cumulative_active_use_->Get();
int64_t active_use_seconds = version_cumulative_active_use_->Get();
if (active_use_seconds > 0) {
SendSample(version_cumulative_active_use_->Name(),
active_use_seconds / 1000, // stat is in seconds

View File

@ -5,6 +5,8 @@
#ifndef METRICS_METRICS_DAEMON_H_
#define METRICS_METRICS_DAEMON_H_
#include <stdint.h>
#include <dbus/dbus.h>
#include <glib.h>
#include <map>
@ -213,7 +215,7 @@ class MetricsDaemon {
void ScheduleStatsCallback(int wait);
// Reads cumulative disk statistics from sysfs. Returns true for success.
bool DiskStatsReadStats(uint64* read_sectors, uint64* write_sectors);
bool DiskStatsReadStats(uint64_t* read_sectors, uint64_t* write_sectors);
// Reads cumulative vm statistics from procfs. Returns true for success.
bool VmStatsReadStats(struct VmstatRecord* stats);
@ -275,7 +277,7 @@ class MetricsDaemon {
// Reads the current OS version from /etc/lsb-release and hashes it
// to a unsigned 32-bit int.
uint32 GetOsVersionHash();
uint32_t GetOsVersionHash();
// Updates stats, additionally sending them to UMA if enough time has elapsed
// since the last report.
@ -287,8 +289,8 @@ class MetricsDaemon {
// Reports zram statistics.
bool ReportZram(const base::FilePath& zram_dir);
// Reads a string from a file and converts it to uint64.
static bool ReadFileToUint64(const base::FilePath& path, uint64* value);
// Reads a string from a file and converts it to uint64_t.
static bool ReadFileToUint64(const base::FilePath& path, uint64_t* value);
// VARIABLES
@ -323,8 +325,8 @@ class MetricsDaemon {
unsigned int memuse_interval_index_;
// Contain the most recent disk and vm cumulative stats.
uint64 read_sectors_;
uint64 write_sectors_;
uint64_t read_sectors_;
uint64_t write_sectors_;
struct VmstatRecord vmstats_;
StatsState stats_state_;
@ -332,10 +334,10 @@ class MetricsDaemon {
// The system "HZ", or frequency of ticks. Some system data uses ticks as a
// unit, and this is used to convert to standard time units.
uint32 ticks_per_second_;
uint32_t ticks_per_second_;
// Used internally by GetIncrementalCpuUse() to return the CPU utilization
// between calls.
uint64 latest_cpu_use_ticks_;
uint64_t latest_cpu_use_ticks_;
// Persistent values and accumulators for crash statistics.
scoped_ptr<PersistentInteger> daily_cycle_;

View File

@ -39,8 +39,8 @@ static const char kFakeDiskStatsFormat[] =
" 1793 1788 %" PRIu64 "d 105580 "
" 196 175 %" PRIu64 "d 30290 "
" 0 44060 135850\n";
static const uint64 kFakeReadSectors[] = {80000, 100000};
static const uint64 kFakeWriteSectors[] = {3000, 4000};
static const uint64_t kFakeReadSectors[] = {80000, 100000};
static const uint64_t kFakeWriteSectors[] = {3000, 4000};
static const char kFakeVmStatsName[] = "fake-vm-stats";
static const char kFakeScalingMaxFreqPath[] = "fake-scaling-max-freq";
@ -173,7 +173,7 @@ class MetricsDaemonTest : public testing::Test {
// Creates or overwrites the file in |path| so that it contains the printable
// representation of |value|.
void CreateUint64ValueFile(const base::FilePath& path, uint64 value) {
void CreateUint64ValueFile(const base::FilePath& path, uint64_t value) {
base::DeleteFile(path, false);
std::string value_string = base::Uint64ToString(value);
ASSERT_EQ(value_string.length(),
@ -258,7 +258,7 @@ TEST_F(MetricsDaemonTest, SendSample) {
}
TEST_F(MetricsDaemonTest, ReportDiskStats) {
uint64 read_sectors_now, write_sectors_now;
uint64_t read_sectors_now, write_sectors_now;
CreateFakeDiskStatsFile(kFakeDiskStats1.c_str());
daemon_.DiskStatsReadStats(&read_sectors_now, &write_sectors_now);
@ -361,12 +361,12 @@ TEST_F(MetricsDaemonTest, SendZramMetrics) {
EXPECT_TRUE(daemon_.testing_);
// |compr_data_size| is the size in bytes of compressed data.
const uint64 compr_data_size = 50 * 1000 * 1000;
const uint64_t compr_data_size = 50 * 1000 * 1000;
// The constant '3' is a realistic but random choice.
// |orig_data_size| does not include zero pages.
const uint64 orig_data_size = compr_data_size * 3;
const uint64 page_size = 4096;
const uint64 zero_pages = 10 * 1000 * 1000 / page_size;
const uint64_t orig_data_size = compr_data_size * 3;
const uint64_t page_size = 4096;
const uint64_t zero_pages = 10 * 1000 * 1000 / page_size;
CreateUint64ValueFile(base::FilePath(MetricsDaemon::kComprDataSizeName),
compr_data_size);
@ -375,11 +375,11 @@ TEST_F(MetricsDaemonTest, SendZramMetrics) {
CreateUint64ValueFile(base::FilePath(MetricsDaemon::kZeroPagesName),
zero_pages);
const uint64 real_orig_size = orig_data_size + zero_pages * page_size;
const uint64 zero_ratio_percent =
const uint64_t real_orig_size = orig_data_size + zero_pages * page_size;
const uint64_t zero_ratio_percent =
zero_pages * page_size * 100 / real_orig_size;
// Ratio samples are in percents.
const uint64 actual_ratio_sample = real_orig_size * 100 / compr_data_size;
const uint64_t actual_ratio_sample = real_orig_size * 100 / compr_data_size;
EXPECT_CALL(metrics_lib_, SendToUMA(_, compr_data_size >> 20, _, _, _));
EXPECT_CALL(metrics_lib_,

View File

@ -37,25 +37,25 @@ PersistentInteger::PersistentInteger(const std::string& name) :
PersistentInteger::~PersistentInteger() {}
void PersistentInteger::Set(int64 value) {
void PersistentInteger::Set(int64_t value) {
value_ = value;
Write();
}
int64 PersistentInteger::Get() {
int64_t PersistentInteger::Get() {
// If not synced, then read. If the read fails, it's a good idea to write.
if (!synced_ && !Read())
Write();
return value_;
}
int64 PersistentInteger::GetAndClear() {
int64 v = Get();
int64_t PersistentInteger::GetAndClear() {
int64_t v = Get();
Set(0);
return v;
}
void PersistentInteger::Add(int64 x) {
void PersistentInteger::Add(int64_t x) {
Set(Get() + x);
}
@ -79,8 +79,8 @@ bool PersistentInteger::Read() {
PLOG(WARNING) << "cannot open " << backing_file_name_ << " for reading";
return false;
}
int32 version;
int64 value;
int32_t version;
int64_t value;
bool read_succeeded = false;
if (HANDLE_EINTR(read(fd, &version, sizeof(version))) == sizeof(version) &&
version == version_ &&

View File

@ -5,7 +5,8 @@
#ifndef METRICS_PERSISTENT_INTEGER_H_
#define METRICS_PERSISTENT_INTEGER_H_
#include <base/basictypes.h>
#include <stdint.h>
#include <string>
namespace chromeos_metrics {
@ -22,20 +23,20 @@ class PersistentInteger {
virtual ~PersistentInteger();
// Sets the value. This writes through to the backing file.
void Set(int64 v);
void Set(int64_t v);
// Gets the value. May sync from backing file first.
int64 Get();
int64_t Get();
// Returns the name of the object.
std::string Name() { return name_; }
// Convenience function for Get() followed by Set(0).
int64 GetAndClear();
int64_t GetAndClear();
// Convenience function for v = Get, Set(v + x).
// Virtual only because of mock.
virtual void Add(int64 x);
virtual void Add(int64_t x);
// After calling with |testing| = true, changes some behavior for the purpose
// of testing. For instance: instances created while testing use the current
@ -53,8 +54,8 @@ class PersistentInteger {
// a valid backing file as a side effect.
bool Read();
int64 value_;
int32 version_;
int64_t value_;
int32_t version_;
std::string name_;
std::string backing_file_name_;
bool synced_;

View File

@ -17,7 +17,7 @@ class PersistentIntegerMock : public PersistentInteger {
public:
explicit PersistentIntegerMock(const std::string& name)
: PersistentInteger(name) {}
MOCK_METHOD1(Add, void(int64 count));
MOCK_METHOD1(Add, void(int64_t count));
};
} // namespace chromeos_metrics

View File

@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdint.h>
#include <base/memory/scoped_ptr.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@ -16,17 +18,17 @@ using ::testing::Return;
namespace chromeos_metrics {
namespace {
const int64 kStime1MSec = 1400;
const int64 kEtime1MSec = 3000;
const int64 kDelta1MSec = 1600;
const int64_t kStime1MSec = 1400;
const int64_t kEtime1MSec = 3000;
const int64_t kDelta1MSec = 1600;
const int64 kStime2MSec = 4200;
const int64 kEtime2MSec = 5000;
const int64 kDelta2MSec = 800;
const int64_t kStime2MSec = 4200;
const int64_t kEtime2MSec = 5000;
const int64_t kDelta2MSec = 800;
const int64 kStime3MSec = 6600;
const int64 kEtime3MSec = 6800;
const int64 kDelta3MSec = 200;
const int64_t kStime3MSec = 6600;
const int64_t kEtime3MSec = 6800;
const int64_t kDelta3MSec = 200;
} // namespace
class TimerTest : public testing::Test {

View File

@ -57,7 +57,7 @@ bool SystemProfileCache::Initialize() {
// TODO(bsimonnet): Change this to map to the number of time system-services
// is started.
session_id_->Add(1);
profile_.session_id = static_cast<int32>(session_id_->Get());
profile_.session_id = static_cast<int32_t>(session_id_->Get());
initialized_ = true;
return initialized_;

View File

@ -5,9 +5,10 @@
#ifndef METRICS_UPLOADER_SYSTEM_PROFILE_CACHE_H_
#define METRICS_UPLOADER_SYSTEM_PROFILE_CACHE_H_
#include <stdint.h>
#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
@ -26,7 +27,7 @@ struct SystemProfile {
std::string app_version;
std::string hardware_class;
std::string client_id;
int32 session_id;
int32_t session_id;
};
// Retrieves general system informations needed by the protobuf for context and