Merge pull request #6377 from scartmell-arm/feature-deep-sleep-tracing-filename-fix

Replace runtime strip_path function with compiler intrinsic equivalents
pull/6442/head
Cruz Monrreal 2018-03-23 10:28:25 -05:00 committed by GitHub
commit ddf70f1dc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 57 deletions

View File

@ -30,44 +30,20 @@ static uint16_t deep_sleep_lock = 0U;
#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
#define STATISTIC_COUNT 10
typedef struct sleep_statistic {
char identifier[IDENTIFIER_WIDTH];
const char* identifier;
uint8_t count;
} sleep_statistic_t;
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)
{
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) {
if (strcmp(sleep_stats[i].identifier, temp) == 0) {
if (sleep_stats[i].identifier == filename) {
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)
{
char temp[IDENTIFIER_WIDTH];
strncpy(temp, filename, IDENTIFIER_WIDTH);
temp[IDENTIFIER_WIDTH - 1] = '\0';
for (int i = 0; i < STATISTIC_COUNT; ++i) {
if (sleep_stats[i].identifier[0] == '\0') {
core_util_critical_section_enter();
strncpy(sleep_stats[i].identifier, temp, sizeof(temp));
core_util_critical_section_exit();
if (sleep_stats[i].identifier == NULL) {
sleep_stats[i].identifier = filename;
return &sleep_stats[i];
}
@ -104,45 +74,42 @@ static void sleep_tracker_print_stats(void)
continue;
}
if (sleep_stats[i].identifier[0] == '\0') {
if (sleep_stats[i].identifier == NULL) {
return;
}
debug("[id: %s, count: %u]\r\n", sleep_stats[i].identifier,
sleep_stats[i].count);
sleep_stats[i].count);
}
}
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(stripped_path);
sleep_statistic_t *stat = sleep_tracker_find(filename);
// Entry for this driver does not exist, create one.
if (stat == NULL) {
stat = sleep_tracker_add(stripped_path);
stat = sleep_tracker_add(filename);
}
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)
{
const char* const stripped_path = strip_path(filename);
sleep_statistic_t* stat = sleep_tracker_find(stripped_path);
sleep_statistic_t *stat = sleep_tracker_find(filename);
// Entry for this driver does not exist, something went wrong.
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;
}
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

View File

@ -68,18 +68,18 @@ extern "C" {
void sleep_tracker_lock(const char *const filename, int line);
void sleep_tracker_unlock(const char *const filename, int line);
#define sleep_manager_lock_deep_sleep() \
do \
{ \
sleep_manager_lock_deep_sleep_internal(); \
sleep_tracker_lock(__FILE__, __LINE__); \
#define sleep_manager_lock_deep_sleep() \
do \
{ \
sleep_manager_lock_deep_sleep_internal(); \
sleep_tracker_lock(MBED_FILENAME, __LINE__); \
} while (0);
#define sleep_manager_unlock_deep_sleep() \
do \
{ \
sleep_manager_unlock_deep_sleep_internal(); \
sleep_tracker_unlock(__FILE__, __LINE__); \
#define sleep_manager_unlock_deep_sleep() \
do \
{ \
sleep_manager_unlock_deep_sleep_internal(); \
sleep_tracker_unlock(MBED_FILENAME, __LINE__); \
} while (0);
#else
@ -121,7 +121,6 @@ void sleep_manager_unlock_deep_sleep_internal(void);
*/
bool sleep_manager_can_deep_sleep(void);
/** Enter auto selected sleep mode. It chooses the sleep or deeepsleep modes based
* on the deepsleep locking counter
*

View File

@ -376,13 +376,27 @@
#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
#if defined(TOOLCHAIN_ARM)
#include <rt_sys.h>
#endif
#ifndef FILEHANDLE
typedef int FILEHANDLE;
typedef int FILEHANDLE;
#endif
// Backwards compatibility