From f458ddd4f51cc1a24c7e6e0622864d4eeb37278c Mon Sep 17 00:00:00 2001 From: zyxzyx Date: Tue, 21 Nov 2023 15:17:34 +0800 Subject: [PATCH 1/9] add gpu plugin Signed-off-by: zyxzyx --- device/BUILD.gn | 2 + device/cmds/BUILD.gn | 1 + device/cmds/include/parse_plugin_config.h | 1 + device/cmds/src/parse_plugin_config.cpp | 19 ++ device/cmds/test/BUILD.gn | 1 + device/ohos_test.xml | 6 + device/plugins/api/src/main.cpp | 1 + device/plugins/gpu_plugin/BUILD.gn | 75 +++++++ .../gpu_plugin/include/gpu_data_plugin.h | 71 +++++++ .../gpu_plugin/src/gpu_data_plugin.cpp | 168 +++++++++++++++ device/plugins/gpu_plugin/src/gpu_module.cpp | 66 ++++++ device/plugins/gpu_plugin/src/test_main.cpp | 70 +++++++ device/plugins/gpu_plugin/test/BUILD.gn | 57 +++++ .../gpu_plugin/test/resources/gpustat1 | 1 + .../gpu_plugin/test/resources/gpustat2 | 1 + .../unittest/gpu_data_plugin_unittest.cpp | 196 ++++++++++++++++++ protos/types/plugins/gpu_data/BUILD.gn | 130 ++++++++++++ .../plugins/gpu_data/gpu_plugin_config.proto | 24 +++ .../plugins/gpu_data/gpu_plugin_result.proto | 22 ++ 19 files changed, 912 insertions(+) create mode 100644 device/plugins/gpu_plugin/BUILD.gn create mode 100644 device/plugins/gpu_plugin/include/gpu_data_plugin.h create mode 100644 device/plugins/gpu_plugin/src/gpu_data_plugin.cpp create mode 100644 device/plugins/gpu_plugin/src/gpu_module.cpp create mode 100644 device/plugins/gpu_plugin/src/test_main.cpp create mode 100644 device/plugins/gpu_plugin/test/BUILD.gn create mode 100644 device/plugins/gpu_plugin/test/resources/gpustat1 create mode 100644 device/plugins/gpu_plugin/test/resources/gpustat2 create mode 100644 device/plugins/gpu_plugin/test/unittest/gpu_data_plugin_unittest.cpp create mode 100644 protos/types/plugins/gpu_data/BUILD.gn create mode 100644 protos/types/plugins/gpu_data/gpu_plugin_config.proto create mode 100644 protos/types/plugins/gpu_data/gpu_plugin_result.proto diff --git a/device/BUILD.gn b/device/BUILD.gn index 71bc6bcb7..15a7fccd9 100644 --- a/device/BUILD.gn +++ b/device/BUILD.gn @@ -20,6 +20,7 @@ group("hiprofiler_targets") { "plugins/api:hiprofiler_plugins", "plugins/arkts_plugin:arktsplugin", "plugins/cpu_plugin:cpudataplugin", + "plugins/gpu_plugin:gpudataplugin", "plugins/diskio_plugin:diskiodataplugin", "plugins/ftrace_plugin:ftrace_targets", "plugins/hidump_plugin:hidumpplugin", @@ -61,6 +62,7 @@ group("unittest") { "plugins/api/test:unittest", "plugins/arkts_plugin/test:unittest", "plugins/cpu_plugin/test:unittest", + "plugins/gpu_plugin/test:unittest", "plugins/diskio_plugin/test:unittest", "plugins/ftrace_plugin/test:unittest", "plugins/hidump_plugin/test:unittest", diff --git a/device/cmds/BUILD.gn b/device/cmds/BUILD.gn index 6b8427106..d60d238fb 100644 --- a/device/cmds/BUILD.gn +++ b/device/cmds/BUILD.gn @@ -41,6 +41,7 @@ ohos_executable("hiprofiler_cmd") { "${OHOS_PROFILER_DIR}/protos/services:profiler_service_type_source", "${OHOS_PROFILER_DIR}/protos/types/plugins/arkts_plugin:arkts_plugin_cpp_standard", "${OHOS_PROFILER_DIR}/protos/types/plugins/cpu_data:cpu_plugin_config_cpp_standard", + "${OHOS_PROFILER_DIR}/protos/types/plugins/gpu_data:gpu_plugin_config_cpp_standard", "${OHOS_PROFILER_DIR}/protos/types/plugins/diskio_data:diskio_plugin_config_cpp_standard", "${OHOS_PROFILER_DIR}/protos/types/plugins/ftrace_data/${device_kernel_version}:ftrace_plugin_config_cpp_standard", "${OHOS_PROFILER_DIR}/protos/types/plugins/hidump_data:hidump_plugin_config_cpp_standard", diff --git a/device/cmds/include/parse_plugin_config.h b/device/cmds/include/parse_plugin_config.h index 6fe3a32bb..abd27abf8 100755 --- a/device/cmds/include/parse_plugin_config.h +++ b/device/cmds/include/parse_plugin_config.h @@ -44,6 +44,7 @@ public: bool SetSerializeHisyseventConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig); bool SetSerializeArkTSConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig); bool SetSerializeXpowerConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig); + bool SetSerializeGpuConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig); google::protobuf::TextFormat::Parser& GetParser() { diff --git a/device/cmds/src/parse_plugin_config.cpp b/device/cmds/src/parse_plugin_config.cpp index 4028668fc..0aeea6706 100755 --- a/device/cmds/src/parse_plugin_config.cpp +++ b/device/cmds/src/parse_plugin_config.cpp @@ -16,6 +16,7 @@ #include "parse_plugin_config.h" #include "cpu_plugin_config_standard.pb.h" +#include "gpu_plugin_config_standard.pb.h" #include "diskio_plugin_config_standard.pb.h" #include "hidump_plugin_config_standard.pb.h" #include "hiebpf_plugin_config_standard.pb.h" @@ -129,6 +130,8 @@ bool ParsePluginConfig::SetSerializePluginsConfig(const std::string& pluginName, ret = SetSerializeArkTSConfig(pluginName, pluginConfig); } else if (pluginName == "xpower-plugin") { ret = SetSerializeXpowerConfig(pluginName, pluginConfig); + } else if (pluginName == "gpu-plugin") { + ret = SetSerializeGpuConfig(pluginName, pluginConfig); } else { printf("unsupport plugin: %s\n", pluginName.c_str()); } @@ -391,3 +394,19 @@ bool ParsePluginConfig::SetSerializeXpowerConfig(const std::string& pluginName, pluginConfig.set_config_data((const void*)configDataVec.data(), configDataVec.size()); return true; } + +bool ParsePluginConfig::SetSerializeGpuConfig(const std::string& pluginName, ProfilerPluginConfig& pluginConfig) +{ + std::string configData = pluginConfigMap[pluginName]; + auto gpuConfigNolite = std::make_unique(); + if (!parser_.ParseFromString(configData, gpuConfigNolite.get())) { + return false; + } + + std::vector configDataVec(gpuConfigNolite->ByteSizeLong()); + if (gpuConfigNolite->SerializeToArray(configDataVec.data(), configDataVec.size()) <= 0) { + return false; + } + pluginConfig.set_config_data((const void*)configDataVec.data(), configDataVec.size()); + return true; +} diff --git a/device/cmds/test/BUILD.gn b/device/cmds/test/BUILD.gn index f48bceb6a..44c7b03f2 100644 --- a/device/cmds/test/BUILD.gn +++ b/device/cmds/test/BUILD.gn @@ -37,6 +37,7 @@ ohos_unittest("hiprofiler_cmd_ut") { "${OHOS_PROFILER_DIR}/protos/services:profiler_service_type_source", "${OHOS_PROFILER_DIR}/protos/types/plugins/arkts_plugin:arkts_plugin_cpp_standard", "${OHOS_PROFILER_DIR}/protos/types/plugins/cpu_data:cpu_plugin_config_cpp_standard", + "${OHOS_PROFILER_DIR}/protos/types/plugins/gpu_data:gpu_plugin_config_cpp_standard", "${OHOS_PROFILER_DIR}/protos/types/plugins/diskio_data:diskio_plugin_config_cpp_standard", "${OHOS_PROFILER_DIR}/protos/types/plugins/ftrace_data/default:ftrace_plugin_config_cpp_standard", "${OHOS_PROFILER_DIR}/protos/types/plugins/hidump_data:hidump_plugin_config_cpp_standard", diff --git a/device/ohos_test.xml b/device/ohos_test.xml index 42bde8bce..b1ed04360 100644 --- a/device/ohos_test.xml +++ b/device/ohos_test.xml @@ -189,4 +189,10 @@