mirror of https://github.com/ARMmbed/mbed-os.git
CPU stats: strip more when disabled
parent
2d6db332e6
commit
28b770510c
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
#include "hal/us_ticker_api.h"
|
#include "hal/us_ticker_api.h"
|
||||||
#include "hal/lp_ticker_api.h"
|
#include "hal/lp_ticker_api.h"
|
||||||
|
#include "platform/mbed_wait_api.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
@ -32,18 +33,18 @@
|
||||||
|
|
||||||
// deep sleep locking counter. A target is allowed to deep sleep if counter == 0
|
// deep sleep locking counter. A target is allowed to deep sleep if counter == 0
|
||||||
static uint16_t deep_sleep_lock = 0U;
|
static uint16_t deep_sleep_lock = 0U;
|
||||||
|
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
|
||||||
static us_timestamp_t sleep_time = 0;
|
static us_timestamp_t sleep_time = 0;
|
||||||
static us_timestamp_t deep_sleep_time = 0;
|
static us_timestamp_t deep_sleep_time = 0;
|
||||||
|
|
||||||
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
|
static const ticker_data_t *sleep_ticker = NULL;
|
||||||
static ticker_data_t *sleep_ticker = NULL;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline us_timestamp_t read_us(void)
|
static inline us_timestamp_t read_us(void)
|
||||||
{
|
{
|
||||||
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
|
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
|
||||||
if (NULL == sleep_ticker) {
|
if (NULL == sleep_ticker) {
|
||||||
sleep_ticker = (ticker_data_t *)get_lp_ticker_data();
|
sleep_ticker = get_lp_ticker_data();
|
||||||
}
|
}
|
||||||
return ticker_read_us(sleep_ticker);
|
return ticker_read_us(sleep_ticker);
|
||||||
#else
|
#else
|
||||||
|
@ -53,7 +54,11 @@ static inline us_timestamp_t read_us(void)
|
||||||
|
|
||||||
us_timestamp_t mbed_time_idle(void)
|
us_timestamp_t mbed_time_idle(void)
|
||||||
{
|
{
|
||||||
|
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
|
||||||
return (sleep_time + deep_sleep_time);
|
return (sleep_time + deep_sleep_time);
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
us_timestamp_t mbed_uptime(void)
|
us_timestamp_t mbed_uptime(void)
|
||||||
|
@ -63,12 +68,20 @@ us_timestamp_t mbed_uptime(void)
|
||||||
|
|
||||||
us_timestamp_t mbed_time_sleep(void)
|
us_timestamp_t mbed_time_sleep(void)
|
||||||
{
|
{
|
||||||
|
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
|
||||||
return sleep_time;
|
return sleep_time;
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
us_timestamp_t mbed_time_deepsleep(void)
|
us_timestamp_t mbed_time_deepsleep(void)
|
||||||
{
|
{
|
||||||
|
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
|
||||||
return deep_sleep_time;
|
return deep_sleep_time;
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MBED_SLEEP_TRACING_ENABLED
|
#ifdef MBED_SLEEP_TRACING_ENABLED
|
||||||
|
@ -211,27 +224,33 @@ void sleep_manager_sleep_auto(void)
|
||||||
sleep_tracker_print_stats();
|
sleep_tracker_print_stats();
|
||||||
#endif
|
#endif
|
||||||
core_util_critical_section_enter();
|
core_util_critical_section_enter();
|
||||||
|
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
|
||||||
us_timestamp_t start = read_us();
|
us_timestamp_t start = read_us();
|
||||||
bool deep = false;
|
bool deep = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
// debug profile should keep debuggers attached, no deep sleep allowed
|
// debug profile should keep debuggers attached, no deep sleep allowed
|
||||||
#ifdef MBED_DEBUG
|
#ifdef MBED_DEBUG
|
||||||
hal_sleep();
|
hal_sleep();
|
||||||
#else
|
#else
|
||||||
if (sleep_manager_can_deep_sleep()) {
|
if (sleep_manager_can_deep_sleep()) {
|
||||||
|
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
|
||||||
deep = true;
|
deep = true;
|
||||||
|
#endif
|
||||||
hal_deepsleep();
|
hal_deepsleep();
|
||||||
} else {
|
} else {
|
||||||
hal_sleep();
|
hal_sleep();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBED_CPU_STATS_ENABLED) && DEVICE_LPTICKER
|
||||||
us_timestamp_t end = read_us();
|
us_timestamp_t end = read_us();
|
||||||
if (true == deep) {
|
if (true == deep) {
|
||||||
deep_sleep_time += end - start;
|
deep_sleep_time += end - start;
|
||||||
} else {
|
} else {
|
||||||
sleep_time += end - start;
|
sleep_time += end - start;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
core_util_critical_section_exit();
|
core_util_critical_section_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue