@@ -30,44 +30,20 @@ static uint16_t deep_sleep_lock = 0U;
30
30
31
31
#ifdef MBED_SLEEP_TRACING_ENABLED
32
32
33
- // Length of the identifier extracted from the driver name to store for logging.
34
- #define IDENTIFIER_WIDTH 15
35
33
// Number of drivers that can be stored in the structure
36
34
#define STATISTIC_COUNT 10
37
35
38
36
typedef struct sleep_statistic {
39
- char identifier [ IDENTIFIER_WIDTH ] ;
37
+ const char * identifier ;
40
38
uint8_t count ;
41
39
} sleep_statistic_t ;
42
40
43
41
static sleep_statistic_t sleep_stats [STATISTIC_COUNT ];
44
42
45
- static const char * strip_path (const char * const filename )
46
- {
47
- char * output = strrchr (filename , '/' );
48
-
49
- if (output != NULL ) {
50
- return output + 1 ;
51
- }
52
-
53
- output = strrchr (filename , '\\' );
54
-
55
- if (output != NULL ) {
56
- return output + 1 ;
57
- }
58
-
59
- return filename ;
60
- }
61
-
62
43
static sleep_statistic_t * sleep_tracker_find (const char * const filename )
63
44
{
64
- char temp [IDENTIFIER_WIDTH ];
65
- strncpy (temp , filename , IDENTIFIER_WIDTH );
66
- temp [IDENTIFIER_WIDTH - 1 ] = '\0' ;
67
-
68
- // Search for the a driver matching the current name and return it's index
69
45
for (int i = 0 ; i < STATISTIC_COUNT ; ++ i ) {
70
- if (strcmp ( sleep_stats [i ].identifier , temp ) == 0 ) {
46
+ if (sleep_stats [i ].identifier == filename ) {
71
47
return & sleep_stats [i ];
72
48
}
73
49
}
@@ -77,15 +53,9 @@ static sleep_statistic_t* sleep_tracker_find(const char *const filename)
77
53
78
54
static sleep_statistic_t * sleep_tracker_add (const char * const filename )
79
55
{
80
- char temp [IDENTIFIER_WIDTH ];
81
- strncpy (temp , filename , IDENTIFIER_WIDTH );
82
- temp [IDENTIFIER_WIDTH - 1 ] = '\0' ;
83
-
84
56
for (int i = 0 ; i < STATISTIC_COUNT ; ++ i ) {
85
- if (sleep_stats [i ].identifier [0 ] == '\0' ) {
86
- core_util_critical_section_enter ();
87
- strncpy (sleep_stats [i ].identifier , temp , sizeof (temp ));
88
- core_util_critical_section_exit ();
57
+ if (sleep_stats [i ].identifier == NULL ) {
58
+ sleep_stats [i ].identifier = filename ;
89
59
90
60
return & sleep_stats [i ];
91
61
}
@@ -104,45 +74,42 @@ static void sleep_tracker_print_stats(void)
104
74
continue ;
105
75
}
106
76
107
- if (sleep_stats [i ].identifier [ 0 ] == '\0' ) {
77
+ if (sleep_stats [i ].identifier == NULL ) {
108
78
return ;
109
79
}
110
80
111
81
debug ("[id: %s, count: %u]\r\n" , sleep_stats [i ].identifier ,
112
- sleep_stats [i ].count );
82
+ sleep_stats [i ].count );
113
83
}
114
84
}
115
85
116
86
void sleep_tracker_lock (const char * const filename , int line )
117
87
{
118
- const char * const stripped_path = strip_path (filename );
119
-
120
- sleep_statistic_t * stat = sleep_tracker_find (stripped_path );
88
+ sleep_statistic_t * stat = sleep_tracker_find (filename );
121
89
122
90
// Entry for this driver does not exist, create one.
123
91
if (stat == NULL ) {
124
- stat = sleep_tracker_add (stripped_path );
92
+ stat = sleep_tracker_add (filename );
125
93
}
126
94
127
95
core_util_atomic_incr_u8 (& stat -> count , 1 );
128
96
129
- debug ("LOCK: %s, ln: %i, lock count: %u\r\n" , stripped_path , line , deep_sleep_lock );
97
+ debug ("LOCK: %s, ln: %i, lock count: %u\r\n" , filename , line , deep_sleep_lock );
130
98
}
131
99
132
100
void sleep_tracker_unlock (const char * const filename , int line )
133
101
{
134
- const char * const stripped_path = strip_path (filename );
135
- sleep_statistic_t * stat = sleep_tracker_find (stripped_path );
102
+ sleep_statistic_t * stat = sleep_tracker_find (filename );
136
103
137
104
// Entry for this driver does not exist, something went wrong.
138
105
if (stat == NULL ) {
139
- debug ("Unlocking sleep for driver that was not previously locked: %s, ln: %i\r\n" , stripped_path , line );
106
+ debug ("Unlocking sleep for driver that was not previously locked: %s, ln: %i\r\n" , filename , line );
140
107
return ;
141
108
}
142
109
143
110
core_util_atomic_decr_u8 (& stat -> count , 1 );
144
111
145
- debug ("UNLOCK: %s, ln: %i, lock count: %u\r\n" , stripped_path , line , deep_sleep_lock );
112
+ debug ("UNLOCK: %s, ln: %i, lock count: %u\r\n" , filename , line , deep_sleep_lock );
146
113
}
147
114
148
115
#endif // MBED_SLEEP_TRACING_ENABLED
0 commit comments