Merge changes from topic "remove-log_to"
* changes: base: remove LOG_TO(), PLOG_TO() and LOG_STREAM_TO() macros storaged: replace LOG_TO() macros with LOG()
This commit is contained in:
commit
acd17330df
7 changed files with 87 additions and 106 deletions
|
|
@ -222,20 +222,16 @@ struct LogAbortAfterFullExpr {
|
||||||
// 1) This will not check whether the severity is high enough. One should use WOULD_LOG to filter
|
// 1) This will not check whether the severity is high enough. One should use WOULD_LOG to filter
|
||||||
// usage manually.
|
// usage manually.
|
||||||
// 2) This does not save and restore errno.
|
// 2) This does not save and restore errno.
|
||||||
#define LOG_STREAM(severity) LOG_STREAM_TO(DEFAULT, severity)
|
#define LOG_STREAM(severity) \
|
||||||
|
::android::base::LogMessage(__FILE__, __LINE__, SEVERITY_LAMBDA(severity), _LOG_TAG_INTERNAL, \
|
||||||
// Get an ostream that can be used for logging at the given severity and to the
|
-1) \
|
||||||
// given destination. The same notes as for LOG_STREAM apply.
|
|
||||||
#define LOG_STREAM_TO(dest, severity) \
|
|
||||||
::android::base::LogMessage(__FILE__, __LINE__, ::android::base::dest, \
|
|
||||||
SEVERITY_LAMBDA(severity), _LOG_TAG_INTERNAL, -1) \
|
|
||||||
.stream()
|
.stream()
|
||||||
|
|
||||||
// Logs a message to logcat on Android otherwise to stderr. If the severity is
|
// Logs a message to logcat on Android otherwise to stderr. If the severity is
|
||||||
// FATAL it also causes an abort. For example:
|
// FATAL it also causes an abort. For example:
|
||||||
//
|
//
|
||||||
// LOG(FATAL) << "We didn't expect to reach here";
|
// LOG(FATAL) << "We didn't expect to reach here";
|
||||||
#define LOG(severity) LOG_TO(DEFAULT, severity)
|
#define LOG(severity) LOGGING_PREAMBLE(severity) && LOG_STREAM(severity)
|
||||||
|
|
||||||
// Checks if we want to log something, and sets up appropriate RAII objects if
|
// Checks if we want to log something, and sets up appropriate RAII objects if
|
||||||
// so.
|
// so.
|
||||||
|
|
@ -245,21 +241,12 @@ struct LogAbortAfterFullExpr {
|
||||||
ABORT_AFTER_LOG_EXPR_IF((SEVERITY_LAMBDA(severity)) == ::android::base::FATAL, true) && \
|
ABORT_AFTER_LOG_EXPR_IF((SEVERITY_LAMBDA(severity)) == ::android::base::FATAL, true) && \
|
||||||
::android::base::ErrnoRestorer())
|
::android::base::ErrnoRestorer())
|
||||||
|
|
||||||
// Logs a message to logcat with the specified log ID on Android otherwise to
|
|
||||||
// stderr. If the severity is FATAL it also causes an abort.
|
|
||||||
// Use an expression here so we can support the << operator following the macro,
|
|
||||||
// like "LOG(DEBUG) << xxx;".
|
|
||||||
#define LOG_TO(dest, severity) LOGGING_PREAMBLE(severity) && LOG_STREAM_TO(dest, severity)
|
|
||||||
|
|
||||||
// A variant of LOG that also logs the current errno value. To be used when
|
// A variant of LOG that also logs the current errno value. To be used when
|
||||||
// library calls fail.
|
// library calls fail.
|
||||||
#define PLOG(severity) PLOG_TO(DEFAULT, severity)
|
#define PLOG(severity) \
|
||||||
|
LOGGING_PREAMBLE(severity) && \
|
||||||
// Behaves like PLOG, but logs to the specified log ID.
|
::android::base::LogMessage(__FILE__, __LINE__, SEVERITY_LAMBDA(severity), \
|
||||||
#define PLOG_TO(dest, severity) \
|
_LOG_TAG_INTERNAL, errno) \
|
||||||
LOGGING_PREAMBLE(severity) && \
|
|
||||||
::android::base::LogMessage(__FILE__, __LINE__, ::android::base::dest, \
|
|
||||||
SEVERITY_LAMBDA(severity), _LOG_TAG_INTERNAL, errno) \
|
|
||||||
.stream()
|
.stream()
|
||||||
|
|
||||||
// Marker that code is yet to be implemented.
|
// Marker that code is yet to be implemented.
|
||||||
|
|
@ -272,24 +259,23 @@ struct LogAbortAfterFullExpr {
|
||||||
//
|
//
|
||||||
// CHECK(false == true) results in a log message of
|
// CHECK(false == true) results in a log message of
|
||||||
// "Check failed: false == true".
|
// "Check failed: false == true".
|
||||||
#define CHECK(x) \
|
#define CHECK(x) \
|
||||||
LIKELY((x)) || ABORT_AFTER_LOG_FATAL_EXPR(false) || \
|
LIKELY((x)) || ABORT_AFTER_LOG_FATAL_EXPR(false) || \
|
||||||
::android::base::LogMessage(__FILE__, __LINE__, ::android::base::DEFAULT, \
|
::android::base::LogMessage(__FILE__, __LINE__, ::android::base::FATAL, _LOG_TAG_INTERNAL, \
|
||||||
::android::base::FATAL, _LOG_TAG_INTERNAL, -1) \
|
-1) \
|
||||||
.stream() \
|
.stream() \
|
||||||
<< "Check failed: " #x << " "
|
<< "Check failed: " #x << " "
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
// Helper for CHECK_xx(x,y) macros.
|
// Helper for CHECK_xx(x,y) macros.
|
||||||
#define CHECK_OP(LHS, RHS, OP) \
|
#define CHECK_OP(LHS, RHS, OP) \
|
||||||
for (auto _values = ::android::base::MakeEagerEvaluator(LHS, RHS); \
|
for (auto _values = ::android::base::MakeEagerEvaluator(LHS, RHS); \
|
||||||
UNLIKELY(!(_values.lhs OP _values.rhs)); \
|
UNLIKELY(!(_values.lhs OP _values.rhs)); \
|
||||||
/* empty */) \
|
/* empty */) \
|
||||||
ABORT_AFTER_LOG_FATAL \
|
ABORT_AFTER_LOG_FATAL \
|
||||||
::android::base::LogMessage(__FILE__, __LINE__, ::android::base::DEFAULT, \
|
::android::base::LogMessage(__FILE__, __LINE__, ::android::base::FATAL, _LOG_TAG_INTERNAL, -1) \
|
||||||
::android::base::FATAL, _LOG_TAG_INTERNAL, -1) \
|
.stream() \
|
||||||
.stream() \
|
<< "Check failed: " << #LHS << " " << #OP << " " << #RHS << " (" #LHS "=" << _values.lhs \
|
||||||
<< "Check failed: " << #LHS << " " << #OP << " " << #RHS << " (" #LHS "=" << _values.lhs \
|
|
||||||
<< ", " #RHS "=" << _values.rhs << ") "
|
<< ", " #RHS "=" << _values.rhs << ") "
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
|
@ -311,8 +297,8 @@ struct LogAbortAfterFullExpr {
|
||||||
#define CHECK_STROP(s1, s2, sense) \
|
#define CHECK_STROP(s1, s2, sense) \
|
||||||
while (UNLIKELY((strcmp(s1, s2) == 0) != (sense))) \
|
while (UNLIKELY((strcmp(s1, s2) == 0) != (sense))) \
|
||||||
ABORT_AFTER_LOG_FATAL \
|
ABORT_AFTER_LOG_FATAL \
|
||||||
::android::base::LogMessage(__FILE__, __LINE__, ::android::base::DEFAULT, \
|
::android::base::LogMessage(__FILE__, __LINE__, ::android::base::FATAL, \
|
||||||
::android::base::FATAL, _LOG_TAG_INTERNAL, -1) \
|
_LOG_TAG_INTERNAL, -1) \
|
||||||
.stream() \
|
.stream() \
|
||||||
<< "Check failed: " << "\"" << (s1) << "\"" \
|
<< "Check failed: " << "\"" << (s1) << "\"" \
|
||||||
<< ((sense) ? " == " : " != ") << "\"" << (s2) << "\""
|
<< ((sense) ? " == " : " != ") << "\"" << (s2) << "\""
|
||||||
|
|
@ -431,8 +417,10 @@ class LogMessageData;
|
||||||
// of a CHECK. The destructor will abort if the severity is FATAL.
|
// of a CHECK. The destructor will abort if the severity is FATAL.
|
||||||
class LogMessage {
|
class LogMessage {
|
||||||
public:
|
public:
|
||||||
LogMessage(const char* file, unsigned int line, LogId id, LogSeverity severity, const char* tag,
|
// LogId has been deprecated, but this constructor must exist for prebuilts.
|
||||||
|
LogMessage(const char* file, unsigned int line, LogId, LogSeverity severity, const char* tag,
|
||||||
int error);
|
int error);
|
||||||
|
LogMessage(const char* file, unsigned int line, LogSeverity severity, const char* tag, int error);
|
||||||
|
|
||||||
~LogMessage();
|
~LogMessage();
|
||||||
|
|
||||||
|
|
@ -441,8 +429,8 @@ class LogMessage {
|
||||||
std::ostream& stream();
|
std::ostream& stream();
|
||||||
|
|
||||||
// The routine that performs the actual logging.
|
// The routine that performs the actual logging.
|
||||||
static void LogLine(const char* file, unsigned int line, LogId id, LogSeverity severity,
|
static void LogLine(const char* file, unsigned int line, LogSeverity severity, const char* tag,
|
||||||
const char* tag, const char* msg);
|
const char* msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::unique_ptr<LogMessageData> data_;
|
const std::unique_ptr<LogMessageData> data_;
|
||||||
|
|
|
||||||
|
|
@ -350,11 +350,10 @@ void SetAborter(AbortFunction&& aborter) {
|
||||||
// checks/logging in a function.
|
// checks/logging in a function.
|
||||||
class LogMessageData {
|
class LogMessageData {
|
||||||
public:
|
public:
|
||||||
LogMessageData(const char* file, unsigned int line, LogId id, LogSeverity severity,
|
LogMessageData(const char* file, unsigned int line, LogSeverity severity, const char* tag,
|
||||||
const char* tag, int error)
|
int error)
|
||||||
: file_(GetFileBasename(file)),
|
: file_(GetFileBasename(file)),
|
||||||
line_number_(line),
|
line_number_(line),
|
||||||
id_(id),
|
|
||||||
severity_(severity),
|
severity_(severity),
|
||||||
tag_(tag),
|
tag_(tag),
|
||||||
error_(error) {}
|
error_(error) {}
|
||||||
|
|
@ -373,10 +372,6 @@ class LogMessageData {
|
||||||
|
|
||||||
const char* GetTag() const { return tag_; }
|
const char* GetTag() const { return tag_; }
|
||||||
|
|
||||||
LogId GetId() const {
|
|
||||||
return id_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int GetError() const {
|
int GetError() const {
|
||||||
return error_;
|
return error_;
|
||||||
}
|
}
|
||||||
|
|
@ -393,7 +388,6 @@ class LogMessageData {
|
||||||
std::ostringstream buffer_;
|
std::ostringstream buffer_;
|
||||||
const char* const file_;
|
const char* const file_;
|
||||||
const unsigned int line_number_;
|
const unsigned int line_number_;
|
||||||
const LogId id_;
|
|
||||||
const LogSeverity severity_;
|
const LogSeverity severity_;
|
||||||
const char* const tag_;
|
const char* const tag_;
|
||||||
const int error_;
|
const int error_;
|
||||||
|
|
@ -401,9 +395,13 @@ class LogMessageData {
|
||||||
DISALLOW_COPY_AND_ASSIGN(LogMessageData);
|
DISALLOW_COPY_AND_ASSIGN(LogMessageData);
|
||||||
};
|
};
|
||||||
|
|
||||||
LogMessage::LogMessage(const char* file, unsigned int line, LogId id, LogSeverity severity,
|
LogMessage::LogMessage(const char* file, unsigned int line, LogId, LogSeverity severity,
|
||||||
const char* tag, int error)
|
const char* tag, int error)
|
||||||
: data_(new LogMessageData(file, line, id, severity, tag, error)) {}
|
: LogMessage(file, line, severity, tag, error) {}
|
||||||
|
|
||||||
|
LogMessage::LogMessage(const char* file, unsigned int line, LogSeverity severity, const char* tag,
|
||||||
|
int error)
|
||||||
|
: data_(new LogMessageData(file, line, severity, tag, error)) {}
|
||||||
|
|
||||||
LogMessage::~LogMessage() {
|
LogMessage::~LogMessage() {
|
||||||
// Check severity again. This is duplicate work wrt/ LOG macros, but not LOG_STREAM.
|
// Check severity again. This is duplicate work wrt/ LOG macros, but not LOG_STREAM.
|
||||||
|
|
@ -429,16 +427,16 @@ LogMessage::~LogMessage() {
|
||||||
// Do the actual logging with the lock held.
|
// Do the actual logging with the lock held.
|
||||||
std::lock_guard<std::mutex> lock(LoggingLock());
|
std::lock_guard<std::mutex> lock(LoggingLock());
|
||||||
if (msg.find('\n') == std::string::npos) {
|
if (msg.find('\n') == std::string::npos) {
|
||||||
LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetId(), data_->GetSeverity(),
|
LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetSeverity(), data_->GetTag(),
|
||||||
data_->GetTag(), msg.c_str());
|
msg.c_str());
|
||||||
} else {
|
} else {
|
||||||
msg += '\n';
|
msg += '\n';
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
while (i < msg.size()) {
|
while (i < msg.size()) {
|
||||||
size_t nl = msg.find('\n', i);
|
size_t nl = msg.find('\n', i);
|
||||||
msg[nl] = '\0';
|
msg[nl] = '\0';
|
||||||
LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetId(), data_->GetSeverity(),
|
LogLine(data_->GetFile(), data_->GetLineNumber(), data_->GetSeverity(), data_->GetTag(),
|
||||||
data_->GetTag(), &msg[i]);
|
&msg[i]);
|
||||||
// Undo the zero-termination so we can give the complete message to the aborter.
|
// Undo the zero-termination so we can give the complete message to the aborter.
|
||||||
msg[nl] = '\n';
|
msg[nl] = '\n';
|
||||||
i = nl + 1;
|
i = nl + 1;
|
||||||
|
|
@ -456,16 +454,16 @@ std::ostream& LogMessage::stream() {
|
||||||
return data_->GetBuffer();
|
return data_->GetBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogMessage::LogLine(const char* file, unsigned int line, LogId id, LogSeverity severity,
|
void LogMessage::LogLine(const char* file, unsigned int line, LogSeverity severity, const char* tag,
|
||||||
const char* tag, const char* message) {
|
const char* message) {
|
||||||
if (tag == nullptr) {
|
if (tag == nullptr) {
|
||||||
std::lock_guard<std::recursive_mutex> lock(TagLock());
|
std::lock_guard<std::recursive_mutex> lock(TagLock());
|
||||||
if (gDefaultTag == nullptr) {
|
if (gDefaultTag == nullptr) {
|
||||||
gDefaultTag = new std::string(getprogname());
|
gDefaultTag = new std::string(getprogname());
|
||||||
}
|
}
|
||||||
Logger()(id, severity, gDefaultTag->c_str(), file, line, message);
|
Logger()(DEFAULT, severity, gDefaultTag->c_str(), file, line, message);
|
||||||
} else {
|
} else {
|
||||||
Logger()(id, severity, tag, file, line, message);
|
Logger()(DEFAULT, severity, tag, file, line, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ void* storaged_main(void* /* unused */) {
|
||||||
storaged_sp->init();
|
storaged_sp->init();
|
||||||
storaged_sp->report_storage_info();
|
storaged_sp->report_storage_info();
|
||||||
|
|
||||||
LOG_TO(SYSTEM, INFO) << "storaged: Start";
|
LOG(INFO) << "storaged: Start";
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
storaged_sp->event_checked();
|
storaged_sp->event_checked();
|
||||||
|
|
@ -76,6 +76,8 @@ int main(int argc, char** argv) {
|
||||||
bool flag_dump_perf = false;
|
bool flag_dump_perf = false;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
|
android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM));
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int opt_idx = 0;
|
int opt_idx = 0;
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
|
|
@ -124,13 +126,13 @@ int main(int argc, char** argv) {
|
||||||
pthread_t storaged_main_thread;
|
pthread_t storaged_main_thread;
|
||||||
errno = pthread_create(&storaged_main_thread, NULL, storaged_main, NULL);
|
errno = pthread_create(&storaged_main_thread, NULL, storaged_main, NULL);
|
||||||
if (errno != 0) {
|
if (errno != 0) {
|
||||||
PLOG_TO(SYSTEM, ERROR) << "Failed to create main thread";
|
PLOG(ERROR) << "Failed to create main thread";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StoragedService::start() != android::OK ||
|
if (StoragedService::start() != android::OK ||
|
||||||
StoragedPrivateService::start() != android::OK) {
|
StoragedPrivateService::start() != android::OK) {
|
||||||
PLOG_TO(SYSTEM, ERROR) << "Failed to start storaged service";
|
PLOG(ERROR) << "Failed to start storaged service";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,25 +97,23 @@ void storaged_t::init_health_service() {
|
||||||
|
|
||||||
health = get_health_service();
|
health = get_health_service();
|
||||||
if (health == NULL) {
|
if (health == NULL) {
|
||||||
LOG_TO(SYSTEM, WARNING) << "health: failed to find IHealth service";
|
LOG(WARNING) << "health: failed to find IHealth service";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BatteryStatus status = BatteryStatus::UNKNOWN;
|
BatteryStatus status = BatteryStatus::UNKNOWN;
|
||||||
auto ret = health->getChargeStatus([&](Result r, BatteryStatus v) {
|
auto ret = health->getChargeStatus([&](Result r, BatteryStatus v) {
|
||||||
if (r != Result::SUCCESS) {
|
if (r != Result::SUCCESS) {
|
||||||
LOG_TO(SYSTEM, WARNING)
|
LOG(WARNING) << "health: cannot get battery status " << toString(r);
|
||||||
<< "health: cannot get battery status " << toString(r);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (v == BatteryStatus::UNKNOWN) {
|
if (v == BatteryStatus::UNKNOWN) {
|
||||||
LOG_TO(SYSTEM, WARNING) << "health: invalid battery status";
|
LOG(WARNING) << "health: invalid battery status";
|
||||||
}
|
}
|
||||||
status = v;
|
status = v;
|
||||||
});
|
});
|
||||||
if (!ret.isOk()) {
|
if (!ret.isOk()) {
|
||||||
LOG_TO(SYSTEM, WARNING) << "health: get charge status transaction error "
|
LOG(WARNING) << "health: get charge status transaction error " << ret.description();
|
||||||
<< ret.description();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mUidm.init(is_charger_on(status));
|
mUidm.init(is_charger_on(status));
|
||||||
|
|
@ -126,11 +124,11 @@ void storaged_t::init_health_service() {
|
||||||
|
|
||||||
void storaged_t::serviceDied(uint64_t cookie, const wp<::android::hidl::base::V1_0::IBase>& who) {
|
void storaged_t::serviceDied(uint64_t cookie, const wp<::android::hidl::base::V1_0::IBase>& who) {
|
||||||
if (health != NULL && interfacesEqual(health, who.promote())) {
|
if (health != NULL && interfacesEqual(health, who.promote())) {
|
||||||
LOG_TO(SYSTEM, ERROR) << "health service died, exiting";
|
LOG(ERROR) << "health service died, exiting";
|
||||||
android::hardware::IPCThreadState::self()->stopProcess();
|
android::hardware::IPCThreadState::self()->stopProcess();
|
||||||
exit(1);
|
exit(1);
|
||||||
} else {
|
} else {
|
||||||
LOG_TO(SYSTEM, ERROR) << "unknown service died";
|
LOG(ERROR) << "unknown service died";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -192,7 +190,7 @@ void storaged_t::load_proto(userid_t user_id) {
|
||||||
reinterpret_cast<const Bytef*>(uid_io_usage.SerializeAsString().c_str()),
|
reinterpret_cast<const Bytef*>(uid_io_usage.SerializeAsString().c_str()),
|
||||||
uid_io_usage.ByteSize());
|
uid_io_usage.ByteSize());
|
||||||
if (proto.crc() != computed_crc) {
|
if (proto.crc() != computed_crc) {
|
||||||
LOG_TO(SYSTEM, WARNING) << "CRC mismatch in " << proto_file;
|
LOG(WARNING) << "CRC mismatch in " << proto_file;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -228,8 +226,7 @@ char* storaged_t:: prepare_proto(userid_t user_id, StoragedProto* proto) {
|
||||||
char* data = nullptr;
|
char* data = nullptr;
|
||||||
if (posix_memalign(reinterpret_cast<void**>(&data),
|
if (posix_memalign(reinterpret_cast<void**>(&data),
|
||||||
pagesize, proto->ByteSize())) {
|
pagesize, proto->ByteSize())) {
|
||||||
PLOG_TO(SYSTEM, ERROR) << "Faied to alloc aligned buffer (size: "
|
PLOG(ERROR) << "Faied to alloc aligned buffer (size: " << proto->ByteSize() << ")";
|
||||||
<< proto->ByteSize() << ")";
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -246,7 +243,7 @@ void storaged_t::flush_proto_data(userid_t user_id,
|
||||||
(user_id == USER_SYSTEM ? O_DIRECT : 0),
|
(user_id == USER_SYSTEM ? O_DIRECT : 0),
|
||||||
S_IRUSR | S_IWUSR)));
|
S_IRUSR | S_IWUSR)));
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
PLOG_TO(SYSTEM, ERROR) << "Faied to open tmp file: " << tmp_file;
|
PLOG(ERROR) << "Faied to open tmp file: " << tmp_file;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -261,7 +258,7 @@ void storaged_t::flush_proto_data(userid_t user_id,
|
||||||
start = steady_clock::now();
|
start = steady_clock::now();
|
||||||
ret = write(fd, data, MIN(benchmark_unit_size, size));
|
ret = write(fd, data, MIN(benchmark_unit_size, size));
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
PLOG_TO(SYSTEM, ERROR) << "Faied to write tmp file: " << tmp_file;
|
PLOG(ERROR) << "Faied to write tmp file: " << tmp_file;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
end = steady_clock::now();
|
end = steady_clock::now();
|
||||||
|
|
@ -284,7 +281,7 @@ void storaged_t::flush_proto_data(userid_t user_id,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!WriteFully(fd, data, size)) {
|
if (!WriteFully(fd, data, size)) {
|
||||||
PLOG_TO(SYSTEM, ERROR) << "Faied to write tmp file: " << tmp_file;
|
PLOG(ERROR) << "Faied to write tmp file: " << tmp_file;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -343,22 +340,21 @@ void storaged_t::event_checked(void) {
|
||||||
if (mConfig.event_time_check_usec &&
|
if (mConfig.event_time_check_usec &&
|
||||||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_ts) < 0) {
|
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_ts) < 0) {
|
||||||
check_time = false;
|
check_time = false;
|
||||||
PLOG_TO(SYSTEM, ERROR) << "clock_gettime() failed";
|
PLOG(ERROR) << "clock_gettime() failed";
|
||||||
}
|
}
|
||||||
|
|
||||||
event();
|
event();
|
||||||
|
|
||||||
if (mConfig.event_time_check_usec && check_time) {
|
if (mConfig.event_time_check_usec && check_time) {
|
||||||
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_ts) < 0) {
|
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_ts) < 0) {
|
||||||
PLOG_TO(SYSTEM, ERROR) << "clock_gettime() failed";
|
PLOG(ERROR) << "clock_gettime() failed";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int64_t cost = (end_ts.tv_sec - start_ts.tv_sec) * SEC_TO_USEC +
|
int64_t cost = (end_ts.tv_sec - start_ts.tv_sec) * SEC_TO_USEC +
|
||||||
(end_ts.tv_nsec - start_ts.tv_nsec) / USEC_TO_NSEC;
|
(end_ts.tv_nsec - start_ts.tv_nsec) / USEC_TO_NSEC;
|
||||||
if (cost > mConfig.event_time_check_usec) {
|
if (cost > mConfig.event_time_check_usec) {
|
||||||
LOG_TO(SYSTEM, ERROR)
|
LOG(ERROR) << "event loop spent " << cost << " usec, threshold "
|
||||||
<< "event loop spent " << cost << " usec, threshold "
|
<< mConfig.event_time_check_usec << " usec";
|
||||||
<< mConfig.event_time_check_usec << " usec";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,8 @@ void log_debug_disk_perf(struct disk_perf* perf, const char* type) {
|
||||||
// skip if the input structure are all zeros
|
// skip if the input structure are all zeros
|
||||||
if (perf == NULL || perf->is_zero()) return;
|
if (perf == NULL || perf->is_zero()) return;
|
||||||
|
|
||||||
LOG_TO(SYSTEM, INFO) << "disk_perf " << type
|
LOG(INFO) << "disk_perf " << type << " rd: " << perf->read_perf << " kbps, " << perf->read_ios
|
||||||
<< " rd: " << perf->read_perf << " kbps, " << perf->read_ios << " iops"
|
<< " iops"
|
||||||
<< " wr: " << perf->write_perf << " kbps, " << perf->write_ios << " iops"
|
<< " wr: " << perf->write_perf << " kbps, " << perf->write_ios << " iops"
|
||||||
<< " q: " << perf->queue;
|
<< " q: " << perf->queue;
|
||||||
}
|
}
|
||||||
|
|
@ -71,7 +71,7 @@ bool get_time(struct timespec* ts) {
|
||||||
// when system is running.
|
// when system is running.
|
||||||
int ret = clock_gettime(CLOCK_MONOTONIC, ts);
|
int ret = clock_gettime(CLOCK_MONOTONIC, ts);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
PLOG_TO(SYSTEM, ERROR) << "clock_gettime() failed";
|
PLOG(ERROR) << "clock_gettime() failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -93,7 +93,7 @@ bool parse_disk_stats(const char* disk_stats_path, struct disk_stats* stats) {
|
||||||
|
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
if (!android::base::ReadFileToString(disk_stats_path, &buffer)) {
|
if (!android::base::ReadFileToString(disk_stats_path, &buffer)) {
|
||||||
PLOG_TO(SYSTEM, ERROR) << disk_stats_path << ": ReadFileToString failed.";
|
PLOG(ERROR) << disk_stats_path << ": ReadFileToString failed.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,12 +130,12 @@ bool get_disk_stats_from_health_hal(const sp<IHealth>& service, struct disk_stat
|
||||||
bool success = false;
|
bool success = false;
|
||||||
auto ret = service->getDiskStats([&success, stats](auto result, const auto& halStats) {
|
auto ret = service->getDiskStats([&success, stats](auto result, const auto& halStats) {
|
||||||
if (result == Result::NOT_SUPPORTED) {
|
if (result == Result::NOT_SUPPORTED) {
|
||||||
LOG_TO(SYSTEM, DEBUG) << "getDiskStats is not supported on health HAL.";
|
LOG(DEBUG) << "getDiskStats is not supported on health HAL.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (result != Result::SUCCESS || halStats.size() == 0) {
|
if (result != Result::SUCCESS || halStats.size() == 0) {
|
||||||
LOG_TO(SYSTEM, ERROR) << "getDiskStats failed with result " << toString(result)
|
LOG(ERROR) << "getDiskStats failed with result " << toString(result) << " and size "
|
||||||
<< " and size " << halStats.size();
|
<< halStats.size();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,7 +144,7 @@ bool get_disk_stats_from_health_hal(const sp<IHealth>& service, struct disk_stat
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!ret.isOk()) {
|
if (!ret.isOk()) {
|
||||||
LOG_TO(SYSTEM, ERROR) << "getDiskStats failed with " << ret.description();
|
LOG(ERROR) << "getDiskStats failed with " << ret.description();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -199,9 +199,9 @@ void get_inc_disk_stats(const struct disk_stats* prev, const struct disk_stats*
|
||||||
void add_disk_stats(struct disk_stats* src, struct disk_stats* dst)
|
void add_disk_stats(struct disk_stats* src, struct disk_stats* dst)
|
||||||
{
|
{
|
||||||
if (dst->end_time != 0 && dst->end_time != src->start_time) {
|
if (dst->end_time != 0 && dst->end_time != src->start_time) {
|
||||||
LOG_TO(SYSTEM, WARNING) << "Two dis-continuous periods of diskstats"
|
LOG(WARNING) << "Two dis-continuous periods of diskstats"
|
||||||
<< " are added. dst end with " << dst->end_time
|
<< " are added. dst end with " << dst->end_time << ", src start with "
|
||||||
<< ", src start with " << src->start_time;
|
<< src->start_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
*dst += *src;
|
*dst += *src;
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ void storage_info_t::load_perf_history_proto(const IOPerfHistory& perf_history)
|
||||||
if (!perf_history.has_day_start_sec() ||
|
if (!perf_history.has_day_start_sec() ||
|
||||||
perf_history.daily_perf_size() > (int)daily_perf.size() ||
|
perf_history.daily_perf_size() > (int)daily_perf.size() ||
|
||||||
perf_history.weekly_perf_size() > (int)weekly_perf.size()) {
|
perf_history.weekly_perf_size() > (int)weekly_perf.size()) {
|
||||||
LOG_TO(SYSTEM, ERROR) << "Invalid IOPerfHistory proto";
|
LOG(ERROR) << "Invalid IOPerfHistory proto";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +114,7 @@ void storage_info_t::refresh(IOPerfHistory* perf_history)
|
||||||
{
|
{
|
||||||
struct statvfs buf;
|
struct statvfs buf;
|
||||||
if (statvfs(userdata_path.c_str(), &buf) != 0) {
|
if (statvfs(userdata_path.c_str(), &buf) != 0) {
|
||||||
PLOG_TO(SYSTEM, WARNING) << "Failed to get userdata info";
|
PLOG(WARNING) << "Failed to get userdata info";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -328,12 +328,12 @@ void ufs_info_t::report()
|
||||||
void health_storage_info_t::report() {
|
void health_storage_info_t::report() {
|
||||||
auto ret = mHealth->getStorageInfo([this](auto result, const auto& halInfos) {
|
auto ret = mHealth->getStorageInfo([this](auto result, const auto& halInfos) {
|
||||||
if (result == Result::NOT_SUPPORTED) {
|
if (result == Result::NOT_SUPPORTED) {
|
||||||
LOG_TO(SYSTEM, DEBUG) << "getStorageInfo is not supported on health HAL.";
|
LOG(DEBUG) << "getStorageInfo is not supported on health HAL.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (result != Result::SUCCESS || halInfos.size() == 0) {
|
if (result != Result::SUCCESS || halInfos.size() == 0) {
|
||||||
LOG_TO(SYSTEM, ERROR) << "getStorageInfo failed with result " << toString(result)
|
LOG(ERROR) << "getStorageInfo failed with result " << toString(result) << " and size "
|
||||||
<< " and size " << halInfos.size();
|
<< halInfos.size();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
set_values_from_hal_storage_info(halInfos[0]);
|
set_values_from_hal_storage_info(halInfos[0]);
|
||||||
|
|
@ -341,7 +341,7 @@ void health_storage_info_t::report() {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!ret.isOk()) {
|
if (!ret.isOk()) {
|
||||||
LOG_TO(SYSTEM, ERROR) << "getStorageInfo failed with " << ret.description();
|
LOG(ERROR) << "getStorageInfo failed with " << ret.description();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,7 @@ bool uid_info::parse_uid_io_stats(std::string&& s)
|
||||||
!ParseUint(fields[8], &io[BACKGROUND].write_bytes) ||
|
!ParseUint(fields[8], &io[BACKGROUND].write_bytes) ||
|
||||||
!ParseUint(fields[9], &io[FOREGROUND].fsync) ||
|
!ParseUint(fields[9], &io[FOREGROUND].fsync) ||
|
||||||
!ParseUint(fields[10], &io[BACKGROUND].fsync)) {
|
!ParseUint(fields[10], &io[BACKGROUND].fsync)) {
|
||||||
LOG_TO(SYSTEM, WARNING) << "Invalid uid I/O stats: \""
|
LOG(WARNING) << "Invalid uid I/O stats: \"" << s << "\"";
|
||||||
<< s << "\"";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -95,8 +94,7 @@ bool task_info::parse_task_io_stats(std::string&& s)
|
||||||
!ParseUint(fields[size - 3], &io[BACKGROUND].write_bytes) ||
|
!ParseUint(fields[size - 3], &io[BACKGROUND].write_bytes) ||
|
||||||
!ParseUint(fields[size - 2], &io[FOREGROUND].fsync) ||
|
!ParseUint(fields[size - 2], &io[FOREGROUND].fsync) ||
|
||||||
!ParseUint(fields[size - 1], &io[BACKGROUND].fsync)) {
|
!ParseUint(fields[size - 1], &io[BACKGROUND].fsync)) {
|
||||||
LOG_TO(SYSTEM, WARNING) << "Invalid task I/O stats: \""
|
LOG(WARNING) << "Invalid task I/O stats: \"" << s << "\"";
|
||||||
<< s << "\"";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
comm = Join(std::vector<std::string>(
|
comm = Join(std::vector<std::string>(
|
||||||
|
|
@ -123,13 +121,13 @@ void get_uid_names(const vector<int>& uids, const vector<std::string*>& uid_name
|
||||||
{
|
{
|
||||||
sp<IServiceManager> sm = defaultServiceManager();
|
sp<IServiceManager> sm = defaultServiceManager();
|
||||||
if (sm == NULL) {
|
if (sm == NULL) {
|
||||||
LOG_TO(SYSTEM, ERROR) << "defaultServiceManager failed";
|
LOG(ERROR) << "defaultServiceManager failed";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sp<IBinder> binder = sm->getService(String16("package_native"));
|
sp<IBinder> binder = sm->getService(String16("package_native"));
|
||||||
if (binder == NULL) {
|
if (binder == NULL) {
|
||||||
LOG_TO(SYSTEM, ERROR) << "getService package_native failed";
|
LOG(ERROR) << "getService package_native failed";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,8 +135,7 @@ void get_uid_names(const vector<int>& uids, const vector<std::string*>& uid_name
|
||||||
std::vector<std::string> names;
|
std::vector<std::string> names;
|
||||||
binder::Status status = package_mgr->getNamesForUids(uids, &names);
|
binder::Status status = package_mgr->getNamesForUids(uids, &names);
|
||||||
if (!status.isOk()) {
|
if (!status.isOk()) {
|
||||||
LOG_TO(SYSTEM, ERROR) << "package_native::getNamesForUids failed: "
|
LOG(ERROR) << "package_native::getNamesForUids failed: " << status.exceptionMessage();
|
||||||
<< status.exceptionMessage();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -158,7 +155,7 @@ std::unordered_map<uint32_t, uid_info> uid_monitor::get_uid_io_stats_locked()
|
||||||
std::unordered_map<uint32_t, uid_info> uid_io_stats;
|
std::unordered_map<uint32_t, uid_info> uid_io_stats;
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
if (!ReadFileToString(UID_IO_STATS_PATH, &buffer)) {
|
if (!ReadFileToString(UID_IO_STATS_PATH, &buffer)) {
|
||||||
PLOG_TO(SYSTEM, ERROR) << UID_IO_STATS_PATH << ": ReadFileToString failed";
|
PLOG(ERROR) << UID_IO_STATS_PATH << ": ReadFileToString failed";
|
||||||
return uid_io_stats;
|
return uid_io_stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue