perfstatsd: replace LOG_TO() macros with LOG()
am: 4a2c84ca96

Change-Id: I20ac079043f553c52487f746eea470f7a3ff37e4
diff --git a/perfstatsd/cpu_usage.cpp b/perfstatsd/cpu_usage.cpp
index 6bbeb2d..5a26ace 100644
--- a/perfstatsd/cpu_usage.cpp
+++ b/perfstatsd/cpu_usage.cpp
@@ -51,22 +51,22 @@
         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 @@
                             !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 @@
 
                         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 @@
         }
         closedir(dir);
     } else {
-        LOG_TO(SYSTEM, ERROR) << "Fail to open /proc/";
+        LOG(ERROR) << "Fail to open /proc/";
     }
 }
 
@@ -186,7 +186,7 @@
                     !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 @@
                     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 @@
                     // 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 @@
         }
         out->append("\n");
     } else {
-        LOG_TO(SYSTEM, ERROR) << "Fail to read /proc/stat";
+        LOG(ERROR) << "Fail to read /proc/stat";
     }
 }
 
@@ -263,7 +264,7 @@
 
     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 @@
     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 49232ad..e96ca37 100644
--- a/perfstatsd/include/io_usage.h
+++ b/perfstatsd/include/io_usage.h
@@ -118,7 +118,7 @@
         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 7c06791..a325bef 100644
--- a/perfstatsd/io_usage.cpp
+++ b/perfstatsd/io_usage.cpp
@@ -97,7 +97,7 @@
     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 @@
     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 @@
         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 @@
             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 @@
             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 @@
         for (const auto &i : mUnknownUidList) {
             msg << i << ", ";
         }
-        LOG_TO(SYSTEM, WARNING) << msg.str();
+        LOG(WARNING) << msg.str();
     }
     mUnknownUidList.clear();
 }
@@ -320,12 +320,10 @@
     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 @@
         !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 @@
         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 @@
         } else if (key == "iostats.debug") {
             sOptDebug = (val != 0);
         }
-        LOG_TO(SYSTEM, INFO) << out.str() << ": Success";
+        LOG(INFO) << out.str() << ": Success";
     }
 }
 
@@ -442,10 +440,10 @@
     _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 @@
     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 fc05484..16fc20e 100644
--- a/perfstatsd/main.cpp
+++ b/perfstatsd/main.cpp
@@ -24,7 +24,7 @@
 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 @@
     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 @@
     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 @@
 
     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 @@
     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 @@
             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 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 6a16e47..60836c5 100644
--- a/perfstatsd/perfstatsd.cpp
+++ b/perfstatsd/perfstatsd.cpp
@@ -64,18 +64,17 @@
     }
 
     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;
     }