1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PERF_TEST_H 17 #define PERF_TEST_H 18 19 #include "frontend_api_handler.h" 20 #include "perf_test_strategy.h" 21 #include "duration_collection.h" 22 23 namespace OHOS::perftest { 24 using namespace std; 25 26 class PerfTestCallback { 27 public: 28 PerfTestCallback() = default; 29 virtual ~PerfTestCallback() = default; OnCall(const std::string && codeRef,const int32_t timeout,ApiCallErr & error)30 virtual void OnCall(const std::string&& codeRef, const int32_t timeout, ApiCallErr &error) {}; OnDestroy(const list<std::string> codeRefs,ApiCallErr & error)31 virtual void OnDestroy(const list<std::string> codeRefs, ApiCallErr &error) {}; 32 }; 33 34 class PerfTest : public BackendClass { 35 public: PerfTest(unique_ptr<PerfTestStrategy> perfTestStrategy,unique_ptr<PerfTestCallback> perfTestCallback)36 explicit PerfTest(unique_ptr<PerfTestStrategy> perfTestStrategy, unique_ptr<PerfTestCallback> perfTestCallback) 37 : perfTestStrategy_(move(perfTestStrategy)), perfTestCallback_(move(perfTestCallback)) {}; ~PerfTest()38 ~PerfTest() override {}; 39 GetFrontendClassDef()40 const FrontEndClassDef &GetFrontendClassDef() const override 41 { 42 return PERF_TEST_DEF; 43 } 44 45 int32_t GetPidByBundleName(string bundleName); 46 void RunTest(ApiCallErr &error); 47 nlohmann::json GetMeasureResult(PerfMetric perfMetric, ApiCallErr &error); 48 bool IsMeasureRunning(); 49 void Destroy(ApiCallErr &error); 50 private: 51 unique_ptr<PerfTestStrategy> perfTestStrategy_; 52 unique_ptr<PerfTestCallback> perfTestCallback_; 53 map<PerfMetric, list<double>> measureResult_; 54 bool isMeasureComplete_ = false; 55 bool isMeasureRunning_ = false; 56 }; 57 } // namespace OHOS::perftest 58 59 #endif