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

Commit 4e0524bf authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Iebe457a5,If32da8e6

* changes:
  Statsd: Add perfprofd call
  Statsd: Add perfprofd_config proto
parents f90662fe 48f98323
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ statsd_common_src := \
    src/config/ConfigListener.cpp \
    src/config/ConfigManager.cpp \
    src/external/Perfetto.cpp \
    src/external/Perfprofd.cpp \
    src/external/StatsPuller.cpp \
    src/external/StatsCompanionServicePuller.cpp \
    src/external/SubsystemSleepStatePuller.cpp \
@@ -70,6 +71,11 @@ statsd_common_src := \
    src/guardrail/StatsdStats.cpp \
    src/socket/StatsSocketListener.cpp

# TODO: Once statsd is using a blueprint file, migrate to the proper filegroups.
statsd_common_src += \
    ../../../../system/extras/perfprofd/binder_interface/aidl/android/os/IPerfProfd.aidl \
    src/perfprofd/perfprofd_config.proto

statsd_common_c_includes := \
    $(LOCAL_PATH)/src \
    $(LOCAL_PATH)/../../libs/services/include
@@ -251,6 +257,7 @@ LOCAL_SRC_FILES := \
    src/stats_log.proto \
    src/statsd_config.proto \
    src/perfetto/perfetto_config.proto \
    src/perfprofd/perfprofd_config.proto \
    src/atoms.proto

LOCAL_PROTOC_OPTIMIZE_TYPE := lite
+7 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
#include <binder/IServiceManager.h>

#include "external/Perfetto.h"
#include "external/Perfprofd.h"
#include "frameworks/base/libs/incident/proto/android/os/header.pb.h"
#include "subscriber/IncidentdReporter.h"
#include "subscriber/SubscriberReporter.h"
@@ -64,6 +65,12 @@ void triggerSubscribers(const int64_t rule_id,
                SubscriberReporter::getInstance().alertBroadcastSubscriber(configKey, subscription,
                                                                           dimensionKey);
                break;
            case Subscription::SubscriberInformationCase::kPerfprofdDetails:
                if (!CollectPerfprofdTraceAndUploadToDropbox(subscription.perfprofd_details(),
                                                             rule_id, configKey)) {
                    ALOGW("Failed to generate perfprofd traces.");
                }
                break;
            default:
                break;
        }
+83 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "Perfprofd.h"

#define DEBUG false  // STOPSHIP if true
#include "config/ConfigKey.h"
#include "Log.h"

#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#include <string>

#include <binder/IServiceManager.h>

#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"  // Alert

#include "android/os/IPerfProfd.h"

namespace android {
namespace os {
namespace statsd {

bool CollectPerfprofdTraceAndUploadToDropbox(const PerfprofdDetails& config,
                                             int64_t alert_id,
                                             const ConfigKey& configKey) {
    VLOG("Starting trace collection through perfprofd");

    if (!config.has_perfprofd_config()) {
      ALOGE("The perfprofd trace config is empty, aborting");
      return false;
    }

    sp<IPerfProfd> service = interface_cast<IPerfProfd>(
        defaultServiceManager()->getService(android::String16("perfprofd")));
    if (service == NULL) {
      ALOGE("Could not find perfprofd service");
      return false;
    }

    // Add protobufs can't be described in AIDL, we need to re-serialize
    // the config proto to send it.
    std::vector<uint8_t> proto_serialized;
    {
      const auto& config_proto = config.perfprofd_config();
      int size = config_proto.ByteSize();
      proto_serialized.resize(size);
      ::google::protobuf::uint8* target_ptr =
          reinterpret_cast<::google::protobuf::uint8*>(proto_serialized.data());
      config_proto.SerializeWithCachedSizesToArray(target_ptr);
    }

    // TODO: alert-id etc?

    binder::Status status = service->startProfilingProtobuf(proto_serialized);
    if (status.isOk()) {
      return true;
    }

    ALOGE("Error starting perfprofd profiling: %s", status.toString8().c_str());
    return false;
}

}  // namespace statsd
}  // namespace os
}  // namespace android
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <inttypes.h>

namespace android {
namespace os {
namespace statsd {

class ConfigKey;
class PerfprofdDetails;  // Declared in statsd_config.pb.h

// Starts the collection of a Perfprofd trace with the given |config|.
// The trace is uploaded to Dropbox by the perfprofd service once done.
// This method returns immediately after passing the config and does NOT wait
// for the full duration of the trace.
bool CollectPerfprofdTraceAndUploadToDropbox(const PerfprofdDetails& config,
                                             int64_t alert_id,
                                             const ConfigKey& configKey);

}  // namespace statsd
}  // namespace os
}  // namespace android
+1 −0
Original line number Diff line number Diff line
../../../../../../system/extras/perfprofd/binder_interface/perfprofd_config.proto
 No newline at end of file
Loading