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

Commit 1481fe14 authored by David Chen's avatar David Chen
Browse files

Changes pulled data to use Parcel objects.

Previously, pulled data was returned as a string. We instead
return the data as an array of StatsLogEventWrapper, which encodes
using the binary-encoded format liblog uses. StatsD uses the same
parsing as for pushed events to convert these. This CL also fixes
the parsing of log_msg since the strings were previously emptied
before we had a chance to read the values.

Note that the cpp-aidl can't support List of Parcelable, so we
have to return the results as an array.

Test: Manual using the new command in StatsService to print results.
Also created a new unit-test by creating a dummy pull code of -1,
but this test is deleted since it required creating a fake output in
StatsCompanionService.

Change-Id: I1cfb9ea081a59292a60e934e8527adc40982ed80
parent 708f1b8c
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -579,6 +579,8 @@ LOCAL_SRC_FILES += \


LOCAL_AIDL_INCLUDES += system/update_engine/binder_bindings
LOCAL_AIDL_INCLUDES += system/update_engine/binder_bindings


LOCAL_AIDL_INCLUDES += core/java/android/os/StatsLogEventWrapper.aidl

LOCAL_AIDL_INCLUDES += frameworks/base/lowpan/java
LOCAL_AIDL_INCLUDES += frameworks/base/lowpan/java
LOCAL_SRC_FILES += \
LOCAL_SRC_FILES += \
	lowpan/java/android/net/lowpan/ILowpanEnergyScanCallback.aidl \
	lowpan/java/android/net/lowpan/ILowpanEnergyScanCallback.aidl \
+4 −3
Original line number Original line Diff line number Diff line
@@ -49,7 +49,8 @@ statsd_common_src := \
    src/stats_util.cpp
    src/stats_util.cpp


statsd_common_c_includes := \
statsd_common_c_includes := \
    $(LOCAL_PATH)/src
    $(LOCAL_PATH)/src \
    $(LOCAL_PATH)/../../libs/services/include


statsd_common_aidl_includes := \
statsd_common_aidl_includes := \
    $(LOCAL_PATH)/../../core/java
    $(LOCAL_PATH)/../../core/java
@@ -95,7 +96,7 @@ else
endif
endif
LOCAL_PROTOC_OPTIMIZE_TYPE := lite-static
LOCAL_PROTOC_OPTIMIZE_TYPE := lite-static


LOCAL_AIDL_INCLUDES := $(statsd_common_c_includes)
LOCAL_AIDL_INCLUDES := $(statsd_common_aidl_includes)
LOCAL_C_INCLUDES += $(statsd_common_c_includes)
LOCAL_C_INCLUDES += $(statsd_common_c_includes)


LOCAL_SHARED_LIBRARIES := $(statsd_common_shared_libraries)
LOCAL_SHARED_LIBRARIES := $(statsd_common_shared_libraries)
@@ -117,7 +118,7 @@ LOCAL_MODULE := statsd_test
LOCAL_COMPATIBILITY_SUITE := device-tests
LOCAL_COMPATIBILITY_SUITE := device-tests
LOCAL_MODULE_TAGS := tests
LOCAL_MODULE_TAGS := tests


LOCAL_AIDL_INCLUDES := $(statsd_common_c_includes)
LOCAL_AIDL_INCLUDES := $(statsd_common_aidl_includes)
LOCAL_C_INCLUDES += $(statsd_common_c_includes)
LOCAL_C_INCLUDES += $(statsd_common_c_includes)


