Skip to content

Fix sleep tracing not finding matching driver during unlock. #9685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Feb 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions platform/mbed_sleep_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,28 @@ us_timestamp_t mbed_time_deepsleep(void)

#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 {
const char *identifier;
char identifier[IDENTIFIER_WIDTH];
uint8_t count;
} sleep_statistic_t;

static sleep_statistic_t sleep_stats[STATISTIC_COUNT];

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 (sleep_stats[i].identifier == filename) {
if (strcmp(sleep_stats[i].identifier, temp) == 0) {
return &sleep_stats[i];
}
}
Expand All @@ -96,9 +104,15 @@ 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 == NULL) {
sleep_stats[i].identifier = filename;
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();

return &sleep_stats[i];
}
Expand All @@ -117,7 +131,7 @@ static void sleep_tracker_print_stats(void)
continue;
}

if (sleep_stats[i].identifier == NULL) {
if (sleep_stats[i].identifier[0] == '\0') {
return;
}

Expand Down