Merge "Adds new API to retrieve statsd metadata."

This commit is contained in:
TreeHugger Robot
2017-12-04 20:27:15 +00:00
committed by Android (Google) Code Review
5 changed files with 51 additions and 3 deletions

View File

@@ -4332,6 +4332,7 @@ package android.util {
public final class StatsManager {
method public boolean addConfiguration(java.lang.String, byte[], java.lang.String, java.lang.String);
method public byte[] getData(java.lang.String);
method public byte[] getMetadata();
method public boolean removeConfiguration(java.lang.String);
}

View File

@@ -715,6 +715,18 @@ Status StatsService::getData(const String16& key, vector<uint8_t>* output) {
}
}
Status StatsService::getMetadata(vector<uint8_t>* output) {
IPCThreadState* ipc = IPCThreadState::self();
VLOG("StatsService::getMetadata with Pid %i, Uid %i", ipc->getCallingPid(),
ipc->getCallingUid());
if (checkCallingPermission(String16(kPermissionDump))) {
StatsdStats::getInstance().dumpStats(output, false); // Don't reset the counters.
return Status::ok();
} else {
return Status::fromExceptionCode(binder::Status::EX_SECURITY);
}
}
Status StatsService::addConfiguration(const String16& key,
const vector <uint8_t>& config,
const String16& package, const String16& cls,

View File

@@ -75,6 +75,11 @@ public:
*/
virtual Status getData(const String16& key, vector<uint8_t>* output) override;
/**
* Binder call for clients to get metadata across all configs in statsd.
*/
virtual Status getMetadata(vector<uint8_t>* output) override;
/**
* Binder call to let clients send a configuration and indicate they're interested when they
* should requestData for this configuration.

View File

@@ -69,10 +69,15 @@ interface IStatsManager {
/**
* Fetches data for the specified configuration key. Returns a byte array representing proto
* wire-encoded of ConfigMetricsReport.
* wire-encoded of ConfigMetricsReportList.
*/
byte[] getData(in String key);
/**
* Fetches metadata across statsd. Returns byte array representing wire-encoded proto.
*/
byte[] getMetadata();
/**
* Sets a configuration with the specified config key and subscribes to updates for this
* configuration key. Broadcasts will be sent if this configuration needs to be collected.

View File

@@ -93,10 +93,11 @@ public final class StatsManager {
}
/**
* Clients can request data with a binder call.
* Clients can request data with a binder call. This getter is destructive and also clears
* the retrieved metrics from statsd memory.
*
* @param configKey Configuration key to retrieve data from.
* @return Serialized ConfigMetricsReport proto. Returns null on failure.
* @return Serialized ConfigMetricsReportList proto. Returns null on failure.
*/
@RequiresPermission(Manifest.permission.DUMP)
public byte[] getData(String configKey) {
@@ -115,6 +116,30 @@ public final class StatsManager {
}
}
/**
* Clients can request metadata for statsd. Will contain stats across all configurations but not
* the actual metrics themselves (metrics must be collected via {@link #getData(String)}.
* This getter is not destructive and will not reset any metrics/counters.
*
* @return Serialized StatsdStatsReport proto. Returns null on failure.
*/
@RequiresPermission(Manifest.permission.DUMP)
public byte[] getMetadata() {
synchronized (this) {
try {
IStatsManager service = getIStatsManagerLocked();
if (service == null) {
Slog.d(TAG, "Failed to find statsd when getting metadata");
return null;
}
return service.getMetadata();
} catch (RemoteException e) {
Slog.d(TAG, "Failed to connecto statsd when getting metadata");
return null;
}
}
}
private class StatsdDeathRecipient implements IBinder.DeathRecipient {
@Override
public void binderDied() {