1. 程式人生 > 實用技巧 >ESP32-效能監控筆記

ESP32-效能監控筆記

基於ESP-IDF4.1

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <unistd.h>
 4 #include "esp_timer.h"
 5 #include "esp_log.h"
 6 #include "esp_sleep.h"
 7 #include "sdkconfig.h"
 8 
 9 #include "perfmon.h"
10 
11 static const char* TAG = "example";
12 
13 static void exec_test_function(void
*params) 14 { 15 for (int i = 0 ; i < 100 ; i++) { 16 __asm__ __volatile__(" nop"); 17 } 18 } 19 20 //具有專用效能計數器的表 21 static uint32_t pm_check_table[] = { 22 XTPERF_CNT_CYCLES, XTPERF_MASK_CYCLES, // 週期合計 23 XTPERF_CNT_INSN, XTPERF_MASK_INSN_ALL, // 指令合計 24 XTPERF_CNT_D_LOAD_U1, XTPERF_MASK_D_LOAD_LOCAL_MEM, //
記憶體讀取 25 XTPERF_CNT_D_STORE_U1, XTPERF_MASK_D_STORE_LOCAL_MEM, // 記憶體寫入 26 XTPERF_CNT_BUBBLES, XTPERF_MASK_BUBBLES_ALL &(~XTPERF_MASK_BUBBLES_R_HOLD_REG_DEP), // 等待其他原因 27 XTPERF_CNT_BUBBLES, XTPERF_MASK_BUBBLES_R_HOLD_REG_DEP, // 等待暫存器依賴 28 XTPERF_CNT_OVERFLOW, XTPERF_MASK_OVERFLOW, //
最後一個測試周期 29 }; 30 31 #define TOTAL_CALL_AMOUNT 200 32 #define PERFMON_TRACELEVEL -1 // -1 - 忽略跟蹤級別 33 34 void app_main(void) 35 { 36 ESP_LOGI(TAG, "Start"); 37 ESP_LOGI(TAG, "Start test with printing all available statistic"); 38 xtensa_perfmon_config_t pm_config = {}; 39 pm_config.counters_size = sizeof(xtensa_perfmon_select_mask_all) / sizeof(uint32_t) / 2; 40 pm_config.select_mask = xtensa_perfmon_select_mask_all; 41 pm_config.repeat_count = TOTAL_CALL_AMOUNT; 42 pm_config.max_deviation = 1; 43 pm_config.call_function = exec_test_function; 44 pm_config.callback = xtensa_perfmon_view_cb; 45 pm_config.callback_params = stdout; 46 pm_config.tracelevel = PERFMON_TRACELEVEL; 47 xtensa_perfmon_exec(&pm_config); 48 49 ESP_LOGI(TAG, "Start test with user defined statistic"); 50 pm_config.counters_size = sizeof(pm_check_table) / sizeof(uint32_t) / 2; 51 pm_config.select_mask = pm_check_table; 52 pm_config.repeat_count = TOTAL_CALL_AMOUNT; 53 pm_config.max_deviation = 1; 54 pm_config.call_function = exec_test_function; 55 pm_config.callback = xtensa_perfmon_view_cb; 56 pm_config.callback_params = stdout; 57 pm_config.tracelevel = PERFMON_TRACELEVEL; 58 59 xtensa_perfmon_exec(&pm_config); 60 61 ESP_LOGI(TAG, "The End"); 62 }

原文:https://gitee.com/EspressifSystems/esp-idf/tree/master/examples/system/perfmon