From afa6e9fc04469544b6466e76b909316754e4ec0a Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 11 May 2021 12:29:27 -0700 Subject: [PATCH] libutils: remove the unused StopWatch lap functionality. It's not tested, and it's not used. Also remove the fuzzer which is just wasting CPU cycles. This gets us to 100% function coverage, 100% line coverage, and N/A branch coverage for StopWatch. Test: treehugger Change-Id: Ib5e08510ef1046a6f2af3f0b8a1c317a8bb39fd4 --- libutils/Android.bp | 6 ---- libutils/StopWatch.cpp | 44 ++++------------------------- libutils/StopWatch_fuzz.cpp | 45 ------------------------------ libutils/include/utils/StopWatch.h | 42 +++++++++------------------- 4 files changed, 19 insertions(+), 118 deletions(-) delete mode 100644 libutils/StopWatch_fuzz.cpp diff --git a/libutils/Android.bp b/libutils/Android.bp index 63955677d..13e4c02de 100644 --- a/libutils/Android.bp +++ b/libutils/Android.bp @@ -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"], diff --git a/libutils/StopWatch.cpp b/libutils/StopWatch.cpp index d01865e9c..28e2d76bc 100644 --- a/libutils/StopWatch.cpp +++ b/libutils/StopWatch.cpp @@ -26,58 +26,26 @@ #include -/*****************************************************************************/ - 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= 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 diff --git a/libutils/StopWatch_fuzz.cpp b/libutils/StopWatch_fuzz.cpp deleted file mode 100644 index 63d8a28c9..000000000 --- a/libutils/StopWatch_fuzz.cpp +++ /dev/null @@ -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> 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(); - android::StopWatch stopWatch = android::StopWatch(nameStr.c_str(), clockVal); - std::vector opsToRun = dataProvider.ConsumeRemainingBytes(); - int opsRun = 0; - for (auto it : opsToRun) { - if (opsRun++ >= MAX_OPERATIONS) { - break; - } - it = it % operations.size(); - operations[it](stopWatch); - } - return 0; -} diff --git a/libutils/include/utils/StopWatch.h b/libutils/include/utils/StopWatch.h index 9b14ac809..4e53edaab 100644 --- a/libutils/include/utils/StopWatch.h +++ b/libutils/include/utils/StopWatch.h @@ -14,46 +14,30 @@ * limitations under the License. */ -#ifndef ANDROID_STOPWATCH_H -#define ANDROID_STOPWATCH_H +#pragma once #include #include #include -// --------------------------------------------------------------------------- - namespace android { -class StopWatch -{ -public: - StopWatch(const char* name, int clock = SYSTEM_TIME_MONOTONIC); - ~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; + const char* name() const; + nsecs_t elapsedTime() const; - void reset(); + void reset(); -private: - const char* mName; - int mClock; - - struct lap_t { - nsecs_t soFar; - nsecs_t thisLap; - }; - - nsecs_t mStartTime; - lap_t mLaps[8]; - int mNumLaps; + private: + const char* mName; + int mClock; + + nsecs_t mStartTime; }; } // namespace android - -// --------------------------------------------------------------------------- - -#endif // ANDROID_STOPWATCH_H