LOCAL_CFLAGS += \
LOCAL_CFLAGS += \
+21 −6
Original line number Original line Diff line number Diff line
@@ -63,9 +63,9 @@ void CompanionDeathRecipient::binderDied(const wp<IBinder>& who) {


// ======================================================================
// ======================================================================
StatsService::StatsService(const sp<Looper>& handlerLooper)
StatsService::StatsService(const sp<Looper>& handlerLooper)
    : mStatsPullerManager(),
    : mAnomalyMonitor(new AnomalyMonitor(2))  // TODO: Put this comment somewhere better
      mAnomalyMonitor(new AnomalyMonitor(2))  // TODO: Put this comment somewhere better
{
{
    mStatsPullerManager = new StatsPullerManager();
    mUidMap = new UidMap();
    mUidMap = new UidMap();
    mConfigManager = new ConfigManager();
    mConfigManager = new ConfigManager();
    mProcessor = new StatsLogProcessor(mUidMap);
    mProcessor = new StatsLogProcessor(mUidMap);
@@ -193,6 +193,10 @@ status_t StatsService::command(FILE* in, FILE* out, FILE* err, Vector<String8>&
        if (!args[0].compare(String8("dump-report"))) {
        if (!args[0].compare(String8("dump-report"))) {
            return cmd_dump_report(out, err, args);
            return cmd_dump_report(out, err, args);
        }
        }

        if (!args[0].compare(String8("pull-source")) && args.size() > 1) {
            return cmd_print_pulled_metrics(out, args);
        }
    }
    }


    print_cmd_help(out);
    print_cmd_help(out);
@@ -210,6 +214,11 @@ void StatsService::print_cmd_help(FILE* out) {
    fprintf(out, "  Prints the UID, app name, version mapping.\n");
    fprintf(out, "  Prints the UID, app name, version mapping.\n");
    fprintf(out, "\n");
    fprintf(out, "\n");
    fprintf(out, "\n");
    fprintf(out, "\n");
    fprintf(out, "usage: adb shell cmds stats pull-source [int] \n");
    fprintf(out, "\n");
    fprintf(out, "  Prints the output of a pulled metrics source (int indicates source)\n");
    fprintf(out, "\n");
    fprintf(out, "\n");
    fprintf(out, "usage: adb shell cmd stats config remove [UID] NAME\n");
    fprintf(out, "usage: adb shell cmd stats config remove [UID] NAME\n");
    fprintf(out, "usage: adb shell cmd stats config update [UID] NAME\n");
    fprintf(out, "usage: adb shell cmd stats config update [UID] NAME\n");
    fprintf(out, "\n");
    fprintf(out, "\n");
@@ -353,6 +362,16 @@ status_t StatsService::cmd_print_uid_map(FILE* out) {
    return NO_ERROR;
    return NO_ERROR;
}
}


status_t StatsService::cmd_print_pulled_metrics(FILE* out, const Vector<String8>& args) {
    int s = atoi(args[1].c_str());
    auto stats = mStatsPullerManager->Pull(s);
    for (const auto& it : stats) {
        fprintf(out, "Pull from %d: %s\n", s, it->ToString().c_str());
    }
    fprintf(out, "Pull from %d: Received %zu elements\n", s, stats.size());
    return NO_ERROR;
}

Status StatsService::informAllUidData(const vector<int32_t>& uid, const vector<int32_t>& version,
Status StatsService::informAllUidData(const vector<int32_t>& uid, const vector<int32_t>& version,
                                      const vector<String16>& app) {
                                      const vector<String16>& app) {
    if (DEBUG) ALOGD("StatsService::informAllUidData was called");
    if (DEBUG) ALOGD("StatsService::informAllUidData was called");
@@ -414,10 +433,6 @@ Status StatsService::informPollAlarmFired() {


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


    return Status::ok();
    return Status::ok();
}
}
+6 −2
Original line number Original line Diff line number Diff line
@@ -120,6 +120,11 @@ private:
     */
     */
    status_t cmd_print_uid_map(FILE* out);
    status_t cmd_print_uid_map(FILE* out);


    /**
     * Print contents of a pulled metrics source.
     */
    status_t cmd_print_pulled_metrics(FILE* out, const Vector<String8>& args);

    /**
    /**
     * Update a configuration.
     * Update a configuration.
     */
     */
@@ -132,9 +137,8 @@ private:


    /**
    /**
     * Fetches external metrics.
     * Fetches external metrics.
     * TODO: This should be an sp<>
     */
     */
    StatsPullerManager mStatsPullerManager;
    sp<StatsPullerManager> mStatsPullerManager;


    /**
    /**
     * Tracks the configurations that have been passed to statsd.
     * Tracks the configurations that have been passed to statsd.
+3 −5
Original line number Original line Diff line number Diff line
@@ -37,9 +37,9 @@ 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
// 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.
// let StatsCompanionService handle that and send the data back.
String16 KernelWakelockPuller::pull() {
vector<StatsLogEventWrapper> KernelWakelockPuller::pull() {
    sp<IStatsCompanionService> statsCompanion = StatsService::getStatsCompanionService();
    sp<IStatsCompanionService> statsCompanion = StatsService::getStatsCompanionService();
    String16 returned_value("");
    vector<StatsLogEventWrapper> returned_value;
    if (statsCompanion != NULL) {
    if (statsCompanion != NULL) {
        Status status = statsCompanion->pullData(KernelWakelockPuller::PULL_CODE_KERNEL_WAKELOCKS,
        Status status = statsCompanion->pullData(KernelWakelockPuller::PULL_CODE_KERNEL_WAKELOCKS,
                                                 &returned_value);
                                                 &returned_value);
@@ -47,12 +47,10 @@ String16 KernelWakelockPuller::pull() {
            ALOGW("error pulling kernel wakelock");
            ALOGW("error pulling kernel wakelock");
        }
        }
        ALOGD("KernelWakelockPuller::pull succeeded!");
        ALOGD("KernelWakelockPuller::pull succeeded!");
        // TODO: remove this when we integrate into aggregation chain.
        ALOGD("%s", String8(returned_value).string());
        return returned_value;
        return returned_value;
    } else {
    } else {
        ALOGW("statsCompanion not found!");
        ALOGW("statsCompanion not found!");
        return String16();
        return returned_value;
    }
    }
}
}


Loading