Loading liblog/log_read.c +8 −0 Original line number Original line Diff line number Diff line Loading @@ -501,6 +501,14 @@ ssize_t android_logger_get_statistics(struct logger_list *logger_list, remaining -= n; remaining -= n; cp += n; cp += n; } } if (logger_list->pid) { n = snprintf(cp, remaining, " pid=%u", logger_list->pid); n = min(n, remaining); remaining -= n; cp += n; } return send_log_msg(NULL, NULL, buf, len); return send_log_msg(NULL, NULL, buf, len); } } Loading logd/CommandListener.cpp +13 −1 Original line number Original line Diff line number Diff line Loading @@ -210,9 +210,20 @@ int CommandListener::GetStatisticsCmd::runCommand(SocketClient *cli, } } unsigned int logMask = -1; unsigned int logMask = -1; pid_t pid = 0; if (argc > 1) { if (argc > 1) { logMask = 0; logMask = 0; for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) { static const char _pid[] = "pid="; if (!strncmp(argv[i], _pid, sizeof(_pid) - 1)) { pid = atol(argv[i] + sizeof(_pid) - 1); if (pid == 0) { cli->sendMsg("PID Error"); return 0; } continue; } int id = atoi(argv[i]); int id = atoi(argv[i]); if ((id < LOG_ID_MIN) || (LOG_ID_MAX <= id)) { if ((id < LOG_ID_MIN) || (LOG_ID_MAX <= id)) { cli->sendMsg("Range Error"); cli->sendMsg("Range Error"); Loading @@ -222,7 +233,8 @@ int CommandListener::GetStatisticsCmd::runCommand(SocketClient *cli, } } } } cli->sendMsg(package_string(mBuf.formatStatistics(uid, logMask)).c_str()); cli->sendMsg(package_string(mBuf.formatStatistics(uid, pid, logMask)).c_str()); return 0; return 0; } } Loading logd/LogBuffer.cpp +5 −3 Original line number Original line Diff line number Diff line Loading @@ -499,7 +499,8 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { size_t second_worst_sizes = 0; size_t second_worst_sizes = 0; if (worstUidEnabledForLogid(id) && mPrune.worstUidEnabled()) { if (worstUidEnabledForLogid(id) && mPrune.worstUidEnabled()) { std::unique_ptr<const UidEntry *[]> sorted = stats.sort(2, id); std::unique_ptr<const UidEntry *[]> sorted = stats.sort( AID_ROOT, (pid_t)0, 2, id); if (sorted.get()) { if (sorted.get()) { if (sorted[0] && sorted[1]) { if (sorted[0] && sorted[1]) { Loading Loading @@ -866,10 +867,11 @@ uint64_t LogBuffer::flushTo( return max; return max; } } std::string LogBuffer::formatStatistics(uid_t uid, unsigned int logMask) { std::string LogBuffer::formatStatistics(uid_t uid, pid_t pid, unsigned int logMask) { pthread_mutex_lock(&mLogElementsLock); pthread_mutex_lock(&mLogElementsLock); std::string ret = stats.format(uid, logMask); std::string ret = stats.format(uid, pid, logMask); pthread_mutex_unlock(&mLogElementsLock); pthread_mutex_unlock(&mLogElementsLock); Loading logd/LogBuffer.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -86,7 +86,7 @@ public: int setSize(log_id_t id, unsigned long size); int setSize(log_id_t id, unsigned long size); unsigned long getSizeUsed(log_id_t id); unsigned long getSizeUsed(log_id_t id); // *strp uses malloc, use free to release. // *strp uses malloc, use free to release. std::string formatStatistics(uid_t uid, unsigned int logMask); std::string formatStatistics(uid_t uid, pid_t pid, unsigned int logMask); void enableStatistics() { void enableStatistics() { stats.enableStatistics(); stats.enableStatistics(); Loading logd/LogStatistics.cpp +29 −14 Original line number Original line Diff line number Diff line Loading @@ -205,7 +205,7 @@ std::string UidEntry::formatHeader(const std::string &name, log_id_t id) const { } } std::string UidEntry::format(const LogStatistics &stat, log_id_t id) const { std::string UidEntry::format(const LogStatistics &stat, log_id_t id) const { uid_t uid = getKey(); uid_t uid = getUid(); std::string name = android::base::StringPrintf("%u", uid); std::string name = android::base::StringPrintf("%u", uid); const char *nameTmp = stat.uidToName(uid); const char *nameTmp = stat.uidToName(uid); if (nameTmp) { if (nameTmp) { Loading Loading @@ -287,8 +287,8 @@ std::string PidEntry::formatHeader(const std::string &name, log_id_t /* id */) c std::string PidEntry::format(const LogStatistics &stat, log_id_t /* id */) const { std::string PidEntry::format(const LogStatistics &stat, log_id_t /* id */) const { uid_t uid = getUid(); uid_t uid = getUid(); std::string name = android::base::StringPrintf("%5u/%u", pid_t pid = getPid(); getKey(), uid); std::string name = android::base::StringPrintf("%5u/%u", pid, uid); const char *nameTmp = getName(); const char *nameTmp = getName(); if (nameTmp) { if (nameTmp) { name += android::base::StringPrintf( name += android::base::StringPrintf( Loading Loading @@ -325,7 +325,7 @@ std::string TidEntry::formatHeader(const std::string &name, log_id_t /* id */) c std::string TidEntry::format(const LogStatistics &stat, log_id_t /* id */) const { std::string TidEntry::format(const LogStatistics &stat, log_id_t /* id */) const { uid_t uid = getUid(); uid_t uid = getUid(); std::string name = android::base::StringPrintf("%5u/%u", std::string name = android::base::StringPrintf("%5u/%u", getKey(), uid); getTid(), uid); const char *nameTmp = getName(); const char *nameTmp = getName(); if (nameTmp) { if (nameTmp) { name += android::base::StringPrintf( name += android::base::StringPrintf( Loading Loading @@ -388,7 +388,8 @@ std::string TagEntry::format(const LogStatistics & /* stat */, log_id_t /* id */ return formatLine(name, size, pruned); return formatLine(name, size, pruned); } } std::string LogStatistics::format(uid_t uid, unsigned int logMask) const { std::string LogStatistics::format(uid_t uid, pid_t pid, unsigned int logMask) const { static const unsigned short spaces_total = 19; static const unsigned short spaces_total = 19; // Report on total logging, current and for all time // Report on total logging, current and for all time Loading Loading @@ -461,24 +462,38 @@ std::string LogStatistics::format(uid_t uid, unsigned int logMask) const { name = (uid == AID_ROOT) name = (uid == AID_ROOT) ? "Chattiest UIDs in %s log buffer:" ? "Chattiest UIDs in %s log buffer:" : "Logging for your UID in %s log buffer:"; : "Logging for your UID in %s log buffer:"; output += uidTable[id].format(*this, uid, name, id); output += uidTable[id].format(*this, uid, pid, name, id); } } if (enable) { if (enable) { name = (uid == AID_ROOT) ? "Chattiest PIDs:" : "Logging for this PID:"; name = ((uid == AID_ROOT) && !pid) output += pidTable.format(*this, uid, name); ? "Chattiest PIDs:" name = "Chattiest TIDs:"; : "Logging for this PID:"; output += tidTable.format(*this, uid, name); output += pidTable.format(*this, uid, pid, name); name = "Chattiest TIDs"; if (pid) { name += android::base::StringPrintf(" for PID %d", pid); } name += ":"; output += tidTable.format(*this, uid, pid, name); } } if (enable && (logMask & (1 << LOG_ID_EVENTS))) { if (enable && (logMask & (1 << LOG_ID_EVENTS))) { name = "Chattiest events log buffer TAGs:"; name = "Chattiest events log buffer TAGs"; output += tagTable.format(*this, uid, name, LOG_ID_EVENTS); if (pid) { name += android::base::StringPrintf(" for PID %d", pid); } name += ":"; output += tagTable.format(*this, uid, pid, name, LOG_ID_EVENTS); } } if (enable && (logMask & (1 << LOG_ID_SECURITY))) { if (enable && (logMask & (1 << LOG_ID_SECURITY))) { name = "Chattiest security log buffer TAGs:"; name = "Chattiest security log buffer TAGs"; output += securityTagTable.format(*this, uid, name, LOG_ID_SECURITY); if (pid) { name += android::base::StringPrintf(" for PID %d", pid); } name += ":"; output += securityTagTable.format(*this, uid, pid, name, LOG_ID_SECURITY); } } return output; return output; Loading Loading
liblog/log_read.c +8 −0 Original line number Original line Diff line number Diff line Loading @@ -501,6 +501,14 @@ ssize_t android_logger_get_statistics(struct logger_list *logger_list, remaining -= n; remaining -= n; cp += n; cp += n; } } if (logger_list->pid) { n = snprintf(cp, remaining, " pid=%u", logger_list->pid); n = min(n, remaining); remaining -= n; cp += n; } return send_log_msg(NULL, NULL, buf, len); return send_log_msg(NULL, NULL, buf, len); } } Loading
logd/CommandListener.cpp +13 −1 Original line number Original line Diff line number Diff line Loading @@ -210,9 +210,20 @@ int CommandListener::GetStatisticsCmd::runCommand(SocketClient *cli, } } unsigned int logMask = -1; unsigned int logMask = -1; pid_t pid = 0; if (argc > 1) { if (argc > 1) { logMask = 0; logMask = 0; for (int i = 1; i < argc; ++i) { for (int i = 1; i < argc; ++i) { static const char _pid[] = "pid="; if (!strncmp(argv[i], _pid, sizeof(_pid) - 1)) { pid = atol(argv[i] + sizeof(_pid) - 1); if (pid == 0) { cli->sendMsg("PID Error"); return 0; } continue; } int id = atoi(argv[i]); int id = atoi(argv[i]); if ((id < LOG_ID_MIN) || (LOG_ID_MAX <= id)) { if ((id < LOG_ID_MIN) || (LOG_ID_MAX <= id)) { cli->sendMsg("Range Error"); cli->sendMsg("Range Error"); Loading @@ -222,7 +233,8 @@ int CommandListener::GetStatisticsCmd::runCommand(SocketClient *cli, } } } } cli->sendMsg(package_string(mBuf.formatStatistics(uid, logMask)).c_str()); cli->sendMsg(package_string(mBuf.formatStatistics(uid, pid, logMask)).c_str()); return 0; return 0; } } Loading
logd/LogBuffer.cpp +5 −3 Original line number Original line Diff line number Diff line Loading @@ -499,7 +499,8 @@ bool LogBuffer::prune(log_id_t id, unsigned long pruneRows, uid_t caller_uid) { size_t second_worst_sizes = 0; size_t second_worst_sizes = 0; if (worstUidEnabledForLogid(id) && mPrune.worstUidEnabled()) { if (worstUidEnabledForLogid(id) && mPrune.worstUidEnabled()) { std::unique_ptr<const UidEntry *[]> sorted = stats.sort(2, id); std::unique_ptr<const UidEntry *[]> sorted = stats.sort( AID_ROOT, (pid_t)0, 2, id); if (sorted.get()) { if (sorted.get()) { if (sorted[0] && sorted[1]) { if (sorted[0] && sorted[1]) { Loading Loading @@ -866,10 +867,11 @@ uint64_t LogBuffer::flushTo( return max; return max; } } std::string LogBuffer::formatStatistics(uid_t uid, unsigned int logMask) { std::string LogBuffer::formatStatistics(uid_t uid, pid_t pid, unsigned int logMask) { pthread_mutex_lock(&mLogElementsLock); pthread_mutex_lock(&mLogElementsLock); std::string ret = stats.format(uid, logMask); std::string ret = stats.format(uid, pid, logMask); pthread_mutex_unlock(&mLogElementsLock); pthread_mutex_unlock(&mLogElementsLock); Loading
logd/LogBuffer.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -86,7 +86,7 @@ public: int setSize(log_id_t id, unsigned long size); int setSize(log_id_t id, unsigned long size); unsigned long getSizeUsed(log_id_t id); unsigned long getSizeUsed(log_id_t id); // *strp uses malloc, use free to release. // *strp uses malloc, use free to release. std::string formatStatistics(uid_t uid, unsigned int logMask); std::string formatStatistics(uid_t uid, pid_t pid, unsigned int logMask); void enableStatistics() { void enableStatistics() { stats.enableStatistics(); stats.enableStatistics(); Loading
logd/LogStatistics.cpp +29 −14 Original line number Original line Diff line number Diff line Loading @@ -205,7 +205,7 @@ std::string UidEntry::formatHeader(const std::string &name, log_id_t id) const { } } std::string UidEntry::format(const LogStatistics &stat, log_id_t id) const { std::string UidEntry::format(const LogStatistics &stat, log_id_t id) const { uid_t uid = getKey(); uid_t uid = getUid(); std::string name = android::base::StringPrintf("%u", uid); std::string name = android::base::StringPrintf("%u", uid); const char *nameTmp = stat.uidToName(uid); const char *nameTmp = stat.uidToName(uid); if (nameTmp) { if (nameTmp) { Loading Loading @@ -287,8 +287,8 @@ std::string PidEntry::formatHeader(const std::string &name, log_id_t /* id */) c std::string PidEntry::format(const LogStatistics &stat, log_id_t /* id */) const { std::string PidEntry::format(const LogStatistics &stat, log_id_t /* id */) const { uid_t uid = getUid(); uid_t uid = getUid(); std::string name = android::base::StringPrintf("%5u/%u", pid_t pid = getPid(); getKey(), uid); std::string name = android::base::StringPrintf("%5u/%u", pid, uid); const char *nameTmp = getName(); const char *nameTmp = getName(); if (nameTmp) { if (nameTmp) { name += android::base::StringPrintf( name += android::base::StringPrintf( Loading Loading @@ -325,7 +325,7 @@ std::string TidEntry::formatHeader(const std::string &name, log_id_t /* id */) c std::string TidEntry::format(const LogStatistics &stat, log_id_t /* id */) const { std::string TidEntry::format(const LogStatistics &stat, log_id_t /* id */) const { uid_t uid = getUid(); uid_t uid = getUid(); std::string name = android::base::StringPrintf("%5u/%u", std::string name = android::base::StringPrintf("%5u/%u", getKey(), uid); getTid(), uid); const char *nameTmp = getName(); const char *nameTmp = getName(); if (nameTmp) { if (nameTmp) { name += android::base::StringPrintf( name += android::base::StringPrintf( Loading Loading @@ -388,7 +388,8 @@ std::string TagEntry::format(const LogStatistics & /* stat */, log_id_t /* id */ return formatLine(name, size, pruned); return formatLine(name, size, pruned); } } std::string LogStatistics::format(uid_t uid, unsigned int logMask) const { std::string LogStatistics::format(uid_t uid, pid_t pid, unsigned int logMask) const { static const unsigned short spaces_total = 19; static const unsigned short spaces_total = 19; // Report on total logging, current and for all time // Report on total logging, current and for all time Loading Loading @@ -461,24 +462,38 @@ std::string LogStatistics::format(uid_t uid, unsigned int logMask) const { name = (uid == AID_ROOT) name = (uid == AID_ROOT) ? "Chattiest UIDs in %s log buffer:" ? "Chattiest UIDs in %s log buffer:" : "Logging for your UID in %s log buffer:"; : "Logging for your UID in %s log buffer:"; output += uidTable[id].format(*this, uid, name, id); output += uidTable[id].format(*this, uid, pid, name, id); } } if (enable) { if (enable) { name = (uid == AID_ROOT) ? "Chattiest PIDs:" : "Logging for this PID:"; name = ((uid == AID_ROOT) && !pid) output += pidTable.format(*this, uid, name); ? "Chattiest PIDs:" name = "Chattiest TIDs:"; : "Logging for this PID:"; output += tidTable.format(*this, uid, name); output += pidTable.format(*this, uid, pid, name); name = "Chattiest TIDs"; if (pid) { name += android::base::StringPrintf(" for PID %d", pid); } name += ":"; output += tidTable.format(*this, uid, pid, name); } } if (enable && (logMask & (1 << LOG_ID_EVENTS))) { if (enable && (logMask & (1 << LOG_ID_EVENTS))) { name = "Chattiest events log buffer TAGs:"; name = "Chattiest events log buffer TAGs"; output += tagTable.format(*this, uid, name, LOG_ID_EVENTS); if (pid) { name += android::base::StringPrintf(" for PID %d", pid); } name += ":"; output += tagTable.format(*this, uid, pid, name, LOG_ID_EVENTS); } } if (enable && (logMask & (1 << LOG_ID_SECURITY))) { if (enable && (logMask & (1 << LOG_ID_SECURITY))) { name = "Chattiest security log buffer TAGs:"; name = "Chattiest security log buffer TAGs"; output += securityTagTable.format(*this, uid, name, LOG_ID_SECURITY); if (pid) { name += android::base::StringPrintf(" for PID %d", pid); } name += ":"; output += securityTagTable.format(*this, uid, pid, name, LOG_ID_SECURITY); } } return output; return output; Loading