@@ -184,8 +184,13 @@ impl Spawner {
184
184
185
185
/// Extension trait adding tracing capabilities to the Spawner
186
186
///
187
- /// This trait provides an additional method to spawn tasks with an associated name,
188
- /// which can be useful for debugging and tracing purposes.
187
+ /// This trait provides additional methods to spawn tasks with tracing controls.
188
+ ///
189
+ /// **Default workflow** (`rtos-trace` feature): All tasks are traced by default.
190
+ /// You can use `spawn_no_trace()` methods to exclude specific tasks.
191
+ ///
192
+ /// **Selective workflow** (`rtos-trace-selective` feature): No tasks are traced by default.
193
+ /// You must use `spawn_with_trace()` methods to include specific tasks.
189
194
pub trait SpawnerTraceExt {
190
195
/// Spawns a new task with a specified name.
191
196
///
@@ -196,6 +201,50 @@ pub trait SpawnerTraceExt {
196
201
/// # Returns
197
202
/// Result indicating whether the spawn was successful
198
203
fn spawn_named < S > ( & self , name : & ' static str , token : SpawnToken < S > ) -> Result < ( ) , SpawnError > ;
204
+
205
+ /// Spawns a new task and explicitly enables it for tracing.
206
+ ///
207
+ /// **In default mode** (`rtos-trace`): This behaves the same as `spawn()` since all tasks are traced.
208
+ /// **In selective mode** (`rtos-trace-selective`): Only tasks spawned with this method will be traced.
209
+ ///
210
+ /// # Arguments
211
+ /// * `token` - Token representing the task to spawn
212
+ ///
213
+ /// # Returns
214
+ /// Result indicating whether the spawn was successful
215
+ fn spawn_with_trace < S > ( & self , token : SpawnToken < S > ) -> Result < ( ) , SpawnError > ;
216
+
217
+ /// Spawns a new task with a name and explicitly enables it for tracing.
218
+ ///
219
+ /// # Arguments
220
+ /// * `name` - Static string name to associate with the task
221
+ /// * `token` - Token representing the task to spawn
222
+ ///
223
+ /// # Returns
224
+ /// Result indicating whether the spawn was successful
225
+ fn spawn_named_with_trace < S > ( & self , name : & ' static str , token : SpawnToken < S > ) -> Result < ( ) , SpawnError > ;
226
+
227
+ /// Spawns a new task and excludes it from tracing.
228
+ ///
229
+ /// **In default mode** (`rtos-trace`): Use this to exclude specific tasks from tracing.
230
+ /// **In selective mode** (`rtos-trace-selective`): This behaves the same as `spawn()` since tasks are excluded by default.
231
+ ///
232
+ /// # Arguments
233
+ /// * `token` - Token representing the task to spawn
234
+ ///
235
+ /// # Returns
236
+ /// Result indicating whether the spawn was successful
237
+ fn spawn_no_trace < S > ( & self , token : SpawnToken < S > ) -> Result < ( ) , SpawnError > ;
238
+
239
+ /// Spawns a new task with a name but excludes it from tracing.
240
+ ///
241
+ /// # Arguments
242
+ /// * `name` - Static string name to associate with the task
243
+ /// * `token` - Token representing the task to spawn
244
+ ///
245
+ /// # Returns
246
+ /// Result indicating whether the spawn was successful
247
+ fn spawn_named_no_trace < S > ( & self , name : & ' static str , token : SpawnToken < S > ) -> Result < ( ) , SpawnError > ;
199
248
}
200
249
201
250
/// Implementation of the SpawnerTraceExt trait for Spawner when trace is enabled
@@ -212,6 +261,87 @@ impl SpawnerTraceExt for Spawner {
212
261
let task_id = task. as_ptr ( ) as u32 ;
213
262
task. set_id ( task_id) ;
214
263
264
+ // In selective mode, tasks are excluded by default (must use spawn_named_with_trace)
265
+ // In default mode, all tasks are traced
266
+ #[ cfg( feature = "rtos-trace-selective" ) ]
267
+ task. set_trace_excluded ( true ) ;
268
+ #[ cfg( not( feature = "rtos-trace-selective" ) ) ]
269
+ task. set_trace_excluded ( false ) ;
270
+
271
+ unsafe { self . executor . spawn ( task) } ;
272
+ Ok ( ( ) )
273
+ }
274
+ None => Err ( SpawnError :: Busy ) ,
275
+ }
276
+ }
277
+
278
+ fn spawn_with_trace < S > ( & self , token : SpawnToken < S > ) -> Result < ( ) , SpawnError > {
279
+ let task = token. raw_task ;
280
+ core:: mem:: forget ( token) ;
281
+
282
+ match task {
283
+ Some ( task) => {
284
+ // Explicitly enable tracing for this task
285
+ task. set_trace_excluded ( false ) ;
286
+ let task_id = task. as_ptr ( ) as u32 ;
287
+ task. set_id ( task_id) ;
288
+
289
+ unsafe { self . executor . spawn ( task) } ;
290
+ Ok ( ( ) )
291
+ }
292
+ None => Err ( SpawnError :: Busy ) ,
293
+ }
294
+ }
295
+
296
+ fn spawn_named_with_trace < S > ( & self , name : & ' static str , token : SpawnToken < S > ) -> Result < ( ) , SpawnError > {
297
+ let task = token. raw_task ;
298
+ core:: mem:: forget ( token) ;
299
+
300
+ match task {
301
+ Some ( task) => {
302
+ // Set the name and explicitly enable tracing
303
+ task. set_name ( Some ( name) ) ;
304
+ let task_id = task. as_ptr ( ) as u32 ;
305
+ task. set_id ( task_id) ;
306
+ task. set_trace_excluded ( false ) ;
307
+
308
+ unsafe { self . executor . spawn ( task) } ;
309
+ Ok ( ( ) )
310
+ }
311
+ None => Err ( SpawnError :: Busy ) ,
312
+ }
313
+ }
314
+
315
+ fn spawn_no_trace < S > ( & self , token : SpawnToken < S > ) -> Result < ( ) , SpawnError > {
316
+ let task = token. raw_task ;
317
+ core:: mem:: forget ( token) ;
318
+
319
+ match task {
320
+ Some ( task) => {
321
+ // Explicitly exclude this task from tracing
322
+ task. set_trace_excluded ( true ) ;
323
+ let task_id = task. as_ptr ( ) as u32 ;
324
+ task. set_id ( task_id) ;
325
+
326
+ unsafe { self . executor . spawn ( task) } ;
327
+ Ok ( ( ) )
328
+ }
329
+ None => Err ( SpawnError :: Busy ) ,
330
+ }
331
+ }
332
+
333
+ fn spawn_named_no_trace < S > ( & self , name : & ' static str , token : SpawnToken < S > ) -> Result < ( ) , SpawnError > {
334
+ let task = token. raw_task ;
335
+ core:: mem:: forget ( token) ;
336
+
337
+ match task {
338
+ Some ( task) => {
339
+ // Set the name but exclude from tracing
340
+ task. set_name ( Some ( name) ) ;
341
+ let task_id = task. as_ptr ( ) as u32 ;
342
+ task. set_id ( task_id) ;
343
+ task. set_trace_excluded ( true ) ;
344
+
215
345
unsafe { self . executor . spawn ( task) } ;
216
346
Ok ( ( ) )
217
347
}
@@ -227,6 +357,26 @@ impl SpawnerTraceExt for Spawner {
227
357
// When trace is disabled, just forward to regular spawn and ignore the name
228
358
self . spawn ( token)
229
359
}
360
+
361
+ fn spawn_with_trace < S > ( & self , token : SpawnToken < S > ) -> Result < ( ) , SpawnError > {
362
+ // When trace is disabled, just forward to regular spawn
363
+ self . spawn ( token)
364
+ }
365
+
366
+ fn spawn_named_with_trace < S > ( & self , _name : & ' static str , token : SpawnToken < S > ) -> Result < ( ) , SpawnError > {
367
+ // When trace is disabled, just forward to regular spawn and ignore the name
368
+ self . spawn ( token)
369
+ }
370
+
371
+ fn spawn_no_trace < S > ( & self , token : SpawnToken < S > ) -> Result < ( ) , SpawnError > {
372
+ // When trace is disabled, just forward to regular spawn
373
+ self . spawn ( token)
374
+ }
375
+
376
+ fn spawn_named_no_trace < S > ( & self , _name : & ' static str , token : SpawnToken < S > ) -> Result < ( ) , SpawnError > {
377
+ // When trace is disabled, just forward to regular spawn and ignore the name
378
+ self . spawn ( token)
379
+ }
230
380
}
231
381
232
382
/// Handle to spawn tasks into an executor from any thread.
0 commit comments