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

Commit 15fb09d1 authored by Mark Tabry's avatar Mark Tabry Committed by Android (Google) Code Review
Browse files

Merge changes from topic "VmsWestworld"

* changes:
  Add AIDL interface and puller implementation for automotive devices.
  Define new atoms for Vehicle Maps Service.
parents 993e82ee 9dc13578
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ cc_defaults {

    srcs: [
        ":statsd_aidl",
        ":ICarStatsService.aidl",
        "src/active_config_list.proto",
        "src/anomaly/AlarmMonitor.cpp",
        "src/anomaly/AlarmTracker.cpp",
@@ -64,6 +65,7 @@ cc_defaults {
        "src/config/ConfigKey.cpp",
        "src/config/ConfigListener.cpp",
        "src/config/ConfigManager.cpp",
        "src/external/CarStatsPuller.cpp",
        "src/external/GpuStatsPuller.cpp",
        "src/external/Perfetto.cpp",
        "src/external/PowerStatsPuller.cpp",
+58 −0
Original line number Diff line number Diff line
@@ -339,6 +339,7 @@ message Atom {
            228 [(allow_from_any_uid) = true];
        PerfettoUploaded perfetto_uploaded =
            229 [(log_from_module) = "perfetto"];
        VmsClientConnectionStateChanged vms_client_connection_state_changed = 230;
    }

    // Pulled events will start at field 10000.
@@ -408,6 +409,7 @@ message Atom {
        SurfaceflingerStatsGlobalInfo surfaceflinger_stats_global_info = 10062;
        SurfaceflingerStatsLayerInfo surfaceflinger_stats_layer_info = 10063;
        ProcessMemorySnapshot process_memory_snapshot = 10064;
        VmsClientStats vms_client_stats = 10065;
    }

    // DO NOT USE field numbers above 100,000 in AOSP.
@@ -3732,6 +3734,33 @@ message RoleRequestResultReported {
    optional Result result = 9;
}

/**
 * Logs when a Vehicle Maps Service client's connection state has changed
 *
 * Logged from:
 *   packages/services/Car/service/src/com/android/car/stats/VmsClientLog.java
 */
message VmsClientConnectionStateChanged {
    // The UID of the VMS client app
    optional int32 uid = 1 [(is_uid) = true];

    enum State {
        UNKNOWN = 0;
        // Attempting to connect to the client
        CONNECTING = 1;
        // Client connection established
        CONNECTED = 2;
        // Client connection closed unexpectedly
        DISCONNECTED = 3;
        // Client connection closed by VMS
        TERMINATED = 4;
        // Error establishing the client connection
        CONNECTION_ERROR = 5;
    }

    optional State state  = 2;
}

//////////////////////////////////////////////////////////////////////
// Pulled atoms below this line //
//////////////////////////////////////////////////////////////////////
@@ -7275,3 +7304,32 @@ message PerfettoUploaded {
    optional int64 trace_uuid_lsb = 2;
    optional int64 trace_uuid_msb = 3;
}

/**
 * Pulls client metrics on data transferred via Vehicle Maps Service.
 * Metrics are keyed by uid + layer.
 *
 * Pulled from:
 *   packages/services/Car/service/src/com/android/car/stats/CarStatsService.java
 */
message VmsClientStats {
    // UID of the VMS client app
    optional int32 uid = 1 [(is_uid) = true];

    // VMS layer definition
    optional int32 layer_type = 2;
    optional int32 layer_channel = 3;
    optional int32 layer_version = 4;

    // Bytes and packets sent by the client for the layer
    optional int64 tx_bytes = 5;
    optional int64 tx_packets = 6;

    // Bytes and packets received by the client for the layer
    optional int64 rx_bytes = 7;
    optional int64 rx_packets = 8;

    // Bytes and packets dropped due to client error
    optional int64 dropped_bytes = 9;
    optional int64 dropped_packets = 10;
}
+96 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 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.
 */

#define DEBUG false
#include "Log.h"

#include <binder/IServiceManager.h>
#include <com/android/internal/car/ICarStatsService.h>

#include "CarStatsPuller.h"
#include "logd/LogEvent.h"
#include "stats_log_util.h"

using android::binder::Status;
using com::android::internal::car::ICarStatsService;

namespace android {
namespace os {
namespace statsd {

static std::mutex gCarStatsMutex;
static sp<ICarStatsService> gCarStats = nullptr;

class CarStatsDeathRecipient : public android::IBinder::DeathRecipient {
 public:
     CarStatsDeathRecipient() = default;
     ~CarStatsDeathRecipient() override = default;

  // android::IBinder::DeathRecipient override:
  void binderDied(const android::wp<android::IBinder>& /* who */) override {
      ALOGE("Car service has died");
      std::lock_guard<std::mutex> lock(gCarStatsMutex);
      if (gCarStats) {
          sp<IBinder> binder = IInterface::asBinder(gCarStats);
          binder->unlinkToDeath(this);
          gCarStats = nullptr;
      }
  }
};

static sp<CarStatsDeathRecipient> gDeathRecipient = new CarStatsDeathRecipient();

static sp<ICarStatsService> getCarService() {
    std::lock_guard<std::mutex> lock(gCarStatsMutex);
    if (!gCarStats) {
        const sp<IBinder> binder = defaultServiceManager()->checkService(String16("car_stats"));
        if (!binder) {
            ALOGW("Car service is unavailable");
            return nullptr;
        }
        gCarStats = interface_cast<ICarStatsService>(binder);
        binder->linkToDeath(gDeathRecipient);
    }
    return gCarStats;
}

CarStatsPuller::CarStatsPuller(const int tagId) : StatsPuller(tagId) {
}

bool CarStatsPuller::PullInternal(std::vector<std::shared_ptr<LogEvent>>* data) {
    const sp<ICarStatsService> carService = getCarService();
    if (!carService) {
        return false;
    }

    vector<StatsLogEventWrapper> returned_value;
    Status status = carService->pullData(mTagId, &returned_value);
    if (!status.isOk()) {
        ALOGW("CarStatsPuller::pull failed for %d", mTagId);
        return false;
    }

    data->clear();
    for (const StatsLogEventWrapper& it : returned_value) {
        LogEvent::createLogEvents(it, *data);
    }
    VLOG("CarStatsPuller::pull succeeded for %d", mTagId);
    return true;
}

}  // namespace statsd
}  // namespace os
}  // namespace android
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 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 "StatsPuller.h"

namespace android {
namespace os {
namespace statsd {

/**
 * Pull atoms from CarService.
 */
class CarStatsPuller : public StatsPuller {
public:
    explicit CarStatsPuller(const int tagId);
    bool PullInternal(std::vector<std::shared_ptr<LogEvent>>* data) override;
};

}  // namespace statsd
}  // namespace os
}  // namespace android
+5 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
#include "../logd/LogEvent.h"
#include "../stats_log_util.h"
#include "../statscompanion_util.h"
#include "CarStatsPuller.h"
#include "GpuStatsPuller.h"
#include "PowerStatsPuller.h"
#include "ResourceHealthManagerPuller.h"
@@ -272,6 +273,10 @@ std::map<int, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = {
        {android::util::SURFACEFLINGER_STATS_GLOBAL_INFO,
         {.puller =
                  new SurfaceflingerStatsPuller(android::util::SURFACEFLINGER_STATS_GLOBAL_INFO)}},
        // VmsClientStats
        {android::util::VMS_CLIENT_STATS,
         {.additiveFields = {5, 6, 7, 8, 9, 10},
          .puller = new CarStatsPuller(android::util::VMS_CLIENT_STATS)}},
};

StatsPullerManager::StatsPullerManager() : mNextPullTimeNs(NO_ALARM_UPDATE) {
Loading