diff options
author | Tom Cherry <tomcherry@google.com> | 2020-01-10 17:09:45 -0800 |
---|---|---|
committer | Tom Cherry <tomcherry@google.com> | 2020-01-13 07:06:05 -0800 |
commit | 4a2c84ca96fb8cde96accfb22f82d0666b6f8374 (patch) | |
tree | a62429eac5b169180b4bb075daed19b2ae104659 /perfstatsd | |
parent | 45cac1658faa54a039c71bab9e1429139b17c42e (diff) | |
download | pixel-4a2c84ca96fb8cde96accfb22f82d0666b6f8374.tar.gz |
perfstatsd: replace LOG_TO() macros with LOG()
perfstatsd always writes to the SYSTEM log, so instead of using
LOG_TO(), it can use the normal LOG() macros as long as it calls
InitLogging() with a default to the SYSTEM log.
Test: perfstatsd writes to the SYSTEM log still
Change-Id: Ib15867589c0b5679cc14f9fe8694ef48fc0e599e
Diffstat (limited to 'perfstatsd')
-rw-r--r-- | perfstatsd/cpu_usage.cpp | 49 | ||||
-rw-r--r-- | perfstatsd/include/io_usage.h | 2 | ||||
-rw-r--r-- | perfstatsd/io_usage.cpp | 38 | ||||
-rw-r--r-- | perfstatsd/main.cpp | 20 | ||||
-rw-r--r-- | perfstatsd/perfstatsd.cpp | 7 |
5 files changed, 58 insertions, 58 deletions
diff --git a/perfstatsd/cpu_usage.cpp b/perfstatsd/cpu_usage.cpp index 6bbeb2db..5a26ace6 100644 --- a/perfstatsd/cpu_usage.cpp +++ b/perfstatsd/cpu_usage.cpp @@ -51,22 +51,22 @@ void CpuUsage::setOptions(const std::string &key, const std::string &value) { key == CPU_TOPCOUNT) { uint32_t val = 0; if (!base::ParseUint(value, &val)) { - LOG_TO(SYSTEM, ERROR) << "Invalid value: " << value; + LOG(ERROR) << "Invalid value: " << value; return; } if (key == PROCPROF_THRESHOLD) { mProfileThreshold = val; - LOG_TO(SYSTEM, INFO) << "set profile threshold " << mProfileThreshold; + LOG(INFO) << "set profile threshold " << mProfileThreshold; } else if (key == CPU_DISABLED) { mDisabled = (val != 0); - LOG_TO(SYSTEM, INFO) << "set disabled " << mDisabled; + LOG(INFO) << "set disabled " << mDisabled; } else if (key == CPU_DEBUG) { cDebug = (val != 0); - LOG_TO(SYSTEM, INFO) << "set debug " << cDebug; + LOG(INFO) << "set debug " << cDebug; } else if (key == CPU_TOPCOUNT) { mTopcount = val; - LOG_TO(SYSTEM, INFO) << "set top count " << mTopcount; + LOG(INFO) << "set top count " << mTopcount; } } } @@ -98,7 +98,7 @@ void CpuUsage::profileProcess(std::string *out) { !base::ParseUint(fields[14], &stime) || !base::ParseUint(fields[15], &cutime) || !base::ParseUint(fields[16], &cstime)) { - LOG_TO(SYSTEM, ERROR) << "Invalid proc data\n" << pidStat; + LOG(ERROR) << "Invalid proc data\n" << pidStat; continue; } std::string proc = fields[1]; @@ -120,10 +120,10 @@ void CpuUsage::profileProcess(std::string *out) { float usageRatio = (float)(diffUsage * 100.0 / mDiffCpu); if (cDebug && usageRatio > 100) { - LOG_TO(SYSTEM, INFO) << "pid: " << pid << " , ratio: " << usageRatio - << " , prev usage: " << mPrevProcdata[pid].usage - << " , cur usage: " << totalUsage - << " , total cpu diff: " << mDiffCpu; + LOG(INFO) << "pid: " << pid << " , ratio: " << usageRatio + << " , prev usage: " << mPrevProcdata[pid].usage + << " , cur usage: " << totalUsage + << " , total cpu diff: " << mDiffCpu; } ProcData data; @@ -147,7 +147,7 @@ void CpuUsage::profileProcess(std::string *out) { } closedir(dir); } else { - LOG_TO(SYSTEM, ERROR) << "Fail to open /proc/"; + LOG(ERROR) << "Fail to open /proc/"; } } @@ -186,7 +186,7 @@ void CpuUsage::getOverallUsage(std::chrono::system_clock::time_point &now, std:: !base::ParseUint(fields[base + 5], &irq) || !base::ParseUint(fields[base + 6], &softirq) || !base::ParseUint(fields[base + 7], &steal)) { - LOG_TO(SYSTEM, ERROR) << "Invalid /proc/stat data\n" << line; + LOG(ERROR) << "Invalid /proc/stat data\n" << line; continue; } @@ -207,10 +207,9 @@ void CpuUsage::getOverallUsage(std::chrono::system_clock::time_point &now, std:: float ioRatio = (float)(diffIo * 100.0 / mDiffCpu); if (cDebug) { - LOG_TO(SYSTEM, INFO) - << "prev total: " << mPrevUsage.cpuUsage - << " , cur total: " << cpuUsage << " , diffusage: " << diffUsage - << " , diffcpu: " << mDiffCpu << " , ratio: " << mTotalRatio; + LOG(INFO) << "prev total: " << mPrevUsage.cpuUsage + << " , cur total: " << cpuUsage << " , diffusage: " << diffUsage + << " , diffcpu: " << mDiffCpu << " , ratio: " << mTotalRatio; } mPrevUsage.cpuUsage = cpuUsage; @@ -227,16 +226,18 @@ void CpuUsage::getOverallUsage(std::chrono::system_clock::time_point &now, std:: // calculate total cpu usage of each core uint32_t c = 0; if (!base::ParseUint(core, &c)) { - LOG_TO(SYSTEM, ERROR) << "Invalid core: " << core; + LOG(ERROR) << "Invalid core: " << core; continue; } uint64_t diffUsage = cpuUsage - mPrevCoresUsage[c].cpuUsage; float coreTotalRatio = (float)(diffUsage * 100.0 / mDiffCpu); if (cDebug) { - LOG_TO(SYSTEM, INFO) - << "core " << c << " , prev cpu usage: " << mPrevCoresUsage[c].cpuUsage - << " , cur cpu usage: " << cpuUsage << " , diffusage: " << diffUsage - << " , difftotalcpu: " << mDiffCpu << " , ratio: " << coreTotalRatio; + LOG(INFO) << "core " << c + << " , prev cpu usage: " << mPrevCoresUsage[c].cpuUsage + << " , cur cpu usage: " << cpuUsage + << " , diffusage: " << diffUsage + << " , difftotalcpu: " << mDiffCpu + << " , ratio: " << coreTotalRatio; } mPrevCoresUsage[c].cpuUsage = cpuUsage; @@ -248,7 +249,7 @@ void CpuUsage::getOverallUsage(std::chrono::system_clock::time_point &now, std:: } out->append("\n"); } else { - LOG_TO(SYSTEM, ERROR) << "Fail to read /proc/stat"; + LOG(ERROR) << "Fail to read /proc/stat"; } } @@ -263,7 +264,7 @@ void CpuUsage::refresh(void) { if (mTotalRatio >= mProfileThreshold) { if (cDebug) - LOG_TO(SYSTEM, INFO) << "Total CPU usage over " << mProfileThreshold << "%"; + LOG(INFO) << "Total CPU usage over " << mProfileThreshold << "%"; std::string profileResult; profileProcess(&profileResult); if (mProfileProcess) { @@ -279,6 +280,6 @@ void CpuUsage::refresh(void) { if (cDebug) { auto ms = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::system_clock::now() - now); - LOG_TO(SYSTEM, INFO) << "Took " << ms.count() << " ms, data bytes: " << out.length(); + LOG(INFO) << "Took " << ms.count() << " ms, data bytes: " << out.length(); } } diff --git a/perfstatsd/include/io_usage.h b/perfstatsd/include/io_usage.h index 49232ad4..e96ca376 100644 --- a/perfstatsd/include/io_usage.h +++ b/perfstatsd/include/io_usage.h @@ -118,7 +118,7 @@ class ScopeTimer { if (!mDisabled) { std::string msg; dump(&msg); - LOG_TO(SYSTEM, INFO) << msg; + LOG(INFO) << msg; } } void setEnabled(bool enabled) { mDisabled = !enabled; } diff --git a/perfstatsd/io_usage.cpp b/perfstatsd/io_usage.cpp index 7c067911..a325bef9 100644 --- a/perfstatsd/io_usage.cpp +++ b/perfstatsd/io_usage.cpp @@ -97,7 +97,7 @@ void ProcPidIoStats::update(bool forceAll) { DIR *dir; struct dirent *ent; if ((dir = opendir("/proc/")) == NULL) { - LOG_TO(SYSTEM, ERROR) << "failed on opendir '/proc/'"; + LOG(ERROR) << "failed on opendir '/proc/'"; return; } while ((ent = readdir(dir)) != NULL) { @@ -113,12 +113,12 @@ void ProcPidIoStats::update(bool forceAll) { for (int i = 0, len = newpids.size(); i < len; i++) { uint32_t pid = newpids[i]; if (sOptDebug > 1) - LOG_TO(SYSTEM, INFO) << i << "."; + LOG(INFO) << i << "."; std::string buffer; if (!android::base::ReadFileToString("/proc/" + std::to_string(pid) + "/status", &buffer)) { if (sOptDebug) - LOG_TO(SYSTEM, INFO) << "/proc/" << std::to_string(pid) << "/status" - << ": ReadFileToString failed (process died?)"; + LOG(INFO) << "/proc/" << std::to_string(pid) << "/status" + << ": ReadFileToString failed (process died?)"; continue; } // --- Find Name --- @@ -154,8 +154,8 @@ void ProcPidIoStats::update(bool forceAll) { std::string strUid(buffer, s, e - s); if (sOptDebug > 1) - LOG_TO(SYSTEM, INFO) << "(pid, name, uid)=(" << pid << ", " << pname << ", " << strUid - << ")" << std::endl; + LOG(INFO) << "(pid, name, uid)=(" << pid << ", " << pname << ", " << strUid << ")" + << std::endl; uint32_t uid = (uint32_t)std::stoi(strUid); mUidNameMapping[uid] = pname; } @@ -207,7 +207,7 @@ void IoStats::updateUnknownUidList() { std::string pname; if (!mProcIoStats.getNameForUid(uid, &pname)) { if (sOptDebug) - LOG_TO(SYSTEM, WARNING) << "unable to find App uid:" << uid; + LOG(WARNING) << "unable to find App uid:" << uid; continue; } mUidNameMap[uid] = pname; @@ -216,7 +216,7 @@ void IoStats::updateUnknownUidList() { passwd *usrpwd = getpwuid(uid); if (!usrpwd) { if (sOptDebug) - LOG_TO(SYSTEM, WARNING) << "unable to find uid:" << uid << " by getpwuid"; + LOG(WARNING) << "unable to find uid:" << uid << " by getpwuid"; continue; } mUidNameMap[uid] = std::string(usrpwd->pw_name); @@ -234,7 +234,7 @@ void IoStats::updateUnknownUidList() { for (const auto &i : mUnknownUidList) { msg << i << ", "; } - LOG_TO(SYSTEM, WARNING) << msg.str(); + LOG(WARNING) << msg.str(); } mUnknownUidList.clear(); } @@ -320,12 +320,10 @@ bool IoStats::dump(std::stringstream *output) { char readTotal[32]; char writeTotal[32]; if (!formatNum(mTotal.sumRead(), readTotal, 32)) { - LOG_TO(SYSTEM, ERROR) << "formatNum buffer size is too small for read: " - << mTotal.sumRead(); + LOG(ERROR) << "formatNum buffer size is too small for read: " << mTotal.sumRead(); } if (!formatNum(mTotal.sumWrite(), writeTotal, 32)) { - LOG_TO(SYSTEM, ERROR) << "formatNum buffer size is too small for write: " - << mTotal.sumWrite(); + LOG(ERROR) << "formatNum buffer size is too small for write: " << mTotal.sumWrite(); } out << android::base::StringPrintf(FMT_STR_TOTAL_USAGE, ms.count() / 1000, ms.count() % 1000, @@ -385,7 +383,7 @@ static bool loadDataFromLine(std::string &&line, UserIo &data) { !android::base::ParseUint(fields[8], &data.bgWrite) || !android::base::ParseUint(fields[9], &data.fgFsync) || !android::base::ParseUint(fields[10], &data.bgFsync)) { - LOG_TO(SYSTEM, WARNING) << "Invalid uid I/O stats: \"" << line << "\""; + LOG(WARNING) << "Invalid uid I/O stats: \"" << line << "\""; return false; } return true; @@ -416,7 +414,7 @@ void IoUsage::setOptions(const std::string &key, const std::string &value) { uint64_t val = 0; if (!android::base::ParseUint(value, &val)) { out << "!!!! unable to parse value to uint64"; - LOG_TO(SYSTEM, ERROR) << out.str(); + LOG(ERROR) << out.str(); return; } if (key == "iostats.min") { @@ -431,7 +429,7 @@ void IoUsage::setOptions(const std::string &key, const std::string &value) { } else if (key == "iostats.debug") { sOptDebug = (val != 0); } - LOG_TO(SYSTEM, INFO) << out.str() << ": Success"; + LOG(INFO) << out.str() << ": Success"; } } @@ -442,10 +440,10 @@ void IoUsage::refresh(void) { _debugTimer.setEnabled(sOptDebug); std::string buffer; if (!android::base::ReadFileToString(UID_IO_STATS_PATH, &buffer)) { - LOG_TO(SYSTEM, ERROR) << UID_IO_STATS_PATH << ": ReadFileToString failed"; + LOG(ERROR) << UID_IO_STATS_PATH << ": ReadFileToString failed"; } if (sOptDebug) - LOG_TO(SYSTEM, INFO) << "read " << UID_IO_STATS_PATH << " OK."; + LOG(INFO) << "read " << UID_IO_STATS_PATH << " OK."; std::vector<std::string> lines = android::base::Split(std::move(buffer), "\n"); std::unordered_map<uint32_t, UserIo> datas; for (uint32_t i = 0; i < lines.size(); i++) { @@ -462,8 +460,8 @@ void IoUsage::refresh(void) { mStats.dump(&out); const std::string &str = out.str(); if (sOptDebug) { - LOG_TO(SYSTEM, INFO) << str; - LOG_TO(SYSTEM, INFO) << "output append length:" << str.length(); + LOG(INFO) << str; + LOG(INFO) << "output append length:" << str.length(); } append((std::string &)str); } diff --git a/perfstatsd/main.cpp b/perfstatsd/main.cpp index fc054841..16fc20e0 100644 --- a/perfstatsd/main.cpp +++ b/perfstatsd/main.cpp @@ -24,7 +24,7 @@ enum MODE { DUMP_HISTORY, SET_OPTION }; android::sp<Perfstatsd> perfstatsdSp; void *perfstatsdMain(void *) { - LOG_TO(SYSTEM, INFO) << "main thread started"; + LOG(INFO) << "main thread started"; perfstatsdSp = new Perfstatsd(); while (true) { @@ -49,7 +49,7 @@ int startService(void) { pthread_t perfstatsdMainThread; errno = pthread_create(&perfstatsdMainThread, NULL, perfstatsdMain, NULL); if (errno != 0) { - PLOG_TO(SYSTEM, ERROR) << "Failed to create main thread"; + PLOG(ERROR) << "Failed to create main thread"; return -1; } else { pthread_setname_np(perfstatsdMainThread, "perfstatsd_main"); @@ -58,10 +58,10 @@ int startService(void) { android::ProcessState::initWithDriver("/dev/vndbinder"); if (PerfstatsdPrivateService::start() != android::OK) { - PLOG_TO(SYSTEM, ERROR) << "Failed to start perfstatsd service"; + PLOG(ERROR) << "Failed to start perfstatsd service"; return -1; } else - LOG_TO(SYSTEM, INFO) << "perfstatsd_pri_service started"; + LOG(INFO) << "perfstatsd_pri_service started"; android::ProcessState::self()->startThreadPool(); android::IPCThreadState::self()->joinThreadPool(); @@ -74,7 +74,7 @@ int serviceCall(int mode, const std::string &key, const std::string &value) { android::sp<IPerfstatsdPrivate> perfstatsdPrivateService = getPerfstatsdPrivateService(); if (perfstatsdPrivateService == NULL) { - PLOG_TO(SYSTEM, ERROR) << "Cannot find perfstatsd service."; + PLOG(ERROR) << "Cannot find perfstatsd service."; fprintf(stdout, "Cannot find perfstatsd service.\n"); return -1; } @@ -82,9 +82,9 @@ int serviceCall(int mode, const std::string &key, const std::string &value) { switch (mode) { case DUMP_HISTORY: { std::string history; - LOG_TO(SYSTEM, INFO) << "dump perfstats history."; + LOG(INFO) << "dump perfstats history."; if (!perfstatsdPrivateService->dumpHistory(&history).isOk() || history.empty()) { - PLOG_TO(SYSTEM, ERROR) << "perf stats history is not available"; + PLOG(ERROR) << "perf stats history is not available"; fprintf(stdout, "perf stats history is not available\n"); return -1; } @@ -92,12 +92,12 @@ int serviceCall(int mode, const std::string &key, const std::string &value) { break; } case SET_OPTION: - LOG_TO(SYSTEM, INFO) << "set option: " << key << " , " << value; + LOG(INFO) << "set option: " << key << " , " << value; if (!perfstatsdPrivateService ->setOptions(std::forward<const std::string>(key), std::forward<const std::string>(value)) .isOk()) { - PLOG_TO(SYSTEM, ERROR) << "fail to set options"; + PLOG(ERROR) << "fail to set options"; fprintf(stdout, "fail to set options\n"); return -1; } @@ -112,6 +112,8 @@ int serviceCall(int mode) { } int main(int argc, char **argv) { + android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM)); + int c; while ((c = getopt(argc, argv, "sdo:h")) != -1) { switch (c) { diff --git a/perfstatsd/perfstatsd.cpp b/perfstatsd/perfstatsd.cpp index 6a16e470..60836c59 100644 --- a/perfstatsd/perfstatsd.cpp +++ b/perfstatsd/perfstatsd.cpp @@ -64,18 +64,17 @@ void Perfstatsd::getHistory(std::string *ret) { } if (ret->size() > 400_KiB) - LOG_TO(SYSTEM, WARNING) << "Data might be too large. size: " << ret->size() << " bytes\n" - << *ret; + LOG(WARNING) << "Data might be too large. size: " << ret->size() << " bytes\n" << *ret; } void Perfstatsd::setOptions(const std::string &key, const std::string &value) { if (key == PERFSTATSD_PERIOD) { uint32_t val = 0; if (!base::ParseUint(value, &val) || val < 1) { - LOG_TO(SYSTEM, ERROR) << "Invalid value. Minimum refresh period is 1 second"; + LOG(ERROR) << "Invalid value. Minimum refresh period is 1 second"; } else { mRefreshPeriod = val; - LOG_TO(SYSTEM, INFO) << "set period to " << value << " seconds"; + LOG(INFO) << "set period to " << value << " seconds"; } return; } |