Fix print-logs
The VERY_VERBOSE_PRINTING flag guards print-logs functionality but is not present in the prebuilt version of the statsd module. To fix print-logs, we remove the flag (thereby allowing print-logs to work on user, userdebug, and eng builds), but require that the caller have root privileges. Test: adb shell cmd stats print-logs && adb logcat -s statsd:I (only works once root privileges are granted) Bug: 159982879 Change-Id: I2201fc0538876d1d6dfd6ab7abfac43cccc1102f Merged-In: I2201fc0538876d1d6dfd6ab7abfac43cccc1102f
This commit is contained in:
committed by
Jeffrey Huang
parent
c162886a3b
commit
1a6164c94a
@@ -216,10 +216,6 @@ cc_binary {
|
||||
// address: true,
|
||||
//},
|
||||
},
|
||||
debuggable: {
|
||||
// Add a flag to enable stats log printing from statsd on debug builds.
|
||||
cflags: ["-DVERY_VERBOSE_PRINTING"],
|
||||
},
|
||||
},
|
||||
|
||||
proto: {
|
||||
|
||||
@@ -409,11 +409,9 @@ void StatsLogProcessor::OnLogEvent(LogEvent* event, int64_t elapsedRealtimeNs) {
|
||||
onWatchdogRollbackOccurredLocked(event);
|
||||
}
|
||||
|
||||
#ifdef VERY_VERBOSE_PRINTING
|
||||
if (mPrintAllLogs) {
|
||||
ALOGI("%s", event->ToString().c_str());
|
||||
}
|
||||
#endif
|
||||
resetIfConfigTtlExpiredLocked(eventElapsedTimeNs);
|
||||
|
||||
// Hard-coded logic to update the isolated uid's in the uid-map.
|
||||
|
||||
@@ -139,10 +139,8 @@ public:
|
||||
int64_t getLastReportTimeNs(const ConfigKey& key);
|
||||
|
||||
inline void setPrintLogs(bool enabled) {
|
||||
#ifdef VERY_VERBOSE_PRINTING
|
||||
std::lock_guard<std::mutex> lock(mMetricsMutex);
|
||||
mPrintAllLogs = enabled;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Add a specific config key to the possible configs to dump ASAP.
|
||||
@@ -276,9 +274,7 @@ private:
|
||||
//Last time we wrote metadata to disk.
|
||||
int64_t mLastMetadataWriteNs = 0;
|
||||
|
||||
#ifdef VERY_VERBOSE_PRINTING
|
||||
bool mPrintAllLogs = false;
|
||||
#endif
|
||||
|
||||
FRIEND_TEST(StatsLogProcessorTest, TestOutOfOrderLogs);
|
||||
FRIEND_TEST(StatsLogProcessorTest, TestRateLimitByteSize);
|
||||
|
||||
@@ -484,7 +484,8 @@ void StatsService::print_cmd_help(int out) {
|
||||
dprintf(out, " Clear cached puller data.\n");
|
||||
dprintf(out, "\n");
|
||||
dprintf(out, "usage: adb shell cmd stats print-logs\n");
|
||||
dprintf(out, " Only works on eng build\n");
|
||||
dprintf(out, " Requires root privileges.\n");
|
||||
dprintf(out, " Can be disabled by calling adb shell cmd stats print-logs 0\n");
|
||||
}
|
||||
|
||||
status_t StatsService::cmd_trigger_broadcast(int out, Vector<String8>& args) {
|
||||
@@ -865,18 +866,19 @@ status_t StatsService::cmd_clear_puller_cache(int out) {
|
||||
}
|
||||
|
||||
status_t StatsService::cmd_print_logs(int out, const Vector<String8>& args) {
|
||||
VLOG("StatsService::cmd_print_logs with Pid %i, Uid %i", AIBinder_getCallingPid(),
|
||||
AIBinder_getCallingUid());
|
||||
if (checkPermission(kPermissionDump)) {
|
||||
bool enabled = true;
|
||||
if (args.size() >= 2) {
|
||||
enabled = atoi(args[1].c_str()) != 0;
|
||||
}
|
||||
mProcessor->setPrintLogs(enabled);
|
||||
return NO_ERROR;
|
||||
} else {
|
||||
Status status = checkUid(AID_ROOT);
|
||||
if (!status.isOk()) {
|
||||
return PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
VLOG("StatsService::cmd_print_logs with pid %i, uid %i", AIBinder_getCallingPid(),
|
||||
AIBinder_getCallingUid());
|
||||
bool enabled = true;
|
||||
if (args.size() >= 2) {
|
||||
enabled = atoi(args[1].c_str()) != 0;
|
||||
}
|
||||
mProcessor->setPrintLogs(enabled);
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
bool StatsService::getUidFromArgs(const Vector<String8>& args, size_t uidArgIndex, int32_t& uid) {
|
||||
|
||||
Reference in New Issue
Block a user