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

Commit 16e9b10a authored by Chenjie Yu's avatar Chenjie Yu Committed by Android (Google) Code Review
Browse files

Merge "refactor statspuller"

parents a08d7489 1a317bae
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ LOCAL_SRC_FILES := \
    ../../core/java/android/os/IStatsManager.aidl \
    src/StatsService.cpp \
    src/AnomalyMonitor.cpp \
    src/StatsPuller.cpp \
    src/LogEntryPrinter.cpp \
    src/LogReader.cpp \
    src/main.cpp \
@@ -53,6 +52,8 @@ LOCAL_SRC_FILES := \
    src/StatsLogProcessor.cpp \
    src/stats_log.proto \
    src/statsd_config.proto \
    src/StatsPullerManager.cpp \
    src/KernelWakelockPuller.cpp \
    src/DropboxReader.cpp \
    src/matchers/LogEntryMatcherManager.cpp \
    src/metrics/CountMetricProducer.cpp \
+60 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 "KernelWakelockPuller.h"
#include <android/os/IStatsCompanionService.h>
#include <binder/IPCThreadState.h>
#include <cutils/log.h>
#include <private/android_filesystem_config.h>
#include "StatsPuller.h"
#include "StatsService.h"

using namespace android;
using namespace android::base;
using namespace android::binder;
using namespace android::os;
using namespace std;

namespace android {
namespace os {
namespace statsd {

const int KernelWakelockPuller::PULL_CODE_KERNEL_WAKELOCKS = 20;

// The reading and parsing are implemented in Java. It is not difficult to port over. But for now
// let StatsCompanionService handle that and send the data back.
String16 KernelWakelockPuller::pull() {
    sp<IStatsCompanionService> statsCompanion = StatsService::getStatsCompanionService();
    String16 returned_value("");
    if (statsCompanion != NULL) {
      Status status = statsCompanion->pullData(KernelWakelockPuller::PULL_CODE_KERNEL_WAKELOCKS,
                                             &returned_value);
      if (!status.isOk()) {
          ALOGW("error pulling kernel wakelock");
      }
      ALOGD("KernelWakelockPuller::pull succeeded!");
      // TODO: remove this when we integrate into aggregation chain.
      ALOGD("%s", String8(returned_value).string());
      return returned_value;
    } else {
        ALOGW("statsCompanion not found!");
        return String16();
    }
}

}  // namespace statsd
}  // namespace os
}  // namespace android
+39 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */

#ifndef STATSD_KERNELWAKELOCKPULLER_H
#define STATSD_KERNELWAKELOCKPULLER_H

#include <utils/String16.h>
#include "StatsPuller.h"

namespace android {
namespace os {
namespace statsd {

class KernelWakelockPuller : public StatsPuller {
public:
    // a number of stats need to be pulled from StatsCompanionService
    //
    const static int PULL_CODE_KERNEL_WAKELOCKS;
    String16 pull() override;
};

}  // namespace statsd
}  // namespace os
}  // namespace android

#endif  // STATSD_KERNELWAKELOCKPULLER_H
+4 −10
Original line number Diff line number Diff line
@@ -25,15 +25,9 @@ namespace statsd {

class StatsPuller {
public:
    // Enums of pulled data types (pullCodes)
    // These values must be kept in sync with com/android/server/stats/StatsCompanionService.java.
    // TODO: pull the constant from stats_events.proto instead
    const static int PULL_CODE_KERNEL_WAKELOCKS = 20;

    StatsPuller();
    ~StatsPuller();

    static String16 pull(int pullCode);
    virtual ~StatsPuller(){};
    // use string for now, until we figure out how to integrate into the aggregation path
    virtual String16 pull() = 0;
};

}  // namespace statsd
+18 −26
Original line number Diff line number Diff line
@@ -14,13 +14,15 @@
 * limitations under the License.
 */

#define LOG_TAG "StatsPuller"
#define LOG_TAG "StatsPullerManager"
#define DEBUG true

#include "StatsPuller.h"
#include "StatsService.h"
#include "StatsPullerManager.h"
#include <android/os/IStatsCompanionService.h>
#include <cutils/log.h>
#include "StatsService.h"
#include "KernelWakelockPuller.h"


using namespace android;

@@ -28,30 +30,20 @@ namespace android {
namespace os {
namespace statsd {

String16 StatsPuller::pull(int pullCode) {
    if (DEBUG) ALOGD("Initiating pulling %d", pullCode);
const int StatsPullerManager::KERNEL_WAKELOCKS = 1;

    switch (pullCode) {
        // All stats_companion_service cases go here with fallthroughs
        case PULL_CODE_KERNEL_WAKELOCKS: {
            // TODO: Consider caching the statsCompanion service
            sp <IStatsCompanionService>
                    statsCompanion = StatsService::getStatsCompanionService();
            String16 returned_value("");
            Status status = statsCompanion->pullData(pullCode, &returned_value);
            if (DEBUG) ALOGD("Finished pulling the data");
            if (!status.isOk()) {
                ALOGW("error pulling data of type %d", pullCode);
StatsPullerManager::StatsPullerManager() {
    mStatsPullers.insert(
            {static_cast<int>(KERNEL_WAKELOCKS), std::make_unique<KernelWakelockPuller>()});
}
            return returned_value;
        }

        // case OTHER_TYPES: etc.

        default: {
            ALOGE("invalid pull code %d", pullCode);
            return String16("");
        }
String16 StatsPullerManager::pull(int pullCode) {
    if (DEBUG) ALOGD("Initiating pulling %d", pullCode);
    if (mStatsPullers.find(pullCode) != mStatsPullers.end()) {
        return (mStatsPullers.find(pullCode)->second)->pull();
    } else {
        ALOGD("Unknown pull code %d", pullCode);
        return String16();
    }
}

Loading