56
56
# define LOAD_FRAC (x ) (LOAD_INT(((x) & (FIXED_1 - 1)) * 100))
57
57
#endif
58
58
59
+ #if CONFIG_MM_BACKTRACE >= 0 && !defined(CONFIG_NSH_DISABLE_PSHEAPUSAGE )
60
+ # define PS_SHOW_HEAPSIZE
61
+ #endif
62
+
63
+ #ifndef CONFIG_NSH_DISABLE_PSSTACKUSAGE
64
+ # define PS_SHOW_STACKSIZE
65
+ # ifdef CONFIG_STACK_COLORATION
66
+ # define PS_SHOW_STACKUSAGE
67
+ # endif
68
+ #endif
69
+
59
70
/****************************************************************************
60
71
* Private Types
61
72
****************************************************************************/
@@ -341,17 +352,20 @@ static int ps_callback(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
341
352
342
353
/* Finally, print the status information */
343
354
344
- nsh_output (vtbl , "%5s " , entryp -> d_name );
345
- nsh_output (vtbl , "%5s " , status .td_groupid );
346
-
355
+ nsh_output (vtbl ,
356
+ "%5s %5s "
347
357
#ifdef CONFIG_SMP
348
- nsh_output ( vtbl , "%3s " , status . td_cpu );
358
+ "%3s "
349
359
#endif
350
360
351
- nsh_output (vtbl , "%3s %-8s %-7s %3s %-8s %-9s " ,
361
+ "%3s %-8s %-7s %3s %-8s %-9s %-8s " ,
362
+ entryp -> d_name , status .td_groupid ,
363
+ #ifdef CONFIG_SMP
364
+ status .td_cpu ,
365
+ #endif
352
366
status .td_priority , status .td_policy , status .td_type ,
353
- status .td_flags , status .td_state , status .td_event );
354
- nsh_output ( vtbl , "%-8s " , status .td_sigmask );
367
+ status .td_flags , status .td_state , status .td_event ,
368
+ status .td_sigmask );
355
369
356
370
#if CONFIG_MM_BACKTRACE >= 0 && !defined(CONFIG_NSH_DISABLE_PSHEAPUSAGE )
357
371
/* Get the Heap AllocSize */
@@ -412,7 +426,6 @@ static int ps_callback(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
412
426
}
413
427
}
414
428
415
- nsh_output (vtbl , "%08lu " , heap_size );
416
429
#endif
417
430
418
431
#if !defined(CONFIG_NSH_DISABLE_PSSTACKUSAGE )
@@ -480,23 +493,14 @@ static int ps_callback(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
480
493
}
481
494
}
482
495
483
- nsh_output (vtbl , "%06lu " , stack_size );
484
-
485
496
#ifdef CONFIG_STACK_COLORATION
486
- nsh_output (vtbl , "%06lu " , stack_used );
487
497
488
498
if (stack_size > 0 && stack_used > 0 )
489
499
{
490
500
/* Use fixed-point math with one decimal place */
491
501
492
502
stack_filled = 10 * 100 * stack_used / stack_size ;
493
503
}
494
-
495
- /* Additionally print a '!' if the stack is filled more than 80% */
496
-
497
- nsh_output (vtbl , "%3lu.%lu%%%c " ,
498
- stack_filled / 10 , stack_filled % 10 ,
499
- (stack_filled >= 10 * 80 ? '!' : ' ' ));
500
504
#endif
501
505
#endif
502
506
@@ -520,8 +524,40 @@ static int ps_callback(FAR struct nsh_vtbl_s *vtbl, FAR const char *dirpath,
520
524
vtbl -> iobuffer [0 ] = '\0' ;
521
525
}
522
526
}
527
+ #endif
523
528
524
- nsh_output (vtbl , "%6s " , nsh_trimspaces (vtbl -> iobuffer ));
529
+ #if defined(PS_SHOW_HEAPSIZE ) || defined (PS_SHOW_STACKSIZE ) || \
530
+ defined (PS_SHOW_STACKUSAGE ) || defined (NSH_HAVE_CPULOAD )
531
+ nsh_output (vtbl ,
532
+ #ifdef PS_SHOW_HEAPSIZE
533
+ "%08lu "
534
+ #endif
535
+ #ifdef PS_SHOW_STACKSIZE
536
+ "%06lu "
537
+ #endif
538
+ #ifdef PS_SHOW_STACKUSAGE
539
+ "%06lu "
540
+ "%3lu.%lu%%%c "
541
+ #endif
542
+ #ifdef NSH_HAVE_CPULOAD
543
+ "%6s "
544
+ #endif
545
+ #if CONFIG_MM_BACKTRACE >= 0 && !defined (CONFIG_NSH_DISABLE_PSHEAPUSAGE )
546
+ , heap_size
547
+ #endif
548
+ #if !defined (CONFIG_NSH_DISABLE_PSSTACKUSAGE )
549
+ , stack_size
550
+ #endif
551
+ #ifdef PS_SHOW_STACKUSAGE
552
+ , stack_used ,
553
+ stack_filled / 10 ,
554
+ stack_filled % 10 ,
555
+ (stack_filled >= 10 * 80 ? '!' : ' ' )
556
+ #endif
557
+ #ifdef NSH_HAVE_CPULOAD
558
+ , nsh_trimspaces (vtbl -> iobuffer )
559
+ #endif
560
+ );
525
561
#endif
526
562
527
563
/* Read the task/thread command line */
@@ -586,33 +622,47 @@ int cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
586
622
UNUSED (argc );
587
623
UNUSED (argv );
588
624
589
- nsh_output (vtbl , "%5s " , "PID" );
590
- nsh_output (vtbl , "%5s " , "GROUP" );
591
-
625
+ nsh_output (vtbl , "%5s %5s "
592
626
#ifdef CONFIG_SMP
593
- nsh_output ( vtbl , "%3s " , "CPU" );
627
+ "%3s "
594
628
#endif
595
-
596
- nsh_output (vtbl , "%3s %-8s %-7s %3s %-8s %-9s " ,
597
- "PRI" , "POLICY" , "TYPE" , "NPX" , "STATE" , "EVENT" );
598
- nsh_output (vtbl , "%-8s " , "SIGMASK" );
599
-
629
+ "%3s %-8s %-7s %3s %-8s %-9s "
630
+ "%-8s "
600
631
#if CONFIG_MM_BACKTRACE >= 0 && !defined (CONFIG_NSH_DISABLE_PSHEAPUSAGE )
601
- nsh_output ( vtbl , "%8s " , "HEAP" );
632
+ "%8s "
602
633
#endif
603
-
604
634
#if !defined (CONFIG_NSH_DISABLE_PSSTACKUSAGE )
605
- nsh_output ( vtbl , "%6s " , "STACK" );
635
+ "%6s "
606
636
#ifdef CONFIG_STACK_COLORATION
607
- nsh_output (vtbl , "%6s " , "USED" );
608
- nsh_output (vtbl , "%7s " , "FILLED" );
637
+ "%6s "
638
+ "%7s "
639
+ #endif
640
+ #endif
641
+ #ifdef NSH_HAVE_CPULOAD
642
+ "%6s "
643
+ #endif
644
+ "%s\n" ,
645
+ "PID" , "GROUP" ,
646
+ #ifdef CONFIG_SMP
647
+ "CPU" ,
648
+ #endif
649
+ "PRI" , "POLICY" , "TYPE" , "NPX" , "STATE" , "EVENT" ,
650
+ "SIGMASK" ,
651
+ #if CONFIG_MM_BACKTRACE >= 0 && !defined (CONFIG_NSH_DISABLE_PSHEAPUSAGE )
652
+ "HEAP" ,
653
+ #endif
654
+ #if !defined (CONFIG_NSH_DISABLE_PSSTACKUSAGE )
655
+ "STACK" ,
656
+ #ifdef CONFIG_STACK_COLORATION
657
+ "USED" ,
658
+ "FILLED" ,
609
659
#endif
610
660
#endif
611
-
612
661
#ifdef NSH_HAVE_CPULOAD
613
- nsh_output ( vtbl , "%6s " , "CPU" );
662
+ "CPU" ,
614
663
#endif
615
- nsh_output (vtbl , "%s\n" , "COMMAND" );
664
+ "COMMAND"
665
+ );
616
666
617
667
return nsh_foreach_direntry (vtbl , "ps" , CONFIG_NSH_PROC_MOUNTPOINT ,
618
668
ps_callback , NULL );
0 commit comments