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

Commit c68a9d21 authored by Bookatz's avatar Bookatz
Browse files

Statsd can pull kernel wakelock data

When statsd is told that it is time to poll data, it asks
StatsCompanionService to pull kernel wakelock data, receives the result
(as a string), and outputs it to screen.

Still to do:
1. don't use a string; use a parcel instead
2. don't output it to screen; do something useful instead
3. do more than just kernel wakelocks
4. pull data on demand, in addition to just on periodic pulling

Test: added setPollingAlarms to statsd.main and confirmed that kernel
wakelock information was written to screen
Change-Id: I35f5164420699dea1a00c9e530b938904f1d3055
parent 0121af61
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ 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 \
+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.
 */

#define LOG_TAG "StatsPuller"
#define DEBUG true

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

using namespace android;

namespace android {
namespace os {
namespace statsd {

String16 StatsPuller::pull(int pullCode) {
    if (DEBUG) ALOGD("Initiating pulling %d", pullCode);

    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);
            }
            return returned_value;
        }

        // case OTHER_TYPES: etc.

        default: {
            ALOGE("invalid pull code %d", pullCode);
            return String16("");
        }
    }
}

}  // namespace statsd
}  // namespace os
}  // namespace android
+43 −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_STATSPULLER_H
#define STATSD_STATSPULLER_H

#include <utils/String16.h>

namespace android {
namespace os {
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);
};

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

#endif //STATSD_STATSPULLER_H
+3 −0
Original line number Diff line number Diff line
@@ -177,6 +177,9 @@ Status StatsService::informPollAlarmFired() {

    if (DEBUG) ALOGD("StatsService::informPollAlarmFired succeeded");
    // TODO: determine what services to poll and poll (or ask StatsCompanionService to poll) them.
    String16 output = StatsPuller::pull(StatsPuller::PULL_CODE_KERNEL_WAKELOCKS);
    // TODO: do something useful with the output instead of writing a string to screen.
    ALOGD("%s", String8(output).string());

    return Status::ok();
}
+9 −6
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

#include "AnomalyMonitor.h"
#include "StatsLogProcessor.h"
#include "StatsPuller.h"

#include <android/os/BnStatsManager.h>
#include <android/os/IStatsCompanionService.h>
@@ -67,19 +68,21 @@ public:
    /** Inform statsCompanion that statsd is ready. */
    virtual void sayHiToStatsCompanion();

    // TODO: Move this to a more logical file/class
    // TODO: Should be private. Temporarily public for testing purposes only.
    const sp<AnomalyMonitor> mAnomalyMonitor;

    /** Fetches and returns the StatsCompanionService. */
    static sp<IStatsCompanionService> getStatsCompanionService();

 private:
    sp<StatsLogProcessor> m_processor;  // Reference to the processor for updating configs.

    const sp<AnomalyMonitor> mAnomalyMonitor;  // TODO: Move this to a more logical file/class

    status_t doPrintStatsLog(FILE* out, const Vector<String8>& args);

    void printCmdHelp(FILE* out);

    status_t doLoadConfig(FILE* in);

    /** Fetches the StatsCompanionService. */
    sp<IStatsCompanionService> getStatsCompanionService();
};

// --- StatsdDeathRecipient ---
Loading