# HWCPipe_ohos **Repository Path**: fengrenjie/hwcpipe_ohos ## Basic Information - **Project Name**: HWCPipe_ohos - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2021-06-01 - **Last Updated**: 2021-06-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## HWCPipe 本项目是基于开源项目HWCPipe进行openharmony的移植和开发的,可以通过项目标签以及github地址([https://github.com/ARM-software/HWCPipe](https://github.com/ARM-software/HWCPipe))追踪到原安卓项目版本。 基线版本:https://github.com/ARM-software/HWCPipe commit:aaadd74d6fcc8a80ec78398283a7c4ae0fd92eab ### 项目介绍 * 项目名称:HWCPipe(获取CPU和GPU硬件计数器的项目) * 所属系列:openharmony的第三方组件适配移植 * 功能:HWCPipe是一个简单且可扩展的接口,用于读取CPU和GPU硬件计数器。 * 项目移植状态:完成 * 调用差异:无 * 开发版本:SDK 5(Demo版本,库可直接在C/C++调用),DevEco Studio 2.1 Beta 3 * 项目作者和维护人:冯仁杰 * 联系方式:fengrenjie@uniontech.com * 原项目Doc地址:https://github.com/ARM-software/HWCPipe ### 项目介绍 * 编程语言:C++ * 外部库依赖:无 ### 安装教程 #### OpenHarmony HAP中使用 1. 将`entry/src/main/cpp/HWCPipe`文件夹复制到你的cpp目录 2. 修改你的cmakelist.txt文件,添加如下代码: ```shell #引入指定目录下的CMakeLists.txt add_subdirectory(HWCPipe) #指定头文件查找路径 include_directories(HWCPipe) #hwcpipe 为HWCPipe库的名称,hilog_ndk.z为hilog 日志引用 target_link_libraries(${PROJECT_NAME} hwcpipe hilog_ndk.z) ``` 3. 在entry的build.gradle中添加如下代码: ```groovy ohos { ... externalNativeBuild { path "src/main/cpp/CMakeLists.txt" arguments "-v" abiFilters "arm64-v8a" cppFlags "-std=c++11" } } ``` 4. 在你的.c/.cpp文件中,使用HWCPipe ```c++ // HWCPipe performs automated platform detection for CPU/GPU counters hwcpipe::HWCPipe h; // Start HWCPipe once at the beginning of the profiling session h.run(); while (main_loop) { // Call sample() to sample counters with the frequency you need auto measurements = h.sample(); [...] } // At the end of the profiling session, stop HWCPipe h.stop(); ``` `sample`函数返回一个`Measurements`结构,可以这样访问: ```c++ // Check if CPU measurements are available if (measurements.cpu) { // Look for a counter in the map const auto &counter = measurements.cpu->find(CpuCounter::Cycles); if (counter != measurements.cpu->end()) { // Get the data stored in the counter, casted to the type you need auto value = counter->second.get(); } } ``` 5. 具体示例(`cmakelist.txt`范例和`sample.cpp`范例)可以在`entry/src/main/cpp/`中查看。 ### 使用说明 如果在移动设备(**模拟器暂不支持,请在真机使用**)使用,请先开启性能分析: ```shell adb shell setprop security.perf_harden 0 ``` `HWCPipe`的基本使用 ```c++ // HWCPipe performs automated platform detection for CPU/GPU counters hwcpipe::HWCPipe h; // Start HWCPipe once at the beginning of the profiling session h.run(); while (main_loop) { // Call sample() to sample counters with the frequency you need auto measurements = h.sample(); [...] } // At the end of the profiling session, stop HWCPipe h.stop(); ``` `sample`函数返回一个`Measurements`结构,可以这样访问: ```c++ // Check if CPU measurements are available if (measurements.cpu) { // Look for a counter in the map const auto &counter = measurements.cpu->find(CpuCounter::Cycles); if (counter != measurements.cpu->end()) { // Get the data stored in the counter, casted to the type you need auto value = counter->second.get(); } } ``` #### 启用计数器 可用的计数器在`CpuCounter`和`GpuCounter`枚举中指定(分别为`cpu_profiler.h`和`gpu_profiler.h`)。 平台将支持这些计数器的子集,可通过以下方式查询: ```c++ auto cpu_counters = h.cpu_profiler()->supported_counters(); auto gpu_counters = h.gpu_profiler()->supported_counters() ``` 您可以通过以下方式指定要启用的计数器: ```c++ // Enable a default set of counters auto h = hwcpipe::HWCPipe(); // Pass sets of CPU and GPU counters to be enabled auto h = hwcpipe::HWCPipe({CpuCounter::Cycles, CpuCounter::Instructions}, {GpuCounter::GpuCycles}); // Pass a JSON string auto h = hwcpipe::HWCPipe(json); ``` JSON字符串的格式应如下所示: ```json { "cpu": ["Cycles", "Instructions"], "gpu": ["GpuCycles"] } ``` 可用的计数器名称可以在`cpu_counter_names`(`cpu_profiler.h`)和`gpu_counter_names`(`gpu_profiler.h`)中找到。 有关马里计数器的更多信息,请参阅 [Mali Performance Counters](https://community.arm.com/graphics/b/blog/posts/mali-bifrost-family-performance-counters)。 **日志显示**请参阅[真机HiLog日志显示](https://developer.huawei.com/consumer/cn/forum/topic/0203536901546500016?fid=0101303901040230869) ### 版本迭代 * [v1.0.0](https://gitee.com/archermind-ti/hwcpipe_ohos/tree/v1.0.0) ### 版权和许可信息 * [MIT License](https://gitee.com/archermind-ti/hwcpipe_ohos/blob/master/LICENSE)