Loading logd/CommandListener.cpp +13 −41 Original line number Diff line number Diff line Loading @@ -25,6 +25,9 @@ #include <sys/socket.h> #include <sys/types.h> #include <string> #include <base/stringprintf.h> #include <cutils/sockets.h> #include <private/android_filesystem_config.h> #include <sysutils/SocketClient.h> Loading Loading @@ -189,22 +192,13 @@ CommandListener::GetStatisticsCmd::GetStatisticsCmd(LogBuffer *buf) : mBuf(*buf) { } static void package_string(char **strp) { const char *a = *strp; if (!a) { a = ""; } static std::string package_string(const std::string &str) { // Calculate total buffer size prefix, count is the string length w/o nul char fmt[32]; for(size_t l = strlen(a), y = 0, x = 6; y != x; y = x, x = strlen(fmt) - 2) { for(size_t l = str.length(), y = 0, x = 6; y != x; y = x, x = strlen(fmt) - 2) { snprintf(fmt, sizeof(fmt), "%zu\n%%s\n\f", l + x); } char *b = *strp; *strp = NULL; asprintf(strp, fmt, a); free(b); return android::base::StringPrintf(fmt, str.c_str()); } int CommandListener::GetStatisticsCmd::runCommand(SocketClient *cli, Loading @@ -228,16 +222,7 @@ int CommandListener::GetStatisticsCmd::runCommand(SocketClient *cli, } } char *buf = NULL; mBuf.formatStatistics(&buf, uid, logMask); if (!buf) { cli->sendMsg("Failed"); } else { package_string(&buf); cli->sendMsg(buf); free(buf); } cli->sendMsg(package_string(mBuf.formatStatistics(uid, logMask)).c_str()); return 0; } Loading @@ -249,15 +234,7 @@ CommandListener::GetPruneListCmd::GetPruneListCmd(LogBuffer *buf) : int CommandListener::GetPruneListCmd::runCommand(SocketClient *cli, int /*argc*/, char ** /*argv*/) { setname(); char *buf = NULL; mBuf.formatPrune(&buf); if (!buf) { cli->sendMsg("Failed"); } else { package_string(&buf); cli->sendMsg(buf); free(buf); } cli->sendMsg(package_string(mBuf.formatPrune()).c_str()); return 0; } Loading @@ -274,20 +251,15 @@ int CommandListener::SetPruneListCmd::runCommand(SocketClient *cli, return 0; } char *cp = NULL; std::string str; for (int i = 1; i < argc; ++i) { char *p = cp; if (p) { cp = NULL; asprintf(&cp, "%s %s", p, argv[i]); free(p); } else { asprintf(&cp, "%s", argv[i]); if (str.length()) { str += " "; } str += argv[i]; } int ret = mBuf.initPrune(cp); free(cp); int ret = mBuf.initPrune(str.c_str()); if (ret) { cli->sendMsg("Invalid"); Loading logd/LogBuffer.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -690,10 +690,12 @@ uint64_t LogBuffer::flushTo( return max; } void LogBuffer::formatStatistics(char **strp, uid_t uid, unsigned int logMask) { std::string LogBuffer::formatStatistics(uid_t uid, unsigned int logMask) { pthread_mutex_lock(&mLogElementsLock); stats.format(strp, uid, logMask); std::string ret = stats.format(uid, logMask); pthread_mutex_unlock(&mLogElementsLock); return ret; } logd/LogBuffer.h +4 −4 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <sys/types.h> #include <list> #include <string> #include <log/log.h> #include <sysutils/SocketClient.h> Loading Loading @@ -67,15 +68,14 @@ public: int setSize(log_id_t id, unsigned long size); unsigned long getSizeUsed(log_id_t id); // *strp uses malloc, use free to release. void formatStatistics(char **strp, uid_t uid, unsigned int logMask); std::string formatStatistics(uid_t uid, unsigned int logMask); void enableStatistics() { stats.enableStatistics(); } int initPrune(char *cp) { return mPrune.init(cp); } // *strp uses malloc, use free to release. void formatPrune(char **strp) { mPrune.format(strp); } int initPrune(const char *cp) { return mPrune.init(cp); } std::string formatPrune() { return mPrune.format(); } // helper must be protected directly or implicitly by lock()/unlock() char *pidToName(pid_t pid) { return stats.pidToName(pid); } Loading logd/LogStatistics.cpp +2 −9 Original line number Diff line number Diff line Loading @@ -20,8 +20,6 @@ #include <string.h> #include <unistd.h> #include <string> #include <base/stringprintf.h> #include <log/logger.h> #include <private/android_filesystem_config.h> Loading Loading @@ -206,14 +204,9 @@ static std::string format_line( } } void LogStatistics::format(char **buf, uid_t uid, unsigned int logMask) { std::string LogStatistics::format(uid_t uid, unsigned int logMask) { static const unsigned short spaces_total = 19; if (*buf) { free(*buf); *buf = NULL; } // Report on total logging, current and for all time std::string output = "size/num"; Loading Loading @@ -514,7 +507,7 @@ void LogStatistics::format(char **buf, uid_t uid, unsigned int logMask) { } } *buf = strdup(output.c_str()); return output; } namespace android { Loading logd/LogStatistics.h +1 −2 Original line number Diff line number Diff line Loading @@ -331,8 +331,7 @@ public: size_t sizesTotal(log_id_t id) const { return mSizesTotal[id]; } size_t elementsTotal(log_id_t id) const { return mElementsTotal[id]; } // *strp = malloc, balance with free void format(char **strp, uid_t uid, unsigned int logMask); std::string format(uid_t uid, unsigned int logMask); // helper (must be locked directly or implicitly by mLogElementsLock) char *pidToName(pid_t pid); Loading Loading
logd/CommandListener.cpp +13 −41 Original line number Diff line number Diff line Loading @@ -25,6 +25,9 @@ #include <sys/socket.h> #include <sys/types.h> #include <string> #include <base/stringprintf.h> #include <cutils/sockets.h> #include <private/android_filesystem_config.h> #include <sysutils/SocketClient.h> Loading Loading @@ -189,22 +192,13 @@ CommandListener::GetStatisticsCmd::GetStatisticsCmd(LogBuffer *buf) : mBuf(*buf) { } static void package_string(char **strp) { const char *a = *strp; if (!a) { a = ""; } static std::string package_string(const std::string &str) { // Calculate total buffer size prefix, count is the string length w/o nul char fmt[32]; for(size_t l = strlen(a), y = 0, x = 6; y != x; y = x, x = strlen(fmt) - 2) { for(size_t l = str.length(), y = 0, x = 6; y != x; y = x, x = strlen(fmt) - 2) { snprintf(fmt, sizeof(fmt), "%zu\n%%s\n\f", l + x); } char *b = *strp; *strp = NULL; asprintf(strp, fmt, a); free(b); return android::base::StringPrintf(fmt, str.c_str()); } int CommandListener::GetStatisticsCmd::runCommand(SocketClient *cli, Loading @@ -228,16 +222,7 @@ int CommandListener::GetStatisticsCmd::runCommand(SocketClient *cli, } } char *buf = NULL; mBuf.formatStatistics(&buf, uid, logMask); if (!buf) { cli->sendMsg("Failed"); } else { package_string(&buf); cli->sendMsg(buf); free(buf); } cli->sendMsg(package_string(mBuf.formatStatistics(uid, logMask)).c_str()); return 0; } Loading @@ -249,15 +234,7 @@ CommandListener::GetPruneListCmd::GetPruneListCmd(LogBuffer *buf) : int CommandListener::GetPruneListCmd::runCommand(SocketClient *cli, int /*argc*/, char ** /*argv*/) { setname(); char *buf = NULL; mBuf.formatPrune(&buf); if (!buf) { cli->sendMsg("Failed"); } else { package_string(&buf); cli->sendMsg(buf); free(buf); } cli->sendMsg(package_string(mBuf.formatPrune()).c_str()); return 0; } Loading @@ -274,20 +251,15 @@ int CommandListener::SetPruneListCmd::runCommand(SocketClient *cli, return 0; } char *cp = NULL; std::string str; for (int i = 1; i < argc; ++i) { char *p = cp; if (p) { cp = NULL; asprintf(&cp, "%s %s", p, argv[i]); free(p); } else { asprintf(&cp, "%s", argv[i]); if (str.length()) { str += " "; } str += argv[i]; } int ret = mBuf.initPrune(cp); free(cp); int ret = mBuf.initPrune(str.c_str()); if (ret) { cli->sendMsg("Invalid"); Loading
logd/LogBuffer.cpp +4 −2 Original line number Diff line number Diff line Loading @@ -690,10 +690,12 @@ uint64_t LogBuffer::flushTo( return max; } void LogBuffer::formatStatistics(char **strp, uid_t uid, unsigned int logMask) { std::string LogBuffer::formatStatistics(uid_t uid, unsigned int logMask) { pthread_mutex_lock(&mLogElementsLock); stats.format(strp, uid, logMask); std::string ret = stats.format(uid, logMask); pthread_mutex_unlock(&mLogElementsLock); return ret; }
logd/LogBuffer.h +4 −4 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ #include <sys/types.h> #include <list> #include <string> #include <log/log.h> #include <sysutils/SocketClient.h> Loading Loading @@ -67,15 +68,14 @@ public: int setSize(log_id_t id, unsigned long size); unsigned long getSizeUsed(log_id_t id); // *strp uses malloc, use free to release. void formatStatistics(char **strp, uid_t uid, unsigned int logMask); std::string formatStatistics(uid_t uid, unsigned int logMask); void enableStatistics() { stats.enableStatistics(); } int initPrune(char *cp) { return mPrune.init(cp); } // *strp uses malloc, use free to release. void formatPrune(char **strp) { mPrune.format(strp); } int initPrune(const char *cp) { return mPrune.init(cp); } std::string formatPrune() { return mPrune.format(); } // helper must be protected directly or implicitly by lock()/unlock() char *pidToName(pid_t pid) { return stats.pidToName(pid); } Loading
logd/LogStatistics.cpp +2 −9 Original line number Diff line number Diff line Loading @@ -20,8 +20,6 @@ #include <string.h> #include <unistd.h> #include <string> #include <base/stringprintf.h> #include <log/logger.h> #include <private/android_filesystem_config.h> Loading Loading @@ -206,14 +204,9 @@ static std::string format_line( } } void LogStatistics::format(char **buf, uid_t uid, unsigned int logMask) { std::string LogStatistics::format(uid_t uid, unsigned int logMask) { static const unsigned short spaces_total = 19; if (*buf) { free(*buf); *buf = NULL; } // Report on total logging, current and for all time std::string output = "size/num"; Loading Loading @@ -514,7 +507,7 @@ void LogStatistics::format(char **buf, uid_t uid, unsigned int logMask) { } } *buf = strdup(output.c_str()); return output; } namespace android { Loading
logd/LogStatistics.h +1 −2 Original line number Diff line number Diff line Loading @@ -331,8 +331,7 @@ public: size_t sizesTotal(log_id_t id) const { return mSizesTotal[id]; } size_t elementsTotal(log_id_t id) const { return mElementsTotal[id]; } // *strp = malloc, balance with free void format(char **strp, uid_t uid, unsigned int logMask); std::string format(uid_t uid, unsigned int logMask); // helper (must be locked directly or implicitly by mLogElementsLock) char *pidToName(pid_t pid); Loading