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

Commit 172562dc authored by Ruchir Rastogi's avatar Ruchir Rastogi Committed by Android (Google) Code Review
Browse files

Merge "Do not truncate AStatsEvent buffers" into rvc-dev

parents c39f708c f2a5ed08
Loading
Loading
Loading
Loading
+1 −20
Original line number Diff line number Diff line
@@ -89,25 +89,6 @@ cc_library_headers {
    min_sdk_version: "29",
}

cc_benchmark {
    name: "libstatssocket_benchmark",
    srcs: [
        "benchmark/main.cpp",
        "benchmark/stats_event_benchmark.cpp",
    ],
    cflags: [
        "-Wall",
        "-Werror",
    ],
    static_libs: [
        "libstatssocket_private",
    ],
    shared_libs: [
        "libcutils",
        "libgtest_prod",
    ],
}

cc_test {
    name: "libstatssocket_test",
    srcs: [
@@ -128,7 +109,7 @@ cc_test {
    ],
    test_suites: ["device-tests", "mts"],
    test_config: "libstatssocket_test.xml",
    //TODO(b/153588990): Remove when the build system properly separates 
    //TODO(b/153588990): Remove when the build system properly separates.
    //32bit and 64bit architectures.
    compile_multilib: "both",
    multilib: {
+0 −19
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.
 */

#include <benchmark/benchmark.h>

BENCHMARK_MAIN();
+0 −54
Original line number Diff line number Diff line
/*
 * Copyright (C) 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.
 */

#include "benchmark/benchmark.h"
#include "stats_event.h"

static AStatsEvent* constructStatsEvent() {
    AStatsEvent* event = AStatsEvent_obtain();
    AStatsEvent_setAtomId(event, 100);

    // randomly sample atom size
    int numElements = rand() % 800;
    for (int i = 0; i < numElements; i++) {
        AStatsEvent_writeInt32(event, i);
    }

    return event;
}

static void BM_stats_event_truncate_buffer(benchmark::State& state) {
    while (state.KeepRunning()) {
        AStatsEvent* event = constructStatsEvent();
        AStatsEvent_build(event);
        AStatsEvent_write(event);
        AStatsEvent_release(event);
    }
}

BENCHMARK(BM_stats_event_truncate_buffer);

static void BM_stats_event_full_buffer(benchmark::State& state) {
    while (state.KeepRunning()) {
        AStatsEvent* event = constructStatsEvent();
        AStatsEvent_truncateBuffer(event, false);
        AStatsEvent_build(event);
        AStatsEvent_write(event);
        AStatsEvent_release(event);
    }
}

BENCHMARK(BM_stats_event_full_buffer);
+0 −3
Original line number Diff line number Diff line
@@ -157,9 +157,6 @@ uint32_t AStatsEvent_getAtomId(AStatsEvent* event);
uint8_t* AStatsEvent_getBuffer(AStatsEvent* event, size_t* size);
uint32_t AStatsEvent_getErrors(AStatsEvent* event);

// exposed for benchmarking only
void AStatsEvent_truncateBuffer(struct AStatsEvent* event, bool truncate);

#ifdef __cplusplus
}
#endif  // __CPLUSPLUS
+0 −13
Original line number Diff line number Diff line
@@ -76,7 +76,6 @@ struct AStatsEvent {
    uint32_t numElements;
    uint32_t atomId;
    uint32_t errors;
    bool truncate;
    bool built;
    size_t bufSize;
};
@@ -95,7 +94,6 @@ AStatsEvent* AStatsEvent_obtain() {
    event->numElements = 0;
    event->atomId = 0;
    event->errors = 0;
    event->truncate = true;  // truncate for both pulled and pushed atoms
    event->built = false;
    event->bufSize = MAX_PUSH_EVENT_PAYLOAD;
    event->buf = (uint8_t*)calloc(event->bufSize, 1);
@@ -318,10 +316,6 @@ uint32_t AStatsEvent_getErrors(AStatsEvent* event) {
    return event->errors;
}

void AStatsEvent_truncateBuffer(AStatsEvent* event, bool truncate) {
    event->truncate = truncate;
}

static void build_internal(AStatsEvent* event, const bool push) {
    if (event->numElements > MAX_BYTE_VALUE) event->errors |= ERROR_TOO_MANY_FIELDS;
    if (0 == event->atomId) event->errors |= ERROR_NO_ATOM_ID;
@@ -341,13 +335,6 @@ static void build_internal(AStatsEvent* event, const bool push) {
    }

    event->buf[POS_NUM_ELEMENTS] = event->numElements;

    // Truncate the buffer to the appropriate length in order to limit our
    // memory usage.
    if (event->truncate) {
        event->buf = (uint8_t*)realloc(event->buf, event->numBytesWritten);
        event->bufSize = event->numBytesWritten;
    }
}

void AStatsEvent_build(AStatsEvent* event) {
Loading