![](/media/cache/group/download_IjbieK2.png.50x50_q85.png)
demo new haven display
Dependencies: LCD Menu ButtonCtrl TimeManagement EventLog AddressMap emic2
ESCM 2000 Control and Display application provides interface for the LPC1768 processor boards with the ECSM 2000 system.
This application implements SW interface : - RX 485 Receive from physical system - RX 485 Interface to send toECOM / ESCM board - CAN Interface to send to ECOM / ESCM board - 4x40 LCD with menu controls - RTC configuration -EMIC2 Sound Card - GPIO Extender to push buttons etc
stats_report.h@6:010ceb99f7b0, 2019-09-17 (annotated)
- Committer:
- foxbrianr
- Date:
- Tue Sep 17 13:48:57 2019 +0000
- Revision:
- 6:010ceb99f7b0
- Parent:
- 5:65f21c0b6b79
Beta 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
foxbrianr | 5:65f21c0b6b79 | 1 | /* mbed Microcontroller Library |
foxbrianr | 5:65f21c0b6b79 | 2 | * Copyright (c) 2018 ARM Limited |
foxbrianr | 5:65f21c0b6b79 | 3 | * SPDX-License-Identifier: Apache-2.0 |
foxbrianr | 5:65f21c0b6b79 | 4 | */ |
foxbrianr | 5:65f21c0b6b79 | 5 | |
foxbrianr | 5:65f21c0b6b79 | 6 | #ifndef STATS_REPORT_H |
foxbrianr | 5:65f21c0b6b79 | 7 | #define STATS_REPORT_H |
foxbrianr | 5:65f21c0b6b79 | 8 | |
foxbrianr | 5:65f21c0b6b79 | 9 | #include "mbed.h" |
foxbrianr | 5:65f21c0b6b79 | 10 | |
foxbrianr | 6:010ceb99f7b0 | 11 | typedef struct { |
foxbrianr | 6:010ceb99f7b0 | 12 | Timer timer; |
foxbrianr | 6:010ceb99f7b0 | 13 | uint32_t counter; |
foxbrianr | 6:010ceb99f7b0 | 14 | uint64_t timeStamp; |
foxbrianr | 6:010ceb99f7b0 | 15 | uint64_t lastTimeStamp; |
foxbrianr | 6:010ceb99f7b0 | 16 | uint32_t deltaTime; |
foxbrianr | 6:010ceb99f7b0 | 17 | uint32_t deltaTimeMax; |
foxbrianr | 6:010ceb99f7b0 | 18 | uint32_t deltaTimeMin; |
foxbrianr | 6:010ceb99f7b0 | 19 | uint32_t deltaTimeAve; |
foxbrianr | 6:010ceb99f7b0 | 20 | uint32_t cycleTime; |
foxbrianr | 6:010ceb99f7b0 | 21 | uint32_t cycleTimeMax; |
foxbrianr | 6:010ceb99f7b0 | 22 | uint32_t cycleTimeMin; |
foxbrianr | 6:010ceb99f7b0 | 23 | uint32_t cycleTimeAve; |
foxbrianr | 6:010ceb99f7b0 | 24 | } OsPerfData_t; |
foxbrianr | 6:010ceb99f7b0 | 25 | |
foxbrianr | 6:010ceb99f7b0 | 26 | typedef struct { |
foxbrianr | 6:010ceb99f7b0 | 27 | OsPerfData_t task[10]; |
foxbrianr | 6:010ceb99f7b0 | 28 | } OsTaskPerfData_t; |
foxbrianr | 6:010ceb99f7b0 | 29 | |
foxbrianr | 6:010ceb99f7b0 | 30 | |
foxbrianr | 6:010ceb99f7b0 | 31 | |
foxbrianr | 5:65f21c0b6b79 | 32 | /** |
foxbrianr | 5:65f21c0b6b79 | 33 | * System Reporting library. Provides runtime information on device: |
foxbrianr | 5:65f21c0b6b79 | 34 | * - CPU sleep, idle, and wake times |
foxbrianr | 5:65f21c0b6b79 | 35 | * - Heap and stack usage |
foxbrianr | 5:65f21c0b6b79 | 36 | * - Thread information |
foxbrianr | 5:65f21c0b6b79 | 37 | * - Static system information |
foxbrianr | 5:65f21c0b6b79 | 38 | */ |
foxbrianr | 5:65f21c0b6b79 | 39 | class SystemReport { |
foxbrianr | 5:65f21c0b6b79 | 40 | mbed_stats_heap_t heap_stats; |
foxbrianr | 5:65f21c0b6b79 | 41 | mbed_stats_cpu_t cpu_stats; |
foxbrianr | 5:65f21c0b6b79 | 42 | mbed_stats_sys_t sys_stats; |
foxbrianr | 5:65f21c0b6b79 | 43 | |
foxbrianr | 5:65f21c0b6b79 | 44 | mbed_stats_thread_t *thread_stats; |
foxbrianr | 5:65f21c0b6b79 | 45 | uint8_t thread_count; |
foxbrianr | 5:65f21c0b6b79 | 46 | uint8_t max_thread_count; |
foxbrianr | 5:65f21c0b6b79 | 47 | uint32_t sample_time_ms; |
foxbrianr | 5:65f21c0b6b79 | 48 | |
foxbrianr | 5:65f21c0b6b79 | 49 | public: |
foxbrianr | 5:65f21c0b6b79 | 50 | /** |
foxbrianr | 5:65f21c0b6b79 | 51 | * SystemReport - Sample rate in ms is required to handle the CPU percent awake logic |
foxbrianr | 5:65f21c0b6b79 | 52 | */ |
foxbrianr | 5:65f21c0b6b79 | 53 | SystemReport(uint32_t sample_rate) : max_thread_count(8), sample_time_ms(sample_rate) |
foxbrianr | 5:65f21c0b6b79 | 54 | { |
foxbrianr | 5:65f21c0b6b79 | 55 | thread_stats = new mbed_stats_thread_t[max_thread_count]; |
foxbrianr | 5:65f21c0b6b79 | 56 | |
foxbrianr | 5:65f21c0b6b79 | 57 | // Collect the static system information |
foxbrianr | 5:65f21c0b6b79 | 58 | mbed_stats_sys_get(&sys_stats); |
foxbrianr | 5:65f21c0b6b79 | 59 | |
foxbrianr | 5:65f21c0b6b79 | 60 | printf("=============================== SYSTEM INFO ================================\r\n"); |
foxbrianr | 5:65f21c0b6b79 | 61 | printf("Mbed OS Version: %ld \r\n", sys_stats.os_version); |
foxbrianr | 5:65f21c0b6b79 | 62 | printf("CPU ID: 0x%lx \r\n", sys_stats.cpu_id); |
foxbrianr | 5:65f21c0b6b79 | 63 | printf("Compiler ID: %d \r\n", sys_stats.compiler_id); |
foxbrianr | 5:65f21c0b6b79 | 64 | printf("Compiler Version: %ld \r\n", sys_stats.compiler_version); |
foxbrianr | 5:65f21c0b6b79 | 65 | |
foxbrianr | 5:65f21c0b6b79 | 66 | for (int i = 0; i < MBED_MAX_MEM_REGIONS; i++) { |
foxbrianr | 5:65f21c0b6b79 | 67 | if (sys_stats.ram_size[i] != 0) { |
foxbrianr | 5:65f21c0b6b79 | 68 | printf("RAM%d: Start 0x%lx Size: 0x%lx \r\n", i, sys_stats.ram_start[i], sys_stats.ram_size[i]); |
foxbrianr | 5:65f21c0b6b79 | 69 | } |
foxbrianr | 5:65f21c0b6b79 | 70 | } |
foxbrianr | 5:65f21c0b6b79 | 71 | for (int i = 0; i < MBED_MAX_MEM_REGIONS; i++) { |
foxbrianr | 5:65f21c0b6b79 | 72 | if (sys_stats.rom_size[i] != 0) { |
foxbrianr | 5:65f21c0b6b79 | 73 | printf("ROM%d: Start 0x%lx Size: 0x%lx \r\n", i, sys_stats.rom_start[i], sys_stats.rom_size[i]); |
foxbrianr | 5:65f21c0b6b79 | 74 | } |
foxbrianr | 5:65f21c0b6b79 | 75 | } |
foxbrianr | 5:65f21c0b6b79 | 76 | } |
foxbrianr | 5:65f21c0b6b79 | 77 | |
foxbrianr | 5:65f21c0b6b79 | 78 | ~SystemReport(void) |
foxbrianr | 5:65f21c0b6b79 | 79 | { |
foxbrianr | 5:65f21c0b6b79 | 80 | free(thread_stats); |
foxbrianr | 5:65f21c0b6b79 | 81 | } |
foxbrianr | 5:65f21c0b6b79 | 82 | |
foxbrianr | 5:65f21c0b6b79 | 83 | /** |
foxbrianr | 5:65f21c0b6b79 | 84 | * Report on each Mbed OS Platform stats API |
foxbrianr | 5:65f21c0b6b79 | 85 | */ |
foxbrianr | 5:65f21c0b6b79 | 86 | void report_state(void) |
foxbrianr | 5:65f21c0b6b79 | 87 | { |
foxbrianr | 5:65f21c0b6b79 | 88 | report_cpu_stats(); |
foxbrianr | 5:65f21c0b6b79 | 89 | report_heap_stats(); |
foxbrianr | 5:65f21c0b6b79 | 90 | report_thread_stats(); |
foxbrianr | 5:65f21c0b6b79 | 91 | |
foxbrianr | 5:65f21c0b6b79 | 92 | // Clear next line to separate subsequent report logs |
foxbrianr | 5:65f21c0b6b79 | 93 | printf("\r\n"); |
foxbrianr | 5:65f21c0b6b79 | 94 | } |
foxbrianr | 5:65f21c0b6b79 | 95 | |
foxbrianr | 5:65f21c0b6b79 | 96 | /** |
foxbrianr | 5:65f21c0b6b79 | 97 | * Report CPU idle and awake time in terms of percentage |
foxbrianr | 5:65f21c0b6b79 | 98 | */ |
foxbrianr | 5:65f21c0b6b79 | 99 | void report_cpu_stats(void) |
foxbrianr | 5:65f21c0b6b79 | 100 | { |
foxbrianr | 5:65f21c0b6b79 | 101 | static uint64_t prev_idle_time = 0; |
foxbrianr | 5:65f21c0b6b79 | 102 | |
foxbrianr | 6:010ceb99f7b0 | 103 | fprintf(stdout,"================= CPU STATS =================\r\n"); |
foxbrianr | 5:65f21c0b6b79 | 104 | |
foxbrianr | 5:65f21c0b6b79 | 105 | // Collect and print cpu stats |
foxbrianr | 5:65f21c0b6b79 | 106 | mbed_stats_cpu_get(&cpu_stats); |
foxbrianr | 5:65f21c0b6b79 | 107 | |
foxbrianr | 5:65f21c0b6b79 | 108 | uint64_t diff = (cpu_stats.idle_time - prev_idle_time); |
foxbrianr | 5:65f21c0b6b79 | 109 | uint8_t idle = (diff * 100) / (sample_time_ms * 1000); // usec; |
foxbrianr | 5:65f21c0b6b79 | 110 | uint8_t usage = 100 - ((diff * 100) / (sample_time_ms * 1000)); // usec;; |
foxbrianr | 5:65f21c0b6b79 | 111 | prev_idle_time = cpu_stats.idle_time; |
foxbrianr | 5:65f21c0b6b79 | 112 | |
foxbrianr | 6:010ceb99f7b0 | 113 | fprintf(stdout,"Idle: %d%% Usage: %d%% \r\n", idle, usage); |
foxbrianr | 5:65f21c0b6b79 | 114 | } |
foxbrianr | 5:65f21c0b6b79 | 115 | |
foxbrianr | 5:65f21c0b6b79 | 116 | /** |
foxbrianr | 5:65f21c0b6b79 | 117 | * Report current heap stats. Current heap refers to the current amount of |
foxbrianr | 5:65f21c0b6b79 | 118 | * allocated heap. Max heap refers to the highest amount of heap allocated |
foxbrianr | 5:65f21c0b6b79 | 119 | * since reset. |
foxbrianr | 5:65f21c0b6b79 | 120 | */ |
foxbrianr | 5:65f21c0b6b79 | 121 | void report_heap_stats(void) |
foxbrianr | 5:65f21c0b6b79 | 122 | { |
foxbrianr | 6:010ceb99f7b0 | 123 | fprintf(stdout,"================ HEAP STATS =================\r\n"); |
foxbrianr | 5:65f21c0b6b79 | 124 | |
foxbrianr | 5:65f21c0b6b79 | 125 | // Collect and print heap stats |
foxbrianr | 5:65f21c0b6b79 | 126 | mbed_stats_heap_get(&heap_stats); |
foxbrianr | 5:65f21c0b6b79 | 127 | |
foxbrianr | 6:010ceb99f7b0 | 128 | fprintf(stdout,"Current heap: %lu\r\n", heap_stats.current_size); |
foxbrianr | 6:010ceb99f7b0 | 129 | |
foxbrianr | 6:010ceb99f7b0 | 130 | fprintf(stdout,"Max heap size: %lu\r\n", heap_stats.max_size); |
foxbrianr | 5:65f21c0b6b79 | 131 | } |
foxbrianr | 5:65f21c0b6b79 | 132 | |
foxbrianr | 5:65f21c0b6b79 | 133 | /** |
foxbrianr | 5:65f21c0b6b79 | 134 | * Report active thread stats |
foxbrianr | 5:65f21c0b6b79 | 135 | */ |
foxbrianr | 5:65f21c0b6b79 | 136 | void report_thread_stats(void) |
foxbrianr | 5:65f21c0b6b79 | 137 | { |
foxbrianr | 6:010ceb99f7b0 | 138 | |
foxbrianr | 6:010ceb99f7b0 | 139 | fprintf(stdout,"================ THREAD STATS ===============\r\n"); |
foxbrianr | 5:65f21c0b6b79 | 140 | |
foxbrianr | 5:65f21c0b6b79 | 141 | // Collect and print running thread stats |
foxbrianr | 5:65f21c0b6b79 | 142 | int count = mbed_stats_thread_get_each(thread_stats, max_thread_count); |
foxbrianr | 5:65f21c0b6b79 | 143 | |
foxbrianr | 5:65f21c0b6b79 | 144 | for (int i = 0; i < count; i++) { |
foxbrianr | 6:010ceb99f7b0 | 145 | fprintf(stdout,"ID: 0x%lx \r\n", thread_stats[i].id); |
foxbrianr | 6:010ceb99f7b0 | 146 | fprintf(stdout,"Name: %s \r\n", thread_stats[i].name); |
foxbrianr | 6:010ceb99f7b0 | 147 | fprintf(stdout,"State: %ld \r\n", thread_stats[i].state); |
foxbrianr | 6:010ceb99f7b0 | 148 | fprintf(stdout,"Priority: %ld \r\n", thread_stats[i].priority); |
foxbrianr | 6:010ceb99f7b0 | 149 | fprintf(stdout,"Stack Size: %ld \r\n", thread_stats[i].stack_size); |
foxbrianr | 6:010ceb99f7b0 | 150 | fprintf(stdout,"Stack Space: %ld \r\n", thread_stats[i].stack_space); |
foxbrianr | 5:65f21c0b6b79 | 151 | } |
foxbrianr | 5:65f21c0b6b79 | 152 | } |
foxbrianr | 6:010ceb99f7b0 | 153 | |
foxbrianr | 6:010ceb99f7b0 | 154 | |
foxbrianr | 6:010ceb99f7b0 | 155 | |
foxbrianr | 6:010ceb99f7b0 | 156 | |
foxbrianr | 5:65f21c0b6b79 | 157 | }; |
foxbrianr | 5:65f21c0b6b79 | 158 | |
foxbrianr | 5:65f21c0b6b79 | 159 | #endif // STATS_REPORT_H |