Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e5755008 authored by Lalit Maganti's avatar Lalit Maganti
Browse files

statsd: add subscription id to Perfetto command line and fix printf bug

This CL adds the id of the subscription triggering Perfetto to the
command line invocation of Perfetto. This is useful to allow for
distinguishing between experiments in post-processing (since the same
alert can be attached to multiple subscriptions).

This also fixes a bug in the same place where the last character of ids
could be cut off if any of the ids are large negative numbers i.e. the
smallest possible int64 is 20 chars long (including the minus sign).
However there were only 19 available digits in the string buffers which
these ids were printed into (the 20th would be the null terminator).
Increase the buffer size by 5 characters to allow for some headroom just
incase we need some in the future.

Bug: 122822046
Change-Id: I9c3ac8cb8b203fd464eee2c72b1228f1a50448b1
parent d50bda40
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ void triggerSubscribers(const int64_t rule_id,
                break;
            case Subscription::SubscriberInformationCase::kPerfettoDetails:
                if (!CollectPerfettoTraceAndUploadToDropbox(subscription.perfetto_details(),
                                                            rule_id, configKey)) {
                                                            subscription.id(), rule_id, configKey)) {
                    ALOGW("Failed to generate perfetto traces.");
                }
                break;
+7 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ namespace os {
namespace statsd {

bool CollectPerfettoTraceAndUploadToDropbox(const PerfettoDetails& config,
                                            int64_t subscription_id,
                                            int64_t alert_id,
                                            const ConfigKey& configKey) {
    VLOG("Starting trace collection through perfetto");
@@ -48,9 +49,11 @@ bool CollectPerfettoTraceAndUploadToDropbox(const PerfettoDetails& config,
        return false;
    }

    char alertId[20];
    char configId[20];
    char configUid[20];
    char subscriptionId[25];
    char alertId[25];
    char configId[25];
    char configUid[25];
    snprintf(subscriptionId, sizeof(subscriptionId), "%" PRId64, subscription_id);
    snprintf(alertId, sizeof(alertId), "%" PRId64, alert_id);
    snprintf(configId, sizeof(configId), "%" PRId64, configKey.GetId());
    snprintf(configUid, sizeof(configUid), "%d", configKey.GetUid());
@@ -94,7 +97,7 @@ bool CollectPerfettoTraceAndUploadToDropbox(const PerfettoDetails& config,

        execl("/system/bin/perfetto", "perfetto", "--background", "--config", "-", "--dropbox",
              kDropboxTag, "--alert-id", alertId, "--config-id", configId, "--config-uid",
              configUid, nullptr);
              configUid, "--subscription-id", subscriptionId, nullptr);

        // execl() doesn't return in case of success, if we get here something
        // failed.
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ class PerfettoDetails; // Declared in statsd_config.pb.h
// This method returns immediately after passing the config and does NOT wait
// for the full duration of the trace.
bool CollectPerfettoTraceAndUploadToDropbox(const PerfettoDetails& config,
                                            int64_t subscription_id,
                                            int64_t alert_id,
                                            const ConfigKey& configKey);