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 EFFECTIVE_H 17 #define EFFECTIVE_H 18 19 #include "sp_profiler.h" 20 #include <string> 21 #include <thread> 22 #include <climits> 23 namespace OHOS { 24 namespace SmartPerf { 25 class Effective : public SpProfiler { 26 public: GetInstance()27 static Effective &GetInstance() 28 { 29 static Effective instance; 30 return instance; 31 } 32 std::map<std::string, std::string> ItemData() override; 33 int fps_ {0}; 34 long long frameTime_ {LLONG_MAX}; 35 36 private: 37 bool CheckCounterId(); 38 std::thread ThreadGetHiperf(long long timeStamp); 39 void GetHiperf(const std::string &traceName); 40 std::string SetHiperf(const std::string &traceName); 41 42 int64_t startCaptuerTime_ {0}; 43 int requestId_ {1}; 44 std::string strOne_ = R"(hiprofiler_cmd \ 45 -c - \ 46 -o /data/local/tmp/)"; 47 std::string strTwo_ = R"(.htrace \ 48 -t 5 \ 49 -s \ 50 -k \ 51 <<CONFIG)"; 52 53 std::string strThree_ = R"(request_id: )"; 54 std::string strFour_ = R"( session_config { 55 buffers { 56 pages: 16384 57 })"; 58 std::string strFive_ = R"( result_file: "/data/local/tmp/)"; 59 std::string strSix_ = R"(.htrace" 60 sample_duration: 5000 61 })"; 62 std::string strNine_ = R"( plugin_configs { 63 plugin_name: "ftrace-plugin" 64 sample_interval: 1000 65 config_data { 66 ftrace_events: "sched/sched_switch" 67 ftrace_events: "power/suspend_resume" 68 ftrace_events: "sched/sched_wakeup" 69 ftrace_events: "sched/sched_wakeup_new" 70 ftrace_events: "sched/sched_waking" 71 ftrace_events: "sched/sched_process_exit" 72 ftrace_events: "sched/sched_process_free" 73 ftrace_events: "task/task_newtask" 74 ftrace_events: "task/task_rename" 75 ftrace_events: "power/cpu_frequency" 76 ftrace_events: "power/cpu_idle" 77 hitrace_categories: "ace" 78 hitrace_categories: "app" 79 hitrace_categories: "ark" 80 hitrace_categories: "graphic" 81 hitrace_categories: "ohos" 82 hitrace_categories: "bin)"; 83 std::string strEleven_ = R"(der" 84 hitrace_categories: "irq" 85 hitrace_categories: "pagecache" 86 hitrace_categories: "zaudio" 87 buffer_size_kb: 20480 88 flush_interval_ms: 1000 89 flush_threshold_kb: 4096 90 parse_ksyms: true 91 clock: "boot" 92 trace_period_ms: 200 93 debug_on: false 94 hitrace_time: 5 95 } 96 })"; 97 std::string strSeven_ = R"( plugin_configs { 98 plugin_name: "hiperf-plugin" 99 sample_interval: 5000 100 config_data { 101 is_root: false 102 outfile_name: "/data/local/tmp/)"; 103 std::string strEight_ = R"(.data" 104 record_args: "-f 1000 -a --cpu-limit 100 -e " SPUtils::GetProductName() "-cpu-cycles,sched:sched_waking )"; 105 std::string strTen_ = R"(--call-stack dwarf --clockid monotonic --offcpu -m 256" 106 } 107 })"; 108 std::string conFig_ = R"(CONFIG)"; 109 }; 110 } 111 } 112 #endif