diff options
| -rw-r--r-- | cmds/statsd/src/anomaly/subscriber_util.cpp | 5 | ||||
| -rw-r--r-- | cmds/statsd/src/external/Perfetto.cpp | 16 | ||||
| -rw-r--r-- | cmds/statsd/src/external/Perfetto.h | 5 |
3 files changed, 21 insertions, 5 deletions
diff --git a/cmds/statsd/src/anomaly/subscriber_util.cpp b/cmds/statsd/src/anomaly/subscriber_util.cpp index e796d19efd93..3f69a2c392bf 100644 --- a/cmds/statsd/src/anomaly/subscriber_util.cpp +++ b/cmds/statsd/src/anomaly/subscriber_util.cpp @@ -55,8 +55,9 @@ void triggerSubscribers(const int64_t rule_id, } break; case Subscription::SubscriberInformationCase::kPerfettoDetails: - if (!CollectPerfettoTraceAndUploadToDropbox(subscription.perfetto_details())) { - ALOGW("Failed to generate prefetto traces."); + if (!CollectPerfettoTraceAndUploadToDropbox(subscription.perfetto_details(), + rule_id, configKey)) { + ALOGW("Failed to generate perfetto traces."); } break; case Subscription::SubscriberInformationCase::kBroadcastSubscriberDetails: diff --git a/cmds/statsd/src/external/Perfetto.cpp b/cmds/statsd/src/external/Perfetto.cpp index b09d373a5f3b..05544837b752 100644 --- a/cmds/statsd/src/external/Perfetto.cpp +++ b/cmds/statsd/src/external/Perfetto.cpp @@ -15,6 +15,7 @@ */ #define DEBUG false // STOPSHIP if true +#include "config/ConfigKey.h" #include "Log.h" #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h" // Alert @@ -22,6 +23,7 @@ #include <android-base/unique_fd.h> #include <errno.h> #include <fcntl.h> +#include <inttypes.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> @@ -36,7 +38,9 @@ namespace android { namespace os { namespace statsd { -bool CollectPerfettoTraceAndUploadToDropbox(const PerfettoDetails& config) { +bool CollectPerfettoTraceAndUploadToDropbox(const PerfettoDetails& config, + int64_t alert_id, + const ConfigKey& configKey) { VLOG("Starting trace collection through perfetto"); if (!config.has_trace_config()) { @@ -44,6 +48,13 @@ bool CollectPerfettoTraceAndUploadToDropbox(const PerfettoDetails& config) { return false; } + char alertId[20]; + char configId[20]; + char configUid[20]; + snprintf(alertId, sizeof(alertId), "%" PRId64, alert_id); + snprintf(configId, sizeof(configId), "%" PRId64, configKey.GetId()); + snprintf(configUid, sizeof(configUid), "%d", configKey.GetUid()); + android::base::unique_fd readPipe; android::base::unique_fd writePipe; if (!android::base::Pipe(&readPipe, &writePipe)) { @@ -82,7 +93,8 @@ bool CollectPerfettoTraceAndUploadToDropbox(const PerfettoDetails& config) { } execl("/system/bin/perfetto", "perfetto", "--background", "--config", "-", "--dropbox", - kDropboxTag, nullptr); + kDropboxTag, "--alert-id", alertId, "--config-id", configId, "--config-uid", + configUid, nullptr); // execl() doesn't return in case of success, if we get here something // failed. diff --git a/cmds/statsd/src/external/Perfetto.h b/cmds/statsd/src/external/Perfetto.h index 2a5679cc79fd..1e7f728e1357 100644 --- a/cmds/statsd/src/external/Perfetto.h +++ b/cmds/statsd/src/external/Perfetto.h @@ -24,13 +24,16 @@ namespace android { namespace os { namespace statsd { +class ConfigKey; class PerfettoDetails; // Declared in statsd_config.pb.h // Starts the collection of a Perfetto trace with the given |config|. // The trace is uploaded to Dropbox by the perfetto cmdline util once done. // This method returns immediately after passing the config and does NOT wait // for the full duration of the trace. -bool CollectPerfettoTraceAndUploadToDropbox(const PerfettoDetails& config); +bool CollectPerfettoTraceAndUploadToDropbox(const PerfettoDetails& config, + int64_t alert_id, + const ConfigKey& configKey); } // namespace statsd } // namespace os |