adxl362 csv output format

Committer:
APS_Lab
Date:
Thu May 16 07:02:24 2019 +0000
Revision:
0:813b34a76f24
adxl362

Who changed what in which revision?

UserRevisionLine numberNew contents of line
APS_Lab 0:813b34a76f24 1 /* mbed Microcontroller Library
APS_Lab 0:813b34a76f24 2 * Copyright (c) 2018 ARM Limited
APS_Lab 0:813b34a76f24 3 * SPDX-License-Identifier: Apache-2.0
APS_Lab 0:813b34a76f24 4 */
APS_Lab 0:813b34a76f24 5
APS_Lab 0:813b34a76f24 6 #ifndef STATS_REPORT_H
APS_Lab 0:813b34a76f24 7 #define STATS_REPORT
APS_Lab 0:813b34a76f24 8
APS_Lab 0:813b34a76f24 9 #include "mbed.h"
APS_Lab 0:813b34a76f24 10
APS_Lab 0:813b34a76f24 11 /**
APS_Lab 0:813b34a76f24 12 * System Reporting library. Provides runtime information on device:
APS_Lab 0:813b34a76f24 13 * - CPU sleep, idle, and wake times
APS_Lab 0:813b34a76f24 14 * - Heap and stack usage
APS_Lab 0:813b34a76f24 15 * - Thread information
APS_Lab 0:813b34a76f24 16 * - Static system information
APS_Lab 0:813b34a76f24 17 */
APS_Lab 0:813b34a76f24 18 class SystemReport {
APS_Lab 0:813b34a76f24 19 mbed_stats_heap_t heap_stats;
APS_Lab 0:813b34a76f24 20 mbed_stats_cpu_t cpu_stats;
APS_Lab 0:813b34a76f24 21 mbed_stats_sys_t sys_stats;
APS_Lab 0:813b34a76f24 22
APS_Lab 0:813b34a76f24 23 mbed_stats_thread_t *thread_stats;
APS_Lab 0:813b34a76f24 24 uint8_t thread_count;
APS_Lab 0:813b34a76f24 25 uint8_t max_thread_count;
APS_Lab 0:813b34a76f24 26 uint32_t sample_time_ms;
APS_Lab 0:813b34a76f24 27
APS_Lab 0:813b34a76f24 28 public:
APS_Lab 0:813b34a76f24 29 /**
APS_Lab 0:813b34a76f24 30 * SystemReport - Sample rate in ms is required to handle the CPU percent awake logic
APS_Lab 0:813b34a76f24 31 */
APS_Lab 0:813b34a76f24 32 SystemReport(uint32_t sample_rate) : max_thread_count(8), sample_time_ms(sample_rate)
APS_Lab 0:813b34a76f24 33 {
APS_Lab 0:813b34a76f24 34 thread_stats = new mbed_stats_thread_t[max_thread_count];
APS_Lab 0:813b34a76f24 35
APS_Lab 0:813b34a76f24 36 // Collect the static system information
APS_Lab 0:813b34a76f24 37 mbed_stats_sys_get(&sys_stats);
APS_Lab 0:813b34a76f24 38
APS_Lab 0:813b34a76f24 39 printf("=============================== SYSTEM INFO ================================\r\n");
APS_Lab 0:813b34a76f24 40 printf("Mbed OS Version: %ld \r\n", sys_stats.os_version);
APS_Lab 0:813b34a76f24 41 printf("CPU ID: 0x%lx \r\n", sys_stats.cpu_id);
APS_Lab 0:813b34a76f24 42 printf("Compiler ID: %d \r\n", sys_stats.compiler_id);
APS_Lab 0:813b34a76f24 43 printf("Compiler Version: %ld \r\n", sys_stats.compiler_version);
APS_Lab 0:813b34a76f24 44
APS_Lab 0:813b34a76f24 45 for (int i = 0; i < MBED_MAX_MEM_REGIONS; i++) {
APS_Lab 0:813b34a76f24 46 if (sys_stats.ram_size[i] != 0) {
APS_Lab 0:813b34a76f24 47 printf("RAM%d: Start 0x%lx Size: 0x%lx \r\n", i, sys_stats.ram_start[i], sys_stats.ram_size[i]);
APS_Lab 0:813b34a76f24 48 }
APS_Lab 0:813b34a76f24 49 }
APS_Lab 0:813b34a76f24 50 for (int i = 0; i < MBED_MAX_MEM_REGIONS; i++) {
APS_Lab 0:813b34a76f24 51 if (sys_stats.rom_size[i] != 0) {
APS_Lab 0:813b34a76f24 52 printf("ROM%d: Start 0x%lx Size: 0x%lx \r\n", i, sys_stats.rom_start[i], sys_stats.rom_size[i]);
APS_Lab 0:813b34a76f24 53 }
APS_Lab 0:813b34a76f24 54 }
APS_Lab 0:813b34a76f24 55 }
APS_Lab 0:813b34a76f24 56
APS_Lab 0:813b34a76f24 57 ~SystemReport(void)
APS_Lab 0:813b34a76f24 58 {
APS_Lab 0:813b34a76f24 59 free(thread_stats);
APS_Lab 0:813b34a76f24 60 }
APS_Lab 0:813b34a76f24 61
APS_Lab 0:813b34a76f24 62 /**
APS_Lab 0:813b34a76f24 63 * Report on each Mbed OS Platform stats API
APS_Lab 0:813b34a76f24 64 */
APS_Lab 0:813b34a76f24 65 void report_state(void)
APS_Lab 0:813b34a76f24 66 {
APS_Lab 0:813b34a76f24 67 report_cpu_stats();
APS_Lab 0:813b34a76f24 68 report_heap_stats();
APS_Lab 0:813b34a76f24 69 report_thread_stats();
APS_Lab 0:813b34a76f24 70
APS_Lab 0:813b34a76f24 71 // Clear next line to separate subsequent report logs
APS_Lab 0:813b34a76f24 72 printf("\r\n");
APS_Lab 0:813b34a76f24 73 }
APS_Lab 0:813b34a76f24 74
APS_Lab 0:813b34a76f24 75 /**
APS_Lab 0:813b34a76f24 76 * Report CPU idle and awake time in terms of percentage
APS_Lab 0:813b34a76f24 77 */
APS_Lab 0:813b34a76f24 78 void report_cpu_stats(void)
APS_Lab 0:813b34a76f24 79 {
APS_Lab 0:813b34a76f24 80 static uint64_t prev_idle_time = 0;
APS_Lab 0:813b34a76f24 81
APS_Lab 0:813b34a76f24 82 printf("================= CPU STATS =================\r\n");
APS_Lab 0:813b34a76f24 83
APS_Lab 0:813b34a76f24 84 // Collect and print cpu stats
APS_Lab 0:813b34a76f24 85 mbed_stats_cpu_get(&cpu_stats);
APS_Lab 0:813b34a76f24 86
APS_Lab 0:813b34a76f24 87 uint64_t diff = (cpu_stats.idle_time - prev_idle_time);
APS_Lab 0:813b34a76f24 88 uint8_t idle = (diff * 100) / (sample_time_ms * 1000); // usec;
APS_Lab 0:813b34a76f24 89 uint8_t usage = 100 - ((diff * 100) / (sample_time_ms * 1000)); // usec;;
APS_Lab 0:813b34a76f24 90 prev_idle_time = cpu_stats.idle_time;
APS_Lab 0:813b34a76f24 91
APS_Lab 0:813b34a76f24 92 printf("Idle: %d%% Usage: %d%% \r\n", idle, usage);
APS_Lab 0:813b34a76f24 93 }
APS_Lab 0:813b34a76f24 94
APS_Lab 0:813b34a76f24 95 /**
APS_Lab 0:813b34a76f24 96 * Report current heap stats. Current heap refers to the current amount of
APS_Lab 0:813b34a76f24 97 * allocated heap. Max heap refers to the highest amount of heap allocated
APS_Lab 0:813b34a76f24 98 * since reset.
APS_Lab 0:813b34a76f24 99 */
APS_Lab 0:813b34a76f24 100 void report_heap_stats(void)
APS_Lab 0:813b34a76f24 101 {
APS_Lab 0:813b34a76f24 102 printf("================ HEAP STATS =================\r\n");
APS_Lab 0:813b34a76f24 103
APS_Lab 0:813b34a76f24 104 // Collect and print heap stats
APS_Lab 0:813b34a76f24 105 mbed_stats_heap_get(&heap_stats);
APS_Lab 0:813b34a76f24 106
APS_Lab 0:813b34a76f24 107 printf("Current heap: %lu\r\n", heap_stats.current_size);
APS_Lab 0:813b34a76f24 108 printf("Max heap size: %lu\r\n", heap_stats.max_size);
APS_Lab 0:813b34a76f24 109 }
APS_Lab 0:813b34a76f24 110
APS_Lab 0:813b34a76f24 111 /**
APS_Lab 0:813b34a76f24 112 * Report active thread stats
APS_Lab 0:813b34a76f24 113 */
APS_Lab 0:813b34a76f24 114 void report_thread_stats(void)
APS_Lab 0:813b34a76f24 115 {
APS_Lab 0:813b34a76f24 116 printf("================ THREAD STATS ===============\r\n");
APS_Lab 0:813b34a76f24 117
APS_Lab 0:813b34a76f24 118 // Collect and print running thread stats
APS_Lab 0:813b34a76f24 119 int count = mbed_stats_thread_get_each(thread_stats, max_thread_count);
APS_Lab 0:813b34a76f24 120
APS_Lab 0:813b34a76f24 121 for (int i = 0; i < count; i++) {
APS_Lab 0:813b34a76f24 122 printf("ID: 0x%lx \r\n", thread_stats[i].id);
APS_Lab 0:813b34a76f24 123 printf("Name: %s \r\n", thread_stats[i].name);
APS_Lab 0:813b34a76f24 124 printf("State: %ld \r\n", thread_stats[i].state);
APS_Lab 0:813b34a76f24 125 printf("Priority: %ld \r\n", thread_stats[i].priority);
APS_Lab 0:813b34a76f24 126 printf("Stack Size: %ld \r\n", thread_stats[i].stack_size);
APS_Lab 0:813b34a76f24 127 printf("Stack Space: %ld \r\n", thread_stats[i].stack_space);
APS_Lab 0:813b34a76f24 128 }
APS_Lab 0:813b34a76f24 129 }
APS_Lab 0:813b34a76f24 130 };
APS_Lab 0:813b34a76f24 131
APS_Lab 0:813b34a76f24 132 #endif // STATS_REPORT_H