mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #6377 from scartmell-arm/feature-deep-sleep-tracing-filename-fix
Replace runtime strip_path function with compiler intrinsic equivalentspull/6442/head
commit
ddf70f1dc9
|
@ -30,44 +30,20 @@ static uint16_t deep_sleep_lock = 0U;
|
||||||
|
|
||||||
#ifdef MBED_SLEEP_TRACING_ENABLED
|
#ifdef MBED_SLEEP_TRACING_ENABLED
|
||||||
|
|
||||||
// Length of the identifier extracted from the driver name to store for logging.
|
|
||||||
#define IDENTIFIER_WIDTH 15
|
|
||||||
// Number of drivers that can be stored in the structure
|
// Number of drivers that can be stored in the structure
|
||||||
#define STATISTIC_COUNT 10
|
#define STATISTIC_COUNT 10
|
||||||
|
|
||||||
typedef struct sleep_statistic {
|
typedef struct sleep_statistic {
|
||||||
char identifier[IDENTIFIER_WIDTH];
|
const char* identifier;
|
||||||
uint8_t count;
|
uint8_t count;
|
||||||
} sleep_statistic_t;
|
} sleep_statistic_t;
|
||||||
|
|
||||||
static sleep_statistic_t sleep_stats[STATISTIC_COUNT];
|
static sleep_statistic_t sleep_stats[STATISTIC_COUNT];
|
||||||
|
|
||||||
static const char* strip_path(const char* const filename)
|
|
||||||
{
|
|
||||||
char *output = strrchr(filename, '/');
|
|
||||||
|
|
||||||
if (output != NULL) {
|
|
||||||
return output + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
output = strrchr(filename, '\\');
|
|
||||||
|
|
||||||
if (output != NULL) {
|
|
||||||
return output + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
static sleep_statistic_t* sleep_tracker_find(const char *const filename)
|
static sleep_statistic_t* sleep_tracker_find(const char *const filename)
|
||||||
{
|
{
|
||||||
char temp[IDENTIFIER_WIDTH];
|
|
||||||
strncpy(temp, filename, IDENTIFIER_WIDTH);
|
|
||||||
temp[IDENTIFIER_WIDTH - 1] = '\0';
|
|
||||||
|
|
||||||
// Search for the a driver matching the current name and return it's index
|
|
||||||
for (int i = 0; i < STATISTIC_COUNT; ++i) {
|
for (int i = 0; i < STATISTIC_COUNT; ++i) {
|
||||||
if (strcmp(sleep_stats[i].identifier, temp) == 0) {
|
if (sleep_stats[i].identifier == filename) {
|
||||||
return &sleep_stats[i];
|
return &sleep_stats[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,15 +53,9 @@ static sleep_statistic_t* sleep_tracker_find(const char *const filename)
|
||||||
|
|
||||||
static sleep_statistic_t* sleep_tracker_add(const char* const filename)
|
static sleep_statistic_t* sleep_tracker_add(const char* const filename)
|
||||||
{
|
{
|
||||||
char temp[IDENTIFIER_WIDTH];
|
|
||||||
strncpy(temp, filename, IDENTIFIER_WIDTH);
|
|
||||||
temp[IDENTIFIER_WIDTH - 1] = '\0';
|
|
||||||
|
|
||||||
for (int i = 0; i < STATISTIC_COUNT; ++i) {
|
for (int i = 0; i < STATISTIC_COUNT; ++i) {
|
||||||
if (sleep_stats[i].identifier[0] == '\0') {
|
if (sleep_stats[i].identifier == NULL) {
|
||||||
core_util_critical_section_enter();
|
sleep_stats[i].identifier = filename;
|
||||||
strncpy(sleep_stats[i].identifier, temp, sizeof(temp));
|
|
||||||
core_util_critical_section_exit();
|
|
||||||
|
|
||||||
return &sleep_stats[i];
|
return &sleep_stats[i];
|
||||||
}
|
}
|
||||||
|
@ -104,7 +74,7 @@ static void sleep_tracker_print_stats(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sleep_stats[i].identifier[0] == '\0') {
|
if (sleep_stats[i].identifier == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,34 +85,31 @@ static void sleep_tracker_print_stats(void)
|
||||||
|
|
||||||
void sleep_tracker_lock(const char* const filename, int line)
|
void sleep_tracker_lock(const char* const filename, int line)
|
||||||
{
|
{
|
||||||
const char* const stripped_path = strip_path(filename);
|
sleep_statistic_t *stat = sleep_tracker_find(filename);
|
||||||
|
|
||||||
sleep_statistic_t* stat = sleep_tracker_find(stripped_path);
|
|
||||||
|
|
||||||
// Entry for this driver does not exist, create one.
|
// Entry for this driver does not exist, create one.
|
||||||
if (stat == NULL) {
|
if (stat == NULL) {
|
||||||
stat = sleep_tracker_add(stripped_path);
|
stat = sleep_tracker_add(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
core_util_atomic_incr_u8(&stat->count, 1);
|
core_util_atomic_incr_u8(&stat->count, 1);
|
||||||
|
|
||||||
debug("LOCK: %s, ln: %i, lock count: %u\r\n", stripped_path, line, deep_sleep_lock);
|
debug("LOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sleep_tracker_unlock(const char* const filename, int line)
|
void sleep_tracker_unlock(const char* const filename, int line)
|
||||||
{
|
{
|
||||||
const char* const stripped_path = strip_path(filename);
|
sleep_statistic_t *stat = sleep_tracker_find(filename);
|
||||||
sleep_statistic_t* stat = sleep_tracker_find(stripped_path);
|
|
||||||
|
|
||||||
// Entry for this driver does not exist, something went wrong.
|
// Entry for this driver does not exist, something went wrong.
|
||||||
if (stat == NULL) {
|
if (stat == NULL) {
|
||||||
debug("Unlocking sleep for driver that was not previously locked: %s, ln: %i\r\n", stripped_path, line);
|
debug("Unlocking sleep for driver that was not previously locked: %s, ln: %i\r\n", filename, line);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
core_util_atomic_decr_u8(&stat->count, 1);
|
core_util_atomic_decr_u8(&stat->count, 1);
|
||||||
|
|
||||||
debug("UNLOCK: %s, ln: %i, lock count: %u\r\n", stripped_path, line, deep_sleep_lock);
|
debug("UNLOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // MBED_SLEEP_TRACING_ENABLED
|
#endif // MBED_SLEEP_TRACING_ENABLED
|
||||||
|
|
|
@ -72,14 +72,14 @@ void sleep_tracker_unlock(const char *const filename, int line);
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
sleep_manager_lock_deep_sleep_internal(); \
|
sleep_manager_lock_deep_sleep_internal(); \
|
||||||
sleep_tracker_lock(__FILE__, __LINE__); \
|
sleep_tracker_lock(MBED_FILENAME, __LINE__); \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#define sleep_manager_unlock_deep_sleep() \
|
#define sleep_manager_unlock_deep_sleep() \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
sleep_manager_unlock_deep_sleep_internal(); \
|
sleep_manager_unlock_deep_sleep_internal(); \
|
||||||
sleep_tracker_unlock(__FILE__, __LINE__); \
|
sleep_tracker_unlock(MBED_FILENAME, __LINE__); \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -121,7 +121,6 @@ void sleep_manager_unlock_deep_sleep_internal(void);
|
||||||
*/
|
*/
|
||||||
bool sleep_manager_can_deep_sleep(void);
|
bool sleep_manager_can_deep_sleep(void);
|
||||||
|
|
||||||
|
|
||||||
/** Enter auto selected sleep mode. It chooses the sleep or deeepsleep modes based
|
/** Enter auto selected sleep mode. It chooses the sleep or deeepsleep modes based
|
||||||
* on the deepsleep locking counter
|
* on the deepsleep locking counter
|
||||||
*
|
*
|
||||||
|
|
|
@ -376,6 +376,20 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Macro containing the filename part of the value of __FILE__. Defined as
|
||||||
|
// string literal.
|
||||||
|
#ifndef MBED_FILENAME
|
||||||
|
#if defined(__CC_ARM)
|
||||||
|
#define MBED_FILENAME __MODULE__
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
#define MBED_FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __builtin_strrchr(__FILE__, '\\') ? __builtin_strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||||
|
#elif defined(__ICCARM__)
|
||||||
|
#define MBED_FILENAME (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||||
|
#else
|
||||||
|
#define MBED_FILENAME __FILE__
|
||||||
|
#endif
|
||||||
|
#endif // #ifndef MBED_FILENAME
|
||||||
|
|
||||||
// FILEHANDLE declaration
|
// FILEHANDLE declaration
|
||||||
#if defined(TOOLCHAIN_ARM)
|
#if defined(TOOLCHAIN_ARM)
|
||||||
#include <rt_sys.h>
|
#include <rt_sys.h>
|
||||||
|
|
Loading…
Reference in New Issue