Merge "libutils: remove the unused StopWatch lap functionality."
This commit is contained in:
commit
0839837fa4
4 changed files with 19 additions and 118 deletions
|
|
@ -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"],
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
/*
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
|
|
@ -14,46 +14,30 @@
|
||||||
* 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();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char* mName;
|
const char* mName;
|
||||||
int mClock;
|
int mClock;
|
||||||
|
|
||||||
struct lap_t {
|
nsecs_t mStartTime;
|
||||||
nsecs_t soFar;
|
|
||||||
nsecs_t thisLap;
|
|
||||||
};
|
|
||||||
|
|
||||||
nsecs_t mStartTime;
|
|
||||||
lap_t mLaps[8];
|
|
||||||
int mNumLaps;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#endif // ANDROID_STOPWATCH_H
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue