Loading libutils/Android.bp +0 −6 Original line number Diff line number Diff line Loading @@ -274,12 +274,6 @@ cc_fuzz { ], } cc_fuzz { name: "libutils_fuzz_stopwatch", defaults: ["libutils_fuzz_defaults"], srcs: ["StopWatch_fuzz.cpp"], } cc_fuzz { name: "libutils_fuzz_refbase", defaults: ["libutils_fuzz_defaults"], Loading libutils/StopWatch.cpp +6 −38 Original line number Diff line number Diff line Loading @@ -26,58 +26,26 @@ #include <utils/Log.h> /*****************************************************************************/ namespace android { StopWatch::StopWatch(const char* name, int clock) : mName(name), mClock(clock) { reset(); } StopWatch::~StopWatch() { 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)); } StopWatch::~StopWatch() { ALOGD("StopWatch %s (us): %" PRId64 " ", name(), ns2us(elapsedTime())); } const char* StopWatch::name() const { const char* StopWatch::name() const { return mName; } nsecs_t StopWatch::lap() { 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 { nsecs_t StopWatch::elapsedTime() const { return systemTime(mClock) - mStartTime; } void StopWatch::reset() { mNumLaps = 0; void StopWatch::reset() { mStartTime = systemTime(mClock); } /*****************************************************************************/ }; // namespace android } // namespace android libutils/StopWatch_fuzz.cppdeleted 100644 → 0 +0 −45 Original line number 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; } libutils/include/utils/StopWatch.h +16 −32 Original line number Diff line number Diff line Loading @@ -14,26 +14,21 @@ * limitations under the License. */ #ifndef ANDROID_STOPWATCH_H #define ANDROID_STOPWATCH_H #pragma once #include <stdint.h> #include <sys/types.h> #include <utils/Timers.h> // --------------------------------------------------------------------------- namespace android { class StopWatch { class StopWatch { public: StopWatch(const char* name, int clock = SYSTEM_TIME_MONOTONIC); ~StopWatch(); const char* name() const; nsecs_t lap(); nsecs_t elapsedTime() const; void reset(); Loading @@ -42,18 +37,7 @@ private: const char* mName; int mClock; struct lap_t { nsecs_t soFar; nsecs_t thisLap; }; nsecs_t mStartTime; lap_t mLaps[8]; int mNumLaps; }; } // namespace android // --------------------------------------------------------------------------- #endif // ANDROID_STOPWATCH_H Loading
libutils/Android.bp +0 −6 Original line number Diff line number Diff line Loading @@ -274,12 +274,6 @@ cc_fuzz { ], } cc_fuzz { name: "libutils_fuzz_stopwatch", defaults: ["libutils_fuzz_defaults"], srcs: ["StopWatch_fuzz.cpp"], } cc_fuzz { name: "libutils_fuzz_refbase", defaults: ["libutils_fuzz_defaults"], Loading
libutils/StopWatch.cpp +6 −38 Original line number Diff line number Diff line Loading @@ -26,58 +26,26 @@ #include <utils/Log.h> /*****************************************************************************/ namespace android { StopWatch::StopWatch(const char* name, int clock) : mName(name), mClock(clock) { reset(); } StopWatch::~StopWatch() { 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)); } StopWatch::~StopWatch() { ALOGD("StopWatch %s (us): %" PRId64 " ", name(), ns2us(elapsedTime())); } const char* StopWatch::name() const { const char* StopWatch::name() const { return mName; } nsecs_t StopWatch::lap() { 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 { nsecs_t StopWatch::elapsedTime() const { return systemTime(mClock) - mStartTime; } void StopWatch::reset() { mNumLaps = 0; void StopWatch::reset() { mStartTime = systemTime(mClock); } /*****************************************************************************/ }; // namespace android } // namespace android
libutils/StopWatch_fuzz.cppdeleted 100644 → 0 +0 −45 Original line number 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; }
libutils/include/utils/StopWatch.h +16 −32 Original line number Diff line number Diff line Loading @@ -14,26 +14,21 @@ * limitations under the License. */ #ifndef ANDROID_STOPWATCH_H #define ANDROID_STOPWATCH_H #pragma once #include <stdint.h> #include <sys/types.h> #include <utils/Timers.h> // --------------------------------------------------------------------------- namespace android { class StopWatch { class StopWatch { public: StopWatch(const char* name, int clock = SYSTEM_TIME_MONOTONIC); ~StopWatch(); const char* name() const; nsecs_t lap(); nsecs_t elapsedTime() const; void reset(); Loading @@ -42,18 +37,7 @@ private: const char* mName; int mClock; struct lap_t { nsecs_t soFar; nsecs_t thisLap; }; nsecs_t mStartTime; lap_t mLaps[8]; int mNumLaps; }; } // namespace android // --------------------------------------------------------------------------- #endif // ANDROID_STOPWATCH_H