• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_STRATEGY_H
17 #define PERF_TEST_STRATEGY_H
18 
19 #include "frontend_api_handler.h"
20 #include "data_collection.h"
21 #include "duration_collection.h"
22 #include "cpu_collection.h"
23 #include "memory_collection.h"
24 #include "app_start_time_collection.h"
25 #include "page_switch_time_collection.h"
26 #include "list_swipe_fps_collection.h"
27 
28 namespace OHOS::perftest {
29     using namespace std;
30 
31     static const map<PerfMetric, function<shared_ptr<DataCollection>(PerfMetric)>> g_dataCollectionMap = {
32         {DURATION, [](PerfMetric metric) { return make_shared<DurationCollection>(metric); }},
33         {CPU_LOAD, [](PerfMetric metric) { return make_shared<CpuCollection>(metric); }},
34         {CPU_USAGE, [](PerfMetric metric) { return make_shared<CpuCollection>(metric); }},
35         {MEMORY_RSS, [](PerfMetric metric) { return make_shared<MemoryCollection>(metric); }},
36         {MEMORY_PSS, [](PerfMetric metric) { return make_shared<MemoryCollection>(metric); }},
37         {APP_START_RESPONSE_TIME, [](PerfMetric metric) { return make_shared<AppStartTimeCollection>(metric); }},
38         {APP_START_COMPLETE_TIME, [](PerfMetric metric) { return make_shared<AppStartTimeCollection>(metric); }},
39         {PAGE_SWITCH_COMPLETE_TIME, [](PerfMetric metric) { return make_shared<PageSwitchTimeCollection>(metric); }},
40         {LIST_SWIPE_FPS, [](PerfMetric metric) { return make_shared<ListSwipeFpsCollection>(metric); }},
41     };
42 
43     class PerfTestStrategy {
44     public:
45         explicit PerfTestStrategy(set<PerfMetric> metrics, string actionCodeRef, string resetCodeRef,
46                                   string bundleName, int32_t iterations, int32_t timeout, ApiCallErr &error);
~PerfTestStrategy()47         ~PerfTestStrategy() {};
48         set<PerfMetric> GetPerfMetrics();
49         string GetActionCodeRef();
50         string GetResetCodeRef();
51         string GetBundleName();
52         int32_t GetIterations();
53         int32_t GetTimeout();
54         map<PerfMetric, shared_ptr<DataCollection>> GetDataCollections();
55         void GetBundleNameByPid(ApiCallErr &error);
56         void CreateDataCollections();
57 
58     private:
59         set<PerfMetric> perfMetrics_;
60         map<PerfMetric, shared_ptr<DataCollection>> dataCollections_;
61         string actionCodeRef_;
62         string resetCodeRef_;
63         string bundleName_;
64         int32_t iterations_;
65         int32_t timeout_;
66     };
67 } // namespace OHOS::perftest
68 
69 #endif