perfmon_example_main.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* perfmon (performance monitor) example
  2. This example code is in the Public Domain (or CC0 licensed, at your option.)
  3. Unless required by applicable law or agreed to in writing, this
  4. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <unistd.h>
  10. #include "esp_timer.h"
  11. #include "esp_log.h"
  12. #include "esp_sleep.h"
  13. #include "sdkconfig.h"
  14. #include "perfmon.h"
  15. static const char* TAG = "example";
  16. static void exec_test_function(void *params)
  17. {
  18. for (int i = 0 ; i < 100 ; i++) {
  19. __asm__ __volatile__(" nop");
  20. }
  21. }
  22. // Table with dedicated performance counters
  23. static uint32_t pm_check_table[] = {
  24. XTPERF_CNT_CYCLES, XTPERF_MASK_CYCLES, // total cycles
  25. XTPERF_CNT_INSN, XTPERF_MASK_INSN_ALL, // total instructions
  26. XTPERF_CNT_D_LOAD_U1, XTPERF_MASK_D_LOAD_LOCAL_MEM, // Mem read
  27. XTPERF_CNT_D_STORE_U1, XTPERF_MASK_D_STORE_LOCAL_MEM, // Mem write
  28. XTPERF_CNT_BUBBLES, XTPERF_MASK_BUBBLES_ALL &(~XTPERF_MASK_BUBBLES_R_HOLD_REG_DEP), // wait for other reasons
  29. XTPERF_CNT_BUBBLES, XTPERF_MASK_BUBBLES_R_HOLD_REG_DEP, // Wait for register dependency
  30. XTPERF_CNT_OVERFLOW, XTPERF_MASK_OVERFLOW, // Last test cycle
  31. };
  32. #define TOTAL_CALL_AMOUNT 200
  33. #define PERFMON_TRACELEVEL -1 // -1 - will ignore trace level
  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. ESP_LOGI(TAG, "Start test with user defined statistic");
  49. pm_config.counters_size = sizeof(pm_check_table) / sizeof(uint32_t) / 2;
  50. pm_config.select_mask = pm_check_table;
  51. pm_config.repeat_count = TOTAL_CALL_AMOUNT;
  52. pm_config.max_deviation = 1;
  53. pm_config.call_function = exec_test_function;
  54. pm_config.callback = xtensa_perfmon_view_cb;
  55. pm_config.callback_params = stdout;
  56. pm_config.tracelevel = PERFMON_TRACELEVEL;
  57. xtensa_perfmon_exec(&pm_config);
  58. ESP_LOGI(TAG, "The End");
  59. }