From 3c5ebd991b8fecfb43e2930ae43efbf95f8c6762 Mon Sep 17 00:00:00 2001 From: zhang-cui11 Date: Wed, 14 Sep 2022 14:57:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0/data/local/tmp/hiperf?= =?UTF-8?q?=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhang-cui11 --- BUILD.gn | 7 ++++++ bundle.json | 3 ++- include/debug_logger.h | 4 ++-- include/subcommand_record.h | 6 ++--- .../innerkits/native/include/hiperf_client.h | 2 +- script/hiperf_utils.py | 22 +++++++++---------- script/recv_binary_cache.py | 8 +++---- src/subcommand_record.cpp | 4 ++-- src/virtual_runtime.cpp | 2 +- .../common/native/hiperf_client_test.cpp | 4 ++-- .../common/native/hiperf_libreport_test.cpp | 2 +- .../common/native/include/callstack_test.h | 14 ++++++------ .../common/native/subcommand_record_test.cpp | 2 +- 13 files changed, 44 insertions(+), 36 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 6ccb95b..0ebb347 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -368,6 +368,13 @@ ohos_executable("hiperf_host") { part_name = "hiperf" } +ohos_prebuilt_etc("hiperf.cfg") { + source = "./config/hiperf.cfg" + relative_install_dir = "init" + subsystem_name = "developtools" + part_name = "hiperf" +} + ohos_source_set("hiperf_platform_host") { part_name = "hiperf" sources = [ "./src/hiperf_libreport.cpp" ] diff --git a/bundle.json b/bundle.json index 375e5eb..e99309f 100644 --- a/bundle.json +++ b/bundle.json @@ -30,7 +30,8 @@ "build": { "sub_component": [ "//developtools/hiperf:hiperf_target", - "//developtools/hiperf:hiperf_target_all" + "//developtools/hiperf:hiperf_target_all", + "//developtools/hiperf:hiperf.cfg" ], "inner_kits": [ { diff --git a/include/debug_logger.h b/include/debug_logger.h index b10c355..44ec165 100644 --- a/include/debug_logger.h +++ b/include/debug_logger.h @@ -56,8 +56,8 @@ enum DebugLevel { #ifdef HIPERF_DEBUG #if is_ohos || is_double_framework -const std::string DEFAULT_UT_LOG_DIR = "/data/local/tmp/"; -const std::string DEFAULT_LOG_PATH = "/data/local/tmp/hiperf_log.txt"; +const std::string DEFAULT_UT_LOG_DIR = "/data/local/tmp/hiperf"; +const std::string DEFAULT_LOG_PATH = "/data/local/tmp/hiperf/hiperf_log.txt"; #elif is_mingw const std::string DEFAULT_LOG_PATH = ".\\hiperf_log.txt"; #elif is_linux diff --git a/include/subcommand_record.h b/include/subcommand_record.h index 82d5eb8..44dbdbd 100644 --- a/include/subcommand_record.h +++ b/include/subcommand_record.h @@ -57,7 +57,7 @@ public: "Usage: hiperf record [options] [command [command-args]]\n" " Collect performance sampling information of running [command].\n" " The default options are: -c --cpu-limit 25 -d 10000.0 -e hw-cpu-cycles\n" - " -f 4000 -m 1024 -o /data/local/tmp/perf.data.\n" + " -f 4000 -m 1024 -o /data/local/tmp/hiperf/perf.data.\n" " -a\n" " Collect system-wide information.\n" " for measures all processes/threads\n" @@ -140,7 +140,7 @@ public: " --data-limit \n" " Stop recording after SIZE bytes of records. Default is unlimited.\n" " -o \n" - " Set output file name, default is /data/local/tmp/perf.data.\n" + " Set output file name, default is /data/local/tmp/hiperf/perf.data.\n" " -z\n" " Compress record data.\n" " --verbose\n" @@ -182,7 +182,7 @@ private: int cpuPercent_ = DEFAULT_CPU_PERCENT; int mmapPages_ = MAX_PERF_MMAP_PAGE; std::vector symbolDir_ = {}; - std::string outputFilename_ = "/data/local/tmp/perf.data"; + std::string outputFilename_ = "/data/local/tmp/hiperf/perf.data"; std::string appPackage_ = {}; std::string clockId_ = {}; std::string strLimit_ = {}; diff --git a/interfaces/innerkits/native/include/hiperf_client.h b/interfaces/innerkits/native/include/hiperf_client.h index 52158a9..a879263 100644 --- a/interfaces/innerkits/native/include/hiperf_client.h +++ b/interfaces/innerkits/native/include/hiperf_client.h @@ -25,7 +25,7 @@ namespace HiPerf { namespace HiperfClient { static const std::string HiperfCommandName = "hiperf"; static const std::string SystemBinPath = "/system/bin/"; -static const std::string TempBinPath = "/data/local/tmp/"; +static const std::string TempBinPath = "/data/local/tmp/hiperf/"; static const std::string CurrentPath = "./"; static const std::string PerfDataName = "perf.data"; diff --git a/script/hiperf_utils.py b/script/hiperf_utils.py index ed624f1..bd7b4ea 100644 --- a/script/hiperf_utils.py +++ b/script/hiperf_utils.py @@ -25,7 +25,7 @@ from ctypes import cdll IS_DEBUG = False HDC_NAME = "hdc_std" -SYMBOL_FILES_DIR = '/data/local/tmp/local_libs/' +SYMBOL_FILES_DIR = '/data/local/tmp/hiperf/local_libs/' BUILD_ID_FILE = "build_id_list" EXPECTED_TOOLS = { HDC_NAME: { @@ -396,8 +396,8 @@ class PerformanceProfile: def download_hiperf(self): hiperf_binary = get_hiperf_binary_path(self.device_arch, 'hiperf') - self.hdc.check_run(['file send', hiperf_binary, '/data/local/tmp']) - self.hdc.check_run(['shell', 'chmod', 'a+x', '/data/local/tmp/hiperf']) + self.hdc.check_run(['file send', hiperf_binary, '/data/local/tmp/hiperf']) + self.hdc.check_run(['shell', 'chmod', 'a+x', '/data/local/tmp/hiperf/hiperf']) def download_libs(self): executor = LocalLibDownload(self.device_arch, self.hdc) @@ -471,12 +471,12 @@ class PerformanceProfile: record_options = self.args.record_options.split(' ') record_options = [cmd.replace("'", "") for cmd in record_options] if self.is_control: - args = ['/data/local/tmp/hiperf', 'record', + args = ['/data/local/tmp/hiperf/hiperf', 'record', '--control', self.control_mode, '-o', - '/data/local/tmp/perf.data'] + record_options + '/data/local/tmp/hiperf/perf.data'] + record_options else: - args = ['/data/local/tmp/hiperf', 'record', '-o', - '/data/local/tmp/perf.data'] + record_options + args = ['/data/local/tmp/hiperf/hiperf', 'record', '-o', + '/data/local/tmp/hiperf/hiperf/perf.data'] + record_options if self.args.local_lib_dir and self.hdc.run_hdc_cmd( ['shell', 'ls', SYMBOL_FILES_DIR]): args += ['--symbol-dir', SYMBOL_FILES_DIR] @@ -521,14 +521,14 @@ class PerformanceProfile: def get_profiling_data(self): current_path = os.getcwd() full_path = os.path.join(current_path, self.args.output_perf_data) - self.hdc.check_run(['file recv', '/data/local/tmp/perf.data', + self.hdc.check_run(['file recv', '/data/local/tmp/hiperf/perf.data', full_path]) self.hdc.run_hdc_cmd(['shell', 'rm', - '/data/local/tmp/perf.data']) + '/data/local/tmp/hiperf/perf.data']) def exec_control(self): hdc_args = [self.hdc.hdc_path, 'shell', - '/data/local/tmp/hiperf', 'record', + '/data/local/tmp/hiperf/hiperf', 'record', '--control', self.control_mode] print('run hdc cmd: %s' % hdc_args) self.record_subproc = subprocess.Popen(hdc_args) @@ -537,7 +537,7 @@ class PerformanceProfile: last_size = 0 while True: (result, out) = self.hdc.run_hdc_cmd( - ['shell', 'du', 'data/local/tmp/perf.data']) + ['shell', 'du', 'data/local/tmp/hiperf/perf.data']) if "du" not in out: current_size = out.split(" ")[0] if current_size == last_size: diff --git a/script/recv_binary_cache.py b/script/recv_binary_cache.py index b187663..5aa1b38 100644 --- a/script/recv_binary_cache.py +++ b/script/recv_binary_cache.py @@ -164,15 +164,15 @@ class GetLibFiles(object): if self.hdc.run_hdc_cmd(['file recv', device_path, host_path]): return True # In non-root device, we can't pull /data/app/XXX/base.odex directly. - # Instead, we can first copy the file to /data/local/tmp, then pull it. + # Instead, we can first copy the file to /data/local/tmp/hiperf, then pull it. filename = device_path[device_path.rfind('/') + 1:] if (self.hdc.run_hdc_cmd(['shell', 'cp', device_path, - '/data/local/tmp']) and + '/data/local/tmp/hiperf']) and self.hdc.run_hdc_cmd(['file recv', - '/data/local/tmp/' + filename, + '/data/local/tmp/hiperf/' + filename, host_path])): self.hdc.run_hdc_cmd(['shell', 'rm', - '/data/local/tmp/' + filename]) + '/data/local/tmp/hiperf/' + filename]) return True print('failed to pull %s from device' % device_path) return False diff --git a/src/subcommand_record.cpp b/src/subcommand_record.cpp index 14ccf7a..45aa14d 100644 --- a/src/subcommand_record.cpp +++ b/src/subcommand_record.cpp @@ -44,8 +44,8 @@ const std::string CONTROL_CMD_START = "start"; const std::string CONTROL_CMD_PAUSE = "pause"; const std::string CONTROL_CMD_RESUME = "resume"; const std::string CONTROL_CMD_STOP = "stop"; -const std::string CONTROL_FIFO_FILE_C2S = "/data/local/tmp/.hiperf_record_control_c2s"; -const std::string CONTROL_FIFO_FILE_S2C = "/data/local/tmp/.hiperf_record_control_s2c"; +const std::string CONTROL_FIFO_FILE_C2S = "/data/local/tmp/hiperf/.hiperf_record_control_c2s"; +const std::string CONTROL_FIFO_FILE_S2C = "/data/local/tmp/hiperf/.hiperf_record_control_s2c"; // when there are many events, start record will take more time. const std::chrono::milliseconds CONTROL_WAITREPY_TOMEOUT = 2000ms; diff --git a/src/virtual_runtime.cpp b/src/virtual_runtime.cpp index 2237513..b0ea415 100644 --- a/src/virtual_runtime.cpp +++ b/src/virtual_runtime.cpp @@ -686,7 +686,7 @@ void VirtualRuntime::LoadVdso() std::string memory(map.end_ - map.begin_, '\0'); std::copy(reinterpret_cast((map.begin_)), reinterpret_cast((map.end_)), &memory[0]); - std::string tempPath("/data/local/tmp/"); + std::string tempPath("/data/local/tmp/hiperf/"); std::string tempFileName = tempPath + MMAP_VDSO_NAME; if (!WriteStringToFile(tempFileName, memory)) { printf("vdso temp file create fail at %s\n", tempFileName.c_str()); diff --git a/test/unittest/common/native/hiperf_client_test.cpp b/test/unittest/common/native/hiperf_client_test.cpp index 22c390e..bf7f0fd 100644 --- a/test/unittest/common/native/hiperf_client_test.cpp +++ b/test/unittest/common/native/hiperf_client_test.cpp @@ -81,7 +81,7 @@ HWTEST_F(HiperfClientTest, OutDir, TestSize.Level1) StdoutRecord stdoutRecord; stdoutRecord.Start(); - HiperfClient::Client myHiperf("/data/local/tmp/"); + HiperfClient::Client myHiperf("/data/local/tmp/hiperf/"); myHiperf.SetDebugMode(); ASSERT_TRUE(myHiperf.Start()); @@ -321,7 +321,7 @@ HWTEST_F(HiperfClientTest, SetSymbolDir, TestSize.Level1) HiperfClient::RecordOption opt; vector selectPids = {getpid()}; opt.SetSelectPids(selectPids); - opt.SetSymbolDir("/data/local/tmp/"); + opt.SetSymbolDir("/data/local/tmp/hiperf/"); TestCaseOption(opt); } diff --git a/test/unittest/common/native/hiperf_libreport_test.cpp b/test/unittest/common/native/hiperf_libreport_test.cpp index 42ee290..d941340 100644 --- a/test/unittest/common/native/hiperf_libreport_test.cpp +++ b/test/unittest/common/native/hiperf_libreport_test.cpp @@ -86,7 +86,7 @@ void HiperfLibReportTest::DefaultSymbolsBuildIdContentCheck(const std::string &c "libace.z.so,b8d9d3bb0184ba917e8d05d471e8387a],[/system/lib/" "libeventhandler.z.so,b1e08a8a6eabe33363f721b14393b06b],[/system/bin/" "hilogd,b11a9f3700884ded33879f81914e3aa2],[/system/bin/" - "wifi_hal_service,6beba486dcdf5debb5c9248bc5cdf5f0],[/data/local/tmp/" + "wifi_hal_service,6beba486dcdf5debb5c9248bc5cdf5f0],[/data/local/tmp/hiperf/" "hiperf,32aa1e9c5f35d49e16fa1b6e86db130c],[/system/bin/" "hiview,419493d9ccef1df5dedfa4a144249e49],[/system/lib/" "libhiviewbase.z.so,349d82d4f1d2dc21c039156afbe470ad],[/system/lib/" diff --git a/test/unittest/common/native/include/callstack_test.h b/test/unittest/common/native/include/callstack_test.h index 01414c3..b991b73 100644 --- a/test/unittest/common/native/include/callstack_test.h +++ b/test/unittest/common/native/include/callstack_test.h @@ -54,22 +54,22 @@ static const std::string TEST_DWARF_ELF = "hiperf_example_cmd"; record mmap2: type 10, misc 2, size 107 pid 643, tid 643, addr 0x454000, len 0x3000 pgoff 0x0, maj 179, min 7, ino 4868, ino_generation 6874019636378171493 - prot 1, flags 2, filename /data/local/tmp/hiperf_example_cmd + prot 1, flags 2, filename /data/local/tmp/hiperf/hiperf_example_cmd record mmap2: type 10, misc 2, size 107 pid 643, tid 643, addr 0x457000, len 0x5000 pgoff 0x2000, maj 179, min 7, ino 4868, ino_generation 7237954708011182952 - prot 5, flags 2, filename /data/local/tmp/hiperf_example_cmd + prot 5, flags 2, filename /data/local/tmp/hiperf/hiperf_example_cmd record mmap2: type 10, misc 2, size 107 pid 643, tid 643, addr 0x45c000, len 0x1000 pgoff 0x6000, maj 179, min 7, ino 4868, ino_generation 7237954708011182952 - prot 1, flags 2, filename /data/local/tmp/hiperf_example_cmd + prot 1, flags 2, filename /data/local/tmp/hiperf/hiperf_example_cmd record mmap2: type 10, misc 2, size 107 pid 643, tid 643, addr 0x45d000, len 0x1000 pgoff 0x6000, maj 179, min 7, ino 4868, ino_generation 7237954708011182952 - prot 3, flags 2, filename /data/local/tmp/hiperf_example_cmd + prot 3, flags 2, filename /data/local/tmp/hiperf/hiperf_example_cmd */ static const std::vector TEST_DWARF_MMAP = { {"hiperf_example_cmd", 0x454000, 0x3000, 0x0}, @@ -109,17 +109,17 @@ static const std::string TEST_DWARF_ELF = "hiperf_example_cmd_64"; record mmap2: type 10, misc 2, size 110 pid 24925, tid 24925, addr 0x5591ef4000, len 0x3000 pgoff 0x0, maj 179, min 11, ino 2495283, ino_generation 0 - prot 1, flags 2, filename /data/local/tmp/hiperf_example_cmd_64 + prot 1, flags 2, filename /data/local/tmp/hiperf/hiperf_example_cmd_64 record mmap2: type 10, misc 2, size 110 pid 24925, tid 24925, addr 0x5591ef7000, len 0x3000 pgoff 0x2000, maj 179, min 11, ino 2495283, ino_generation 0 - prot 5, flags 2, filename /data/local/tmp/hiperf_example_cmd_64 + prot 5, flags 2, filename /data/local/tmp/hiperf/hiperf_example_cmd_64 record mmap2: type 10, misc 2, size 110 pid 24925, tid 24925, addr 0x5591efa000, len 0x1000 pgoff 0x4000, maj 179, min 11, ino 2495283, ino_generation 0 - prot 1, flags 2, filename /data/local/tmp/hiperf_example_cmd_64 + prot 1, flags 2, filename /data/local/tmp/hiperf/hiperf_example_cmd_64 */ static const std::vector TEST_DWARF_MMAP = { {"hiperf_example_cmd_64", 0x5591ef4000, 0x3000, 0x0}, diff --git a/test/unittest/common/native/subcommand_record_test.cpp b/test/unittest/common/native/subcommand_record_test.cpp index 0930cba..6c074b5 100644 --- a/test/unittest/common/native/subcommand_record_test.cpp +++ b/test/unittest/common/native/subcommand_record_test.cpp @@ -649,7 +649,7 @@ HWTEST_F(SubCommandRecordTest, MmapPagesInputErr, TestSize.Level1) // output file name HWTEST_F(SubCommandRecordTest, OutputFileName, TestSize.Level1) { - TestRecordCommand("-d 2 -o /data/local/tmp/output.perf.data "); + TestRecordCommand("-d 2 -o /data/local/tmp/hiperf/output.perf.data "); } HWTEST_F(SubCommandRecordTest, OutputFileNameErr, TestSize.Level1) -- Gitee From 265c91a6161221544e3873c4ed4c6532c3476832 Mon Sep 17 00:00:00 2001 From: zhang-cui11 Date: Wed, 14 Sep 2022 15:15:33 +0800 Subject: [PATCH 2/2] add config Signed-off-by: zhang-cui11 --- config/hiperf.cfg | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 config/hiperf.cfg diff --git a/config/hiperf.cfg b/config/hiperf.cfg new file mode 100644 index 0000000..a6bafb4 --- /dev/null +++ b/config/hiperf.cfg @@ -0,0 +1,9 @@ +{ + "jobs" : [{ + "name" : "post-init", + "cmds" : [ + "mkdir /data/local/tmp/hiperf -m 755" + ] + } + ] +} -- Gitee