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

Commit 70673be9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "libutils: remove the unused StopWatch lap functionality." am:...

Merge "libutils: remove the unused StopWatch lap functionality." am: 0839837f am: 5c28af98 am: 038077c1

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1703652

Change-Id: If73e10e9321af420ff32b992a6df4f8dd9e5a911
parents dc334a7c 038077c1
Loading
Loading
Loading
Loading
+0 −6
Original line number Original line Diff line number Diff line
@@ -274,12 +274,6 @@ cc_fuzz {
    ],
    ],
}
}


cc_fuzz {
    name: "libutils_fuzz_stopwatch",
    defaults: ["libutils_fuzz_defaults"],
    srcs: ["StopWatch_fuzz.cpp"],
}

cc_fuzz {
cc_fuzz {
    name: "libutils_fuzz_refbase",
    name: "libutils_fuzz_refbase",
    defaults: ["libutils_fuzz_defaults"],
    defaults: ["libutils_fuzz_defaults"],
+6 −38
Original line number Original line Diff line number Diff line
@@ -26,58 +26,26 @@


#include <utils/Log.h>
#include <utils/Log.h>


/*****************************************************************************/

namespace android {
namespace android {


StopWatch::StopWatch(const char* name, int clock) : mName(name), mClock(clock) {
StopWatch::StopWatch(const char* name, int clock) : mName(name), mClock(clock) {
    reset();
    reset();
}
}


StopWatch::~StopWatch()
StopWatch::~StopWatch() {
{
    ALOGD("StopWatch %s (us): %" PRId64 " ", name(), ns2us(elapsedTime()));
    nsecs_t elapsed = elapsedTime();
    const int n = mNumLaps;
    ALOGD("StopWatch %s (us): %" PRId64 " ", mName, ns2us(elapsed));
    for (int i=0 ; i<n ; i++) {
        const nsecs_t soFar = mLaps[i].soFar;
        const nsecs_t thisLap = mLaps[i].thisLap;
        ALOGD(" [%d: %" PRId64 ", %" PRId64, i, ns2us(soFar), ns2us(thisLap));
    }
}
}


const char* StopWatch::name() const
const char* StopWatch::name() const {
{
    return mName;
    return mName;
}
}


nsecs_t StopWatch::lap()
nsecs_t StopWatch::elapsedTime() const {
{
    nsecs_t elapsed = elapsedTime();
    if (mNumLaps >= 8) {
        elapsed = 0;
    } else {
        const int n = mNumLaps;
        mLaps[n].soFar   = elapsed;
        mLaps[n].thisLap = n ? (elapsed - mLaps[n-1].soFar) : elapsed;
        mNumLaps = n+1;
    }
    return elapsed;
}

nsecs_t StopWatch::elapsedTime() const
{
    return systemTime(mClock) - mStartTime;
    return systemTime(mClock) - mStartTime;
}
}


void StopWatch::reset()
void StopWatch::reset() {
{
    mNumLaps = 0;
    mStartTime = systemTime(mClock);
    mStartTime = systemTime(mClock);
}
}



}  // namespace android
/*****************************************************************************/

}; // namespace android

libutils/StopWatch_fuzz.cpp

deleted100644 → 0
+0 −45
Original line number Original line Diff line number Diff line
/*
 * Copyright 2020 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 "fuzzer/FuzzedDataProvider.h"
#include "utils/StopWatch.h"

static constexpr int MAX_OPERATIONS = 100;
static constexpr int MAX_NAME_LEN = 2048;

static const std::vector<std::function<void(android::StopWatch)>> operations = {
        [](android::StopWatch stopWatch) -> void { stopWatch.reset(); },
        [](android::StopWatch stopWatch) -> void { stopWatch.lap(); },
        [](android::StopWatch stopWatch) -> void { stopWatch.elapsedTime(); },
        [](android::StopWatch stopWatch) -> void { stopWatch.name(); },
};

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
    FuzzedDataProvider dataProvider(data, size);
    std::string nameStr = dataProvider.ConsumeRandomLengthString(MAX_NAME_LEN);
    int clockVal = dataProvider.ConsumeIntegral<int>();
    android::StopWatch stopWatch = android::StopWatch(nameStr.c_str(), clockVal);
    std::vector<uint8_t> opsToRun = dataProvider.ConsumeRemainingBytes<uint8_t>();
    int opsRun = 0;
    for (auto it : opsToRun) {
        if (opsRun++ >= MAX_OPERATIONS) {
            break;
        }
        it = it % operations.size();
        operations[it](stopWatch);
    }
    return 0;
}
+16 −32
Original line number Original line Diff line number Diff line
@@ -14,26 +14,21 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#ifndef ANDROID_STOPWATCH_H
#pragma once
#define ANDROID_STOPWATCH_H


#include <stdint.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/types.h>


#include <utils/Timers.h>
#include <utils/Timers.h>


// ---------------------------------------------------------------------------

namespace android {
namespace android {


class StopWatch
class StopWatch {
{
  public:
  public:
    StopWatch(const char* name, int clock = SYSTEM_TIME_MONOTONIC);
    StopWatch(const char* name, int clock = SYSTEM_TIME_MONOTONIC);
    ~StopWatch();
    ~StopWatch();


    const char* name() const;
    const char* name() const;
  nsecs_t lap();
    nsecs_t elapsedTime() const;
    nsecs_t elapsedTime() const;


    void reset();
    void reset();
@@ -42,18 +37,7 @@ private:
    const char* mName;
    const char* mName;
    int mClock;
    int mClock;


    struct lap_t {
        nsecs_t     soFar;
        nsecs_t     thisLap;
    };
    
    nsecs_t mStartTime;
    nsecs_t mStartTime;
    lap_t           mLaps[8];
    int             mNumLaps;
};
};


}  // namespace android
}  // namespace android

// ---------------------------------------------------------------------------

#endif // ANDROID_STOPWATCH_H