Changeset 1374fd3 in rtems


Ignore:
Timestamp:
Aug 17, 2007, 12:54:16 AM (13 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
8db468f
Parents:
f41dd23
Message:

2007-08-17 Chris Johns <chrisj@…>

  • libmisc/capture/README: Minor copyright change.
  • libmisc/capture/capture-cli.c, libmisc/capture/capture.c, libmisc/capture/capture.h: Fixed the memory leak when lots of tasks are being created and deleted. Improved the trigger interface so all task type actions can be caught.
Location:
cpukit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    rf41dd23 r1374fd3  
     12007-08-17      Chris Johns <chrisj@rtems.org>
     2        * libmisc/capture/README: Minor copyright change.
     3        * libmisc/capture/capture-cli.c, libmisc/capture/capture.c,
     4        libmisc/capture/capture.h: Fixed the memory leak when lots of
     5        tasks are being created and deleted. Improved the trigger
     6        interface so all task type actions can be caught.
     7
    182007-08-13      Chris Johns <chrisj@rtems.org>
    29        * score/include/rtems/score/object.h: Point the
  • cpukit/libmisc/capture/README

    rf41dd23 r1374fd3  
    55          RTEMS Performance Monitoring and Measurement Framework
    66
    7                                       Copyright 2002 Chris Johns (ccj@acm.org)
     7                              Copyright 2002-2007 Chris Johns (chrisj@rtems.org)
    88                                                                 23 April 2002
    99
  • cpukit/libmisc/capture/capture-cli.c

    rf41dd23 r1374fd3  
    3939#include <rtems/monitor.h>
    4040
    41 #define RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS (32)
     41#define RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS (20)
    4242
    4343/*
     
    6464
    6565static void
    66 rtems_capture_cli_open (
    67   int argc,
    68   char **argv,
    69   rtems_monitor_command_arg_t *command_arg,
    70   boolean verbose )
    71 {
    72   uint32_t    size = 0;
     66rtems_capture_cli_open (int                          argc,
     67                        char**                       argv,
     68                        rtems_monitor_command_arg_t* command_arg,
     69                        boolean                      verbose)
     70{
     71  uint32_t          size = 0;
    7372  rtems_boolean     enable = 0;
    7473  rtems_status_code sc;
     
    7776  if (argc <= 1)
    7877  {
    79     fprintf(stdout,open_usage);
     78    fprintf (stdout, open_usage);
    8079    return;
    8180  }
     
    8887        enable = 1;
    8988      else
    90         fprintf(stdout,"warning: option -%c ignored\n", argv[arg][1]);
     89        fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
    9190    }
    9291    else
     
    9695      if (size < 100)
    9796      {
    98         fprintf(stdout,"error: size must be greater than or equal to 100\n");
     97        fprintf (stdout, "error: size must be greater than or equal to 100\n");
    9998        return;
    10099      }
     
    106105  if (sc != RTEMS_SUCCESSFUL)
    107106  {
    108     fprintf(stdout,"error: open failed: %s\n", rtems_status_text (sc));
    109     return;
    110   }
    111 
    112   fprintf(stdout,"capture engine opened.\n");
     107    fprintf (stdout, "error: open failed: %s\n", rtems_status_text (sc));
     108    return;
     109  }
     110
     111  fprintf (stdout, "capture engine opened.\n");
    113112
    114113  if (!enable)
     
    119118  if (sc != RTEMS_SUCCESSFUL)
    120119  {
    121     fprintf(stdout,"error: open enable failed: %s\n", rtems_status_text (sc));
    122     return;
    123   }
    124 
    125   fprintf(stdout,"capture engine enabled.\n");
     120    fprintf (stdout, "error: open enable failed: %s\n", rtems_status_text (sc));
     121    return;
     122  }
     123
     124  fprintf (stdout, "capture engine enabled.\n");
    126125}
    127126
     
    136135
    137136static void
    138 rtems_capture_cli_close (
    139   int argc,
    140   char **argv,
    141   rtems_monitor_command_arg_t *command_arg,
    142   boolean verbose )
     137rtems_capture_cli_close (int                          argc,
     138                         char**                       argv,
     139                         rtems_monitor_command_arg_t* command_arg,
     140                         boolean                      verbose)
    143141{
    144142  rtems_status_code sc;
     
    148146  if (sc != RTEMS_SUCCESSFUL)
    149147  {
    150     fprintf(stdout,"error: close failed: %s\n", rtems_status_text (sc));
    151     return;
    152   }
    153 
    154   fprintf(stdout,"capture engine closed.\n");
     148    fprintf (stdout, "error: close failed: %s\n", rtems_status_text (sc));
     149    return;
     150  }
     151
     152  fprintf (stdout, "capture engine closed.\n");
    155153}
    156154
     
    165163
    166164static void
    167 rtems_capture_cli_enable (
    168   int argc,
    169   char **argv,
    170   rtems_monitor_command_arg_t *command_arg,
    171   boolean verbose )
     165rtems_capture_cli_enable (int                          argc,
     166                          char**                       argv,
     167                          rtems_monitor_command_arg_t* command_arg,
     168                          boolean                      verbose)
    172169{
    173170  rtems_status_code sc;
     
    177174  if (sc != RTEMS_SUCCESSFUL)
    178175  {
    179     fprintf(stdout,"error: enable failed: %s\n", rtems_status_text (sc));
    180     return;
    181   }
    182 
    183   fprintf(stdout,"capture engine enabled.\n");
     176    fprintf (stdout, "error: enable failed: %s\n", rtems_status_text (sc));
     177    return;
     178  }
     179
     180  fprintf (stdout, "capture engine enabled.\n");
    184181}
    185182
     
    194191
    195192static void
    196 rtems_capture_cli_disable (
    197   int argc,
    198   char **argv,
    199   rtems_monitor_command_arg_t *command_arg,
    200   boolean verbose )
     193rtems_capture_cli_disable (int                          argc,
     194                           char**                       argv,
     195                           rtems_monitor_command_arg_t* command_arg,
     196                           boolean                      verbose)
    201197{
    202198  rtems_status_code sc;
     
    206202  if (sc != RTEMS_SUCCESSFUL)
    207203  {
    208     fprintf(stdout,"error: disable failed: %s\n", rtems_status_text (sc));
    209     return;
    210   }
    211 
    212   fprintf(stdout,"capture engine disabled.\n");
     204    fprintf (stdout, "error: disable failed: %s\n", rtems_status_text (sc));
     205    return;
     206  }
     207
     208  fprintf (stdout, "capture engine disabled.\n");
    213209}
    214210
     
    223219
    224220static void
    225 rtems_capture_cli_task_list (
    226   int argc,
    227   char **argv,
    228   rtems_monitor_command_arg_t *command_arg,
    229   boolean verbose )
     221rtems_capture_cli_task_list (int                          argc,
     222                             char**                       argv,
     223                             rtems_monitor_command_arg_t* command_arg,
     224                             boolean                      verbose)
    230225{
    231226  rtems_task_priority   ceiling = rtems_capture_watch_get_ceiling ();
    232227  rtems_task_priority   floor = rtems_capture_watch_get_floor ();
    233228  rtems_capture_task_t* task = rtems_capture_get_task_list ();
    234   uint32_t        ticks;
    235   uint32_t        tick_offset;
     229  uint32_t              ticks;
     230  uint32_t              tick_offset;
    236231  unsigned long long    total_time;
    237232  int                   count = rtems_capture_task_count ();
     
    245240  }
    246241
    247   total_time = (ticks * rtems_capture_task_time (task)) + tick_offset;
    248 
    249   fprintf(stdout,"total %i\n", count);
     242  fprintf (stdout, "total %i\n", count);
    250243
    251244  while (task)
     
    255248    int32_t             time_used;
    256249
    257     stack_used = rtems_capture_task_stack_usage (task) * 100;
    258     stack_used /= rtems_capture_task_stack_size (task);
     250    stack_used = rtems_capture_task_stack_usage (task);
     251    if (stack_used)
     252      stack_used = (stack_used * 100) / stack_used;
    259253
    260254    if (stack_used > 100)
    261255      stack_used = 100;
    262256
     257    total_time = (ticks * rtems_capture_task_time (task)) + tick_offset;
     258
    263259    time_used = (rtems_capture_task_time (task) * 100) / total_time;
    264260
     
    268264    priority = rtems_capture_task_real_priority (task);
    269265
    270     fprintf(stdout," ");
     266    fprintf (stdout, " ");
    271267    rtems_monitor_dump_id (rtems_capture_task_id (task));
    272     fprintf(stdout," ");
     268    fprintf (stdout, " ");
    273269    rtems_monitor_dump_name (rtems_capture_task_name (task));
    274     fprintf(stdout," ");
     270    fprintf (stdout, " ");
    275271    rtems_monitor_dump_priority (rtems_capture_task_start_priority (task));
    276     fprintf(stdout," ");
     272    fprintf (stdout, " ");
    277273    rtems_monitor_dump_priority (rtems_capture_task_real_priority (task));
    278     fprintf(stdout," ");
     274    fprintf (stdout, " ");
    279275    rtems_monitor_dump_priority (rtems_capture_task_curr_priority (task));
    280     fprintf(stdout," ");
     276    fprintf (stdout, " ");
    281277    rtems_monitor_dump_state (rtems_capture_task_state (task));
    282     fprintf(stdout," %c%c%c%c%c",
    283             rtems_capture_task_valid (task) ? 'a' : 'd',
    284             rtems_capture_task_flags (task) & RTEMS_CAPTURE_TRACED ? 't' : '-',
    285             rtems_capture_task_control_flags (task) & RTEMS_CAPTURE_TO_ANY ? 'F' : '-',
    286             rtems_capture_task_control_flags (task) & RTEMS_CAPTURE_FROM_ANY ? 'T' : '-',
    287             rtems_capture_task_control_flags (task) & RTEMS_CAPTURE_FROM_TO ? 'E' : '-');
     278    fprintf (stdout, " %c%c",
     279             rtems_capture_task_valid (task) ? 'a' : 'd',
     280             rtems_capture_task_flags (task) & RTEMS_CAPTURE_TRACED ? 't' : '-');
     281
    288282    if ((floor > ceiling) && (ceiling > priority))
    289       fprintf(stdout,"--");
     283      fprintf (stdout, "--");
    290284    else
    291       fprintf(stdout,"%c%c",
    292               rtems_capture_task_control (task) ?
    293               (rtems_capture_task_control_flags (task) & RTEMS_CAPTURE_WATCH ? 'w' : '+') : '-',
    294               rtems_capture_watch_global_on () ? 'g' : '-');
    295     fprintf(stdout," %3" PRId32 "%% %3" PRId32 "%% (%" PRIu32 ")\n",
     285    {
     286      uint32_t flags = rtems_capture_task_control_flags (task);
     287      fprintf (stdout, "%c%c",
     288               rtems_capture_task_control (task) ?
     289               (flags & RTEMS_CAPTURE_WATCH ? 'w' : '+') : '-',
     290               rtems_capture_watch_global_on () ? 'g' : '-');
     291    }
     292    fprintf (stdout, " %3" PRId32 "%% %3" PRId32 "%% (%" PRIu32 ")\n",
    296293            stack_used, time_used, rtems_capture_task_ticks (task));
    297294
     
    315312  rtems_task_priority floor = rtems_capture_watch_get_floor ();
    316313  int                 last_count = 0;
    317 
    318   fprintf(stdout,"\x1b[2J Press ENTER to exit.\n\n");
    319   fprintf(stdout,"     PID NAME RPRI CPRI STATE  %%CPU     %%STK FLGS   EXEC TIME\n");
    320 
     314 
    321315  for (;;)
    322316  {
     
    342336    task = rtems_capture_get_task_list ();
    343337
     338    total_time = 0;
     339
    344340    while (task)
    345341    {
     
    349345
    350346        count++;
     347
     348        total_time += l;
    351349
    352350        for (i = 0; i < RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS; i++)
     
    372370    }
    373371
    374     fprintf(stdout,"\x1b[4;0H");
    375 
    376     total_time = 0;
    377 
    378     for (i = 0; i < RTEMS_CAPTURE_CLI_MAX_LOAD_TASKS; i++)
    379       total_time += load[i];
     372    fprintf (stdout, "\x1b[H\x1b[J Press ENTER to exit.\n\n");
     373    fprintf (stdout,
     374             "     PID NAME RPRI CPRI STATE  %%CPU     %%STK FLGS    EXEC TIME\n");
    380375
    381376    if (count > last_count)
     
    396391      j--;
    397392
    398       stack_used = rtems_capture_task_stack_usage (tasks[i]) * 100;
    399       stack_used /= rtems_capture_task_stack_size (tasks[i]);
     393      stack_used = rtems_capture_task_stack_usage (tasks[i]);
     394      if (stack_used)
     395        stack_used = (stack_used * 100) / stack_used;
    400396
    401397      if (stack_used > 100)
     
    406402      priority = rtems_capture_task_real_priority (tasks[i]);
    407403
    408       fprintf(stdout,"\x1b[K");
     404      fprintf (stdout, "\x1b[K");
    409405      rtems_monitor_dump_id (rtems_capture_task_id (tasks[i]));
    410       fprintf(stdout," ");
     406      fprintf (stdout, " ");
    411407      rtems_monitor_dump_name (rtems_capture_task_name (tasks[i]));
    412       fprintf(stdout,"  ");
     408      fprintf (stdout, "  ");
    413409      rtems_monitor_dump_priority (priority);
    414       fprintf(stdout,"  ");
     410      fprintf (stdout, "  ");
    415411      rtems_monitor_dump_priority (rtems_capture_task_curr_priority (tasks[i]));
    416       fprintf(stdout," ");
     412      fprintf (stdout, " ");
    417413      k = rtems_monitor_dump_state (rtems_capture_task_state (tasks[i]));
    418       fprintf(stdout,"%*c %3i.%03i%% ", 6 - k, ' ', task_load / 1000, task_load % 1000);
    419       fprintf(stdout,"%3i%% %c%c%c%c%c", stack_used,
     414      fprintf (stdout, "%*c %3i.%03i%% ", 6 - k, ' ',
     415               task_load / 1000, task_load % 1000);
     416      fprintf (stdout, "%3i%% %c%c", stack_used,
    420417              rtems_capture_task_valid (tasks[i]) ? 'a' : 'd',
    421               rtems_capture_task_flags (tasks[i]) & RTEMS_CAPTURE_TRACED ? 't' : '-',
    422               rtems_capture_task_control_flags (tasks[i]) & RTEMS_CAPTURE_TO_ANY ? 'F' : '-',
    423               rtems_capture_task_control_flags (tasks[i]) & RTEMS_CAPTURE_FROM_ANY ? 'T' : '-',
    424               rtems_capture_task_control_flags (tasks[i]) & RTEMS_CAPTURE_FROM_TO ? 'E' : '-');
     418              rtems_capture_task_flags (tasks[i]) & RTEMS_CAPTURE_TRACED ? 't' : '-');
     419
    425420      if ((floor > ceiling) && (ceiling > priority))
    426         fprintf(stdout,"--");
     421        fprintf (stdout, "--");
    427422      else
    428         fprintf(stdout,"%c%c",
     423        fprintf (stdout, "%c%c",
    429424                rtems_capture_task_control (tasks[i]) ?
    430425                (rtems_capture_task_control_flags (tasks[i]) &
     
    432427                rtems_capture_watch_global_on () ? 'g' : '-');
    433428
    434       fprintf(stdout,"   %qi\n", rtems_capture_task_time (tasks[i]));
     429      fprintf (stdout, "   %qi\n", rtems_capture_task_time (tasks[i]));
    435430    }
    436431
     
    440435      while (j > 0)
    441436      {
    442         fprintf(stdout,"\x1b[K\n");
     437        fprintf (stdout, "\x1b[K\n");
    443438        j--;
    444439      }
     
    463458
    464459static void
    465 rtems_capture_cli_task_load (
    466   int argc,
    467   char **argv,
    468   rtems_monitor_command_arg_t *command_arg,
    469   boolean verbose )
     460rtems_capture_cli_task_load (int                          argc,
     461                             char**                       argv,
     462                             rtems_monitor_command_arg_t* command_arg,
     463                             boolean                      verbose)
    470464{
    471465  rtems_status_code   sc;
     
    478472  if (sc != RTEMS_SUCCESSFUL)
    479473  {
    480     fprintf(stdout,"error: cannot obtain the current priority: %s\n", rtems_status_text (sc));
    481     return;
    482   }
    483 
    484   memcpy (&name, "CPlt", 4);
    485 
    486   sc = rtems_task_create (name, priority, 1024,
     474    fprintf (stdout, "error: cannot obtain the current priority: %s\n",
     475             rtems_status_text (sc));
     476    return;
     477  }
     478
     479  name = rtems_build_name('C', 'P', 'l', 't');
     480 
     481  sc = rtems_task_create (name, priority, 4 * 1024,
    487482                          RTEMS_NO_FLOATING_POINT | RTEMS_LOCAL,
    488483                          RTEMS_PREEMPT | RTEMS_TIMESLICE | RTEMS_NO_ASR,
    489484                          &id);
     485 
     486  if (sc != RTEMS_SUCCESSFUL)
     487  {
     488    fprintf (stdout, "error: cannot create helper thread: %s\n",
     489             rtems_status_text (sc));
     490    return;
     491  }
     492
     493  sc = rtems_task_start (id, rtems_capture_cli_task_load_thread, 0);
    490494
    491495  if (sc != RTEMS_SUCCESSFUL)
    492496  {
    493     fprintf(stdout,"error: cannot create helper thread: %s\n", rtems_status_text (sc));
    494     return;
    495   }
    496 
    497   sc = rtems_task_start (id, rtems_capture_cli_task_load_thread, 0);
    498 
    499   if (sc != RTEMS_SUCCESSFUL)
    500   {
    501     fprintf(stdout,"error: cannot start helper thread: %s\n", rtems_status_text (sc));
     497    fprintf (stdout, "error: cannot start helper thread: %s\n",
     498             rtems_status_text (sc));
    502499    rtems_task_delete (id);
    503500    return;
     
    517514      rtems_task_delete (id);
    518515
    519       fprintf(stdout,"load monitoring stopped.\n");
     516      fprintf (stdout, "load monitoring stopped.\n");
    520517
    521518      return;
     
    534531
    535532static void
    536 rtems_capture_cli_watch_list (
    537   int argc,
    538   char **argv,
    539   rtems_monitor_command_arg_t *command_arg,
    540   boolean verbose )
     533rtems_capture_cli_watch_list (int                          argc,
     534                              char**                       argv,
     535                              rtems_monitor_command_arg_t* command_arg,
     536                              boolean                      verbose)
    541537{
    542538  rtems_capture_control_t* control = rtems_capture_get_control_list ();
     
    544540  rtems_task_priority      floor = rtems_capture_watch_get_floor ();
    545541
    546   fprintf(stdout,"watch priority ceiling is %" PRId32 "\n", ceiling);
    547   fprintf(stdout,"watch priority floor is %" PRId32 "\n", floor);
    548   fprintf(stdout,"global watch is %s\n",
     542  fprintf (stdout, "watch priority ceiling is %" PRId32 "\n", ceiling);
     543  fprintf (stdout, "watch priority floor is %" PRId32 "\n", floor);
     544  fprintf (stdout, "global watch is %s\n",
    549545          rtems_capture_watch_global_on () ? "enabled" : "disabled");
    550   fprintf(stdout,"total %" PRId32 "\n", rtems_capture_control_count ());
     546  fprintf (stdout, "total %" PRId32 "\n", rtems_capture_control_count ());
    551547
    552548  while (control)
    553549  {
    554     int f;
    555     int fshowed;
    556     int lf;
    557 
    558     fprintf(stdout," ");
     550    uint32_t flags;
     551    int      f;
     552    int      fshowed;
     553    int      lf;
     554
     555    fprintf (stdout, " ");
    559556    rtems_monitor_dump_id (rtems_capture_control_id (control));
    560     fprintf(stdout," ");
     557    fprintf (stdout, " ");
    561558    rtems_monitor_dump_name (rtems_capture_control_name (control));
    562     fprintf(stdout," %c%c%c%c%c",
    563             rtems_capture_control_flags (control) & RTEMS_CAPTURE_WATCH ? 'w' : '-',
    564             rtems_capture_watch_global_on () ? 'g' : '-',
    565             rtems_capture_control_flags (control) & RTEMS_CAPTURE_TO_ANY ? 'F' : '-',
    566             rtems_capture_control_flags (control) & RTEMS_CAPTURE_FROM_ANY ? 'T' : '-',
    567             rtems_capture_control_flags (control) & RTEMS_CAPTURE_FROM_TO ? 'E' : '-');
     559    flags = rtems_capture_control_flags (control);
     560    fprintf (stdout, " %c%c ",
     561             rtems_capture_watch_global_on () ? 'g' : '-',
     562             flags & RTEMS_CAPTURE_WATCH ? 'w' : '-');
     563    flags = rtems_capture_control_to_triggers (control);
     564    fprintf (stdout, " T:%c%c%c%c%c%c%c",
     565             flags & RTEMS_CAPTURE_SWITCH    ? 'S' : '-',
     566             flags & RTEMS_CAPTURE_CREATE ? 'C' : '-',
     567             flags & RTEMS_CAPTURE_START ? 'S' : '-',
     568             flags & RTEMS_CAPTURE_RESTART ? 'R' : '-',
     569             flags & RTEMS_CAPTURE_DELETE ? 'D' : '-',
     570             flags & RTEMS_CAPTURE_BEGIN ? 'B' : '-',
     571             flags & RTEMS_CAPTURE_EXITTED ? 'E' : '-');
     572    flags = rtems_capture_control_from_triggers (control);
     573    fprintf (stdout, " F:%c%c%c%c%c",
     574             flags & RTEMS_CAPTURE_SWITCH  ? 'S' : '-',
     575             flags & RTEMS_CAPTURE_CREATE  ? 'C' : '-',
     576             flags & RTEMS_CAPTURE_START   ? 'S' : '-',
     577             flags & RTEMS_CAPTURE_RESTART ? 'R' : '-',
     578             flags & RTEMS_CAPTURE_DELETE  ? 'D' : '-');
    568579
    569580    for (f = 0, fshowed = 0, lf = 1; f < RTEMS_CAPTURE_TRIGGER_TASKS; f++)
    570581    {
    571       if (lf && ((fshowed % 16) == 0))
     582      if (rtems_capture_control_by_valid (control, f))
    572583      {
    573         fprintf(stdout,"\n");
    574         lf = 0;
    575       }
    576 
    577       /*
    578        * FIXME: name test.
    579        */
    580       if (rtems_capture_control_from_name (control, f))
    581       {
    582         fprintf(stdout,"  %2i:", f);
    583         rtems_monitor_dump_name (rtems_capture_control_from_name (control, f));
    584         fprintf(stdout,"/");
    585         rtems_monitor_dump_id (rtems_capture_control_from_id (control, f));
     584        if (lf && ((fshowed % 3) == 0))
     585        {
     586          fprintf (stdout, "\n");
     587          lf = 0;
     588        }
     589
     590        fprintf (stdout, "  %2i:", f);
     591        rtems_monitor_dump_name (rtems_capture_control_by_name (control, f));
     592        fprintf (stdout, "/");
     593        rtems_monitor_dump_id (rtems_capture_control_by_id (control, f));
     594        flags = rtems_capture_control_by_triggers (control, f);
     595        fprintf (stdout, ":%c%c%c%c%c",
     596                 flags & RTEMS_CAPTURE_SWITCH  ? 'S' : '-',
     597                 flags & RTEMS_CAPTURE_CREATE  ? 'C' : '-',
     598                 flags & RTEMS_CAPTURE_START   ? 'S' : '-',
     599                 flags & RTEMS_CAPTURE_RESTART ? 'R' : '-',
     600                 flags & RTEMS_CAPTURE_DELETE  ? 'D' : '-');
    586601        fshowed++;
    587602        lf = 1;
     
    590605
    591606    if (lf)
    592       fprintf(stdout,"\n");
     607      fprintf (stdout, "\n");
    593608
    594609    control = rtems_capture_next_control (control);
     
    612627                               rtems_id*      id)
    613628{
    614   uint32_t   objclass;
    615   size_t     l;
    616   size_t     i;
     629  size_t l;
     630  size_t i;
    617631
    618632  if (*valid_name && *valid_id)
    619633  {
    620     fprintf(stdout,"error: too many arguments\n");
     634    fprintf (stdout, "error: too many arguments\n");
    621635    return 0;
    622636  }
     
    632646      break;
    633647
    634   *id = strtoul (arg, 0, 16);
    635 
    636   objclass = _Objects_Get_class (*id);
    637 
    638   if ((i == l))
     648  if (i == l)
     649  {
     650    *id = strtoul (arg, 0, 16);
    639651    *valid_id = 1;
     652  }
    640653  else
    641654  {
    642     memcpy (name, arg, sizeof (rtems_name));
     655    /*
     656     * This is a bit of hack but it should work on all platforms
     657     * as it is what the score does with names.
     658     *
     659     * @warning The extra assigns play with the byte order so do not
     660     *          remove unless the score has been updated.
     661     */
     662    Objects_Name object_name;
     663    rtems_name   rname;
     664   
     665    rname = rtems_build_name(arg[0], arg[1], arg[2], arg[3]);
     666    object_name = (Objects_Name) rname;
     667    *name = (rtems_name) object_name;
    643668    *valid_name = 1;
    644669  }
     
    660685
    661686static void
    662 rtems_capture_cli_watch_add (
    663   int argc,
    664   char **argv,
    665   rtems_monitor_command_arg_t *command_arg,
    666   boolean verbose )
     687rtems_capture_cli_watch_add (int                          argc,
     688                             char**                       argv,
     689                             rtems_monitor_command_arg_t* command_arg,
     690                             boolean                      verbose)
    667691{
    668692  rtems_status_code sc;
     
    675699  if (argc <= 1)
    676700  {
    677     fprintf(stdout,watch_add_usage);
     701    fprintf (stdout, watch_add_usage);
    678702    return;
    679703  }
     
    683707    if (argv[arg][0] == '-')
    684708    {
    685       fprintf(stdout,"warning: option -%c ignored\n", argv[arg][1]);
     709      fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
    686710    }
    687711    else
    688712    {
    689       if (!rtems_capture_cli_get_name_id (argv[arg], &valid_name, &valid_id, &name, &id))
     713      if (!rtems_capture_cli_get_name_id (argv[arg], &valid_name, &valid_id,
     714                                          &name, &id))
    690715        return;
    691716    }
     
    694719  if (!valid_name && !valid_id)
    695720  {
    696     fprintf(stdout,"error: no valid name or task id located\n");
     721    fprintf (stdout, "error: no valid name or task id located\n");
    697722    return;
    698723  }
     
    702727  if (sc != RTEMS_SUCCESSFUL)
    703728  {
    704     fprintf(stdout,"error: watch add failed: %s\n", rtems_status_text (sc));
    705     return;
    706   }
    707 
    708   fprintf(stdout,"watch added.\n");
     729    fprintf (stdout,
     730             "error: watch add failed: %s\n", rtems_status_text (sc));
     731    return;
     732  }
     733
     734  fprintf (stdout, "watch added.\n");
    709735}
    710736
     
    722748
    723749static void
    724 rtems_capture_cli_watch_del (
    725   int argc,
    726   char **argv,
    727   rtems_monitor_command_arg_t *command_arg,
    728   boolean verbose )
     750rtems_capture_cli_watch_del (int                          argc,
     751                             char**                       argv,
     752                             rtems_monitor_command_arg_t* command_arg,
     753                             boolean                      verbose)
    729754{
    730755  rtems_status_code sc;
     
    737762  if (argc <= 1)
    738763  {
    739     fprintf(stdout,watch_del_usage);
     764    fprintf (stdout, watch_del_usage);
    740765    return;
    741766  }
     
    745770    if (argv[arg][0] == '-')
    746771    {
    747       fprintf(stdout,"warning: option -%c ignored\n", argv[arg][1]);
     772      fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
    748773    }
    749774    else
    750775    {
    751       if (!rtems_capture_cli_get_name_id (argv[arg], &valid_name, &valid_id, &name, &id))
     776      if (!rtems_capture_cli_get_name_id (argv[arg], &valid_name, &valid_id,
     777                                          &name, &id))
    752778        return;
    753779    }
     
    756782  if (!valid_name && !valid_id)
    757783  {
    758     fprintf(stdout,"error: no valid name or task id located\n");
     784    fprintf (stdout, "error: no valid name or task id located\n");
    759785    return;
    760786  }
     
    764790  if (sc != RTEMS_SUCCESSFUL)
    765791  {
    766     fprintf(stdout,"error: watch delete failed: %s\n", rtems_status_text (sc));
    767     return;
    768   }
    769 
    770   fprintf(stdout,"watch delete.\n");
     792    fprintf (stdout, "error: watch delete failed: %s\n",
     793             rtems_status_text (sc));
     794    return;
     795  }
     796
     797  fprintf (stdout, "watch delete.\n");
    771798}
    772799
     
    783810
    784811static void
    785 rtems_capture_cli_watch_control (
    786   int argc,
    787   char **argv,
    788   rtems_monitor_command_arg_t *command_arg,
    789   boolean verbose )
     812rtems_capture_cli_watch_control (int                          argc,
     813                                 char**                       argv,
     814                                 rtems_monitor_command_arg_t* command_arg,
     815                                 boolean                      verbose)
    790816{
    791817  rtems_status_code sc;
     
    799825  if (argc <= 2)
    800826  {
    801     fprintf(stdout,watch_control_usage);
     827    fprintf (stdout, watch_control_usage);
    802828    return;
    803829  }
     
    807833    if (argv[arg][0] == '-')
    808834    {
    809       fprintf(stdout,"warning: option -%c ignored\n", argv[arg][1]);
     835      fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
    810836    }
    811837    else
     
    815841      else if (strcmp (argv[arg], "off") == 0)
    816842        enable = 0;
    817       else if (!rtems_capture_cli_get_name_id (argv[arg], &valid_name, &valid_id, &name, &id))
     843      else if (!rtems_capture_cli_get_name_id (argv[arg], &valid_name,
     844                                               &valid_id, &name, &id))
    818845        return;
    819846    }
     
    822849  if (!valid_name && !valid_id)
    823850  {
    824     fprintf(stdout,"error: no valid name or task id located\n");
     851    fprintf (stdout, "error: no valid name or task id located\n");
    825852    return;
    826853  }
     
    830857  if (sc != RTEMS_SUCCESSFUL)
    831858  {
    832     fprintf(stdout,"error: watch control failed: %s\n", rtems_status_text (sc));
    833     return;
    834   }
    835 
    836   fprintf(stdout,"watch %s.\n", enable ? "enabled" : "disabled");
     859    fprintf (stdout, "error: watch control failed: %s\n",
     860             rtems_status_text (sc));
     861    return;
     862  }
     863
     864  fprintf (stdout, "watch %s.\n", enable ? "enabled" : "disabled");
    837865}
    838866
     
    849877
    850878static void
    851 rtems_capture_cli_watch_global (
    852   int argc,
    853   char **argv,
    854   rtems_monitor_command_arg_t *command_arg,
    855   boolean verbose )
     879rtems_capture_cli_watch_global (int                          argc,
     880                                char**                       argv,
     881                                rtems_monitor_command_arg_t* command_arg,
     882                                boolean                      verbose)
    856883{
    857884  rtems_status_code sc;
     
    861888  if (argc <= 1)
    862889  {
    863     fprintf(stdout,watch_global_usage);
     890    fprintf (stdout, watch_global_usage);
    864891    return;
    865892  }
     
    869896    if (argv[arg][0] == '-')
    870897    {
    871       fprintf(stdout,"warning: option -%c ignored\n", argv[arg][1]);
     898      fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
    872899    }
    873900    else
     
    884911  if (sc != RTEMS_SUCCESSFUL)
    885912  {
    886     fprintf(stdout,"error: global watch failed: %s\n", rtems_status_text (sc));
    887     return;
    888   }
    889 
    890   fprintf(stdout,"global watch %s.\n", enable ? "enabled" : "disabled");
     913    fprintf (stdout, "error: global watch failed: %s\n",
     914             rtems_status_text (sc));
     915    return;
     916  }
     917
     918  fprintf (stdout, "global watch %s.\n", enable ? "enabled" : "disabled");
    891919}
    892920
     
    903931
    904932static void
    905 rtems_capture_cli_watch_ceiling (
    906   int argc,
    907   char **argv,
    908   rtems_monitor_command_arg_t *command_arg,
    909   boolean verbose )
     933rtems_capture_cli_watch_ceiling (int                          argc,
     934                                 char**                       argv,
     935                                 rtems_monitor_command_arg_t* command_arg,
     936                                 boolean                      verbose)
    910937{
    911938  rtems_status_code   sc;
     
    915942  if (argc <= 1)
    916943  {
    917     fprintf(stdout,watch_ceiling_usage);
     944    fprintf (stdout, watch_ceiling_usage);
    918945    return;
    919946  }
     
    923950    if (argv[arg][0] == '-')
    924951    {
    925       fprintf(stdout,"warning: option -%c ignored\n", argv[arg][1]);
     952      fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
    926953    }
    927954    else
     
    935962  if (sc != RTEMS_SUCCESSFUL)
    936963  {
    937     fprintf(stdout,"error: watch ceiling failed: %s\n", rtems_status_text (sc));
    938     return;
    939   }
    940 
    941   fprintf(stdout,"watch ceiling is %" PRId32 ".\n", priority);
     964    fprintf (stdout, "error: watch ceiling failed: %s\n",
     965             rtems_status_text (sc));
     966    return;
     967  }
     968
     969  fprintf (stdout, "watch ceiling is %" PRId32 ".\n", priority);
    942970}
    943971
     
    954982
    955983static void
    956 rtems_capture_cli_watch_floor (
    957   int argc,
    958   char **argv,
    959   rtems_monitor_command_arg_t *command_arg,
    960   boolean verbose )
     984rtems_capture_cli_watch_floor (int                          argc,
     985                               char**                       argv,
     986                               rtems_monitor_command_arg_t* command_arg,
     987                               boolean                      verbose)
    961988{
    962989  rtems_status_code   sc;
     
    966993  if (argc <= 1)
    967994  {
    968     fprintf(stdout,watch_floor_usage);
     995    fprintf (stdout, watch_floor_usage);
    969996    return;
    970997  }
     
    9741001    if (argv[arg][0] == '-')
    9751002    {
    976       fprintf(stdout,"warning: option -%c ignored\n", argv[arg][1]);
     1003      fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
    9771004    }
    9781005    else
     
    9861013  if (sc != RTEMS_SUCCESSFUL)
    9871014  {
    988     fprintf(stdout,"error: watch floor failed: %s\n", rtems_status_text (sc));
    989     return;
    990   }
    991 
    992   fprintf(stdout,"watch floor is %" PRId32 ".\n", priority);
    993 }
    994 
    995 /*
    996  * rtems_capture_cli_trigger_set
    997  *
    998  *  DESCRIPTION:
    999  *
    1000  * This function is a monitor command that sets a trigger.
    1001  *
    1002  */
    1003 
    1004 static char const *trigger_set_usage = "usage: ctrig type [from] [fromid] [to] [to id]\n";
    1005 
    1006 static void
    1007 rtems_capture_cli_trigger_set (
    1008   int argc,
    1009   char **argv,
    1010   rtems_monitor_command_arg_t *command_arg,
    1011   boolean verbose )
    1012 {
    1013   rtems_status_code       sc;
    1014   int                     arg;
    1015   rtems_capture_trigger_t trigger = rtems_capture_from_to;
    1016   rtems_boolean           trigger_set = 0;
    1017   rtems_name              name = 0;
    1018   rtems_id                id = 0;
    1019   rtems_boolean           valid_name = 0;
    1020   rtems_boolean           valid_id = 0;
    1021   rtems_name              from_name = 0;
    1022   rtems_id                from_id = 0;
    1023   rtems_boolean           from_valid_name = 0;
    1024   rtems_boolean           from_valid_id = 0;
    1025   rtems_name              to_name = 0;
    1026   rtems_id                to_id = 0;
    1027   rtems_boolean           to_valid_name = 0;
    1028   rtems_boolean           to_valid_id = 0;
    1029 
    1030   if (argc <= 2)
    1031   {
    1032     fprintf(stdout,trigger_set_usage);
    1033     return;
    1034   }
     1015    fprintf (stdout, "error: watch floor failed: %s\n",
     1016             rtems_status_text (sc));
     1017    return;
     1018  }
     1019
     1020  fprintf (stdout, "watch floor is %" PRId32 ".\n", priority);
     1021}
     1022
     1023/*
     1024 * rtems_capture_cli_trigger_worker
     1025 *
     1026 *  DESCRIPTION:
     1027 *
     1028 * This function is a monitor command that sets or clears a trigger.
     1029 *
     1030 */
     1031
     1032static char const *trigger_set_usage =
     1033      "usage: %s [-?] type [to name/id] [from] [from name/id]\n";
     1034
     1035static char const *trigger_set_types =
     1036      "  You can say 'type TASK' or 'type TO from FROM'\n" \
     1037      "  where TASK is the task the event is happening to\n" \
     1038      "  or you can say the event TO this task FROM this task.\n" \
     1039      "  No type defaults to 'switch'.\n" \
     1040      "   switch  : context switch TASK or FROM or FROM->TO\n" \
     1041      "   create  : create TASK, or create TO from FROM\n" \
     1042      "   start   : start TASK, or start TO from FROM\n" \
     1043      "   restart : restart TASK, or restart TO from FROM\n" \
     1044      "   delete  : delete TASK or delete TO from FROM\n" \
     1045      "   begin   : begin TASK\n" \
     1046      "   exitted : exitted TASK\n";
     1047
     1048/*
     1049 * Structure to handle the parsing of the trigger command line.
     1050 */
     1051typedef struct rtems_capture_cli_triggers_s
     1052{
     1053  char const *            name;
     1054  rtems_capture_trigger_t type;
     1055  int                     to_only;
     1056} rtems_capture_cli_triggers_t;
     1057
     1058static rtems_capture_cli_triggers_t rtems_capture_cli_triggers[] =
     1059{
     1060  { "switch",  rtems_capture_switch,  0 }, /* must be first */
     1061  { "create",  rtems_capture_create,  0 },
     1062  { "start",   rtems_capture_start,   0 },
     1063  { "restart", rtems_capture_restart, 0 },
     1064  { "delete",  rtems_capture_delete,  0 },
     1065  { "begin",   rtems_capture_begin,   1 },
     1066  { "exitted", rtems_capture_exitted, 1 }
     1067};
     1068
     1069typedef enum rtems_capture_cli_trig_state_e
     1070{
     1071  trig_type,
     1072  trig_to,
     1073  trig_from_from,
     1074  trig_from
     1075} rtems_capture_cli_trig_state_t;
     1076
     1077#define RTEMS_CAPTURE_CLI_TRIGGERS_NUM \
     1078  (sizeof (rtems_capture_cli_triggers) / sizeof (rtems_capture_cli_triggers_t))
     1079
     1080static void
     1081rtems_capture_cli_trigger_worker (int set, int argc, char** argv)
     1082{
     1083  rtems_status_code            sc;
     1084  int                          arg;
     1085  int                          trigger = 0; /* switch */
     1086  rtems_capture_trigger_mode_t trigger_mode = rtems_capture_from_any;
     1087  rtems_boolean                trigger_set = 0;
     1088  rtems_boolean                is_from = 0;
     1089  rtems_name                   name = 0;
     1090  rtems_id                     id = 0;
     1091  rtems_boolean                valid_name = 0;
     1092  rtems_boolean                valid_id = 0;
     1093  rtems_name                   from_name = 0;
     1094  rtems_id                     from_id = 0;
     1095  rtems_boolean                from_valid_name = 0;
     1096  rtems_boolean                from_valid_id = 0;
     1097  rtems_name                   to_name = 0;
     1098  rtems_id                     to_id = 0;
     1099  rtems_boolean                to_valid_name = 0;
     1100  rtems_boolean                to_valid_id = 0;
    10351101
    10361102  for (arg = 1; arg < argc; arg++)
     
    10381104    if (argv[arg][0] == '-')
    10391105    {
    1040       fprintf(stdout,"warning: option -%c ignored\n", argv[arg][1]);
     1106      switch (argv[arg][1])
     1107      {
     1108        case '?':
     1109          fprintf (stdout, trigger_set_usage, set ? "ctset" : "ctclear");
     1110          fprintf (stdout, trigger_set_types);
     1111          return;
     1112        default:
     1113          fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
     1114          break;
     1115      }
    10411116    }
    10421117    else
     
    10441119      if (!trigger_set)
    10451120      {
    1046         if (strcmp (argv[arg], "from") == 0)
    1047           trigger = rtems_capture_to_any;
    1048         else if (strcmp (argv[arg], "to") == 0)
    1049           trigger = rtems_capture_from_any;
    1050         else if (strcmp (argv[arg], "edge") == 0)
    1051           trigger = rtems_capture_from_any;
     1121        rtems_boolean found = 0;
     1122        int           t;
     1123       
     1124        for (t = 0; t < RTEMS_CAPTURE_CLI_TRIGGERS_NUM; t++)
     1125          if (strcmp (argv[arg], rtems_capture_cli_triggers[t].name) == 0)
     1126          {
     1127            trigger = t;
     1128            found = 1;
     1129            break;
     1130          }
     1131
     1132        trigger_set = 1;
     1133
     1134        /*
     1135         * If a trigger was not found assume the default and
     1136         * assume the parameter is a task name or id.
     1137         */
     1138        if (found)
     1139          continue;
     1140      }
     1141
     1142      if (strcmp (arg[argv], "from") == 0)
     1143      {
     1144        if (is_from)
     1145          fprintf (stdout, "warning: extra 'from' ignored\n");
     1146       
     1147        is_from = 1;
     1148        continue;
     1149      }
     1150
     1151      if (!rtems_capture_cli_get_name_id (argv[arg], &valid_name, &valid_id,
     1152                                          &name, &id))
     1153        return;
     1154
     1155      if (valid_name)
     1156      {
     1157        if (is_from)
     1158        {
     1159          if (!from_valid_name && !from_valid_id)
     1160          {
     1161            from_valid_name = 1;
     1162            from_name       = name;
     1163          }
     1164          else
     1165            fprintf (stdout, "warning: extra arguments ignored\n");
     1166        }
     1167        else if (!to_valid_name && !to_valid_id)
     1168        {
     1169          to_valid_name = 1;
     1170          to_name       = name;
     1171        }
    10521172        else
     1173          fprintf (stdout, "warning: extra arguments ignored\n");
     1174      }
     1175         
     1176      if (valid_id)
     1177      {
     1178        if (is_from)
    10531179        {
    1054           fprintf(stdout,"error: the first argument is the trigger type (from/to/edge)\n");
     1180          if (!from_valid_name && !from_valid_id)
     1181          {
     1182            from_valid_id = 1;
     1183            from_id       = id;
     1184          }
     1185          else
     1186            fprintf (stdout, "warning: extra arguments ignored\n");
     1187        }
     1188        else if (!to_valid_name && !to_valid_id)
     1189        {
     1190          to_valid_id = 1;
     1191          to_id       = id;
     1192        }
     1193        else
     1194          fprintf (stdout, "warning: extra arguments ignored\n");
     1195      }
     1196    }
     1197  }
     1198
     1199  if (is_from && rtems_capture_cli_triggers[trigger].to_only)
     1200  {
     1201    fprintf (stdout, "error: a %s trigger can be a TO trigger\n",
     1202             rtems_capture_cli_triggers[trigger].name);
     1203    return;
     1204  }
     1205 
     1206  if (!to_valid_name && !to_valid_id && !from_valid_name && !from_valid_id)
     1207  {
     1208    fprintf (stdout, trigger_set_usage);
     1209    return;
     1210  }
     1211
     1212  if (!is_from && !to_valid_name && !to_valid_id)
     1213  {
     1214    fprintf (stdout, "error: a %s trigger needs a TO name or id\n",
     1215             rtems_capture_cli_triggers[trigger].name);
     1216    return;
     1217  }
     1218
     1219  if (is_from && !from_valid_name && !from_valid_id)
     1220  {
     1221    fprintf (stdout, "error: a %s trigger needs a FROM name or id\n",
     1222             rtems_capture_cli_triggers[trigger].name);
     1223    return;
     1224  }
     1225
     1226  if ((from_valid_name || from_valid_id) && (to_valid_name || to_valid_id))
     1227    trigger_mode = rtems_capture_from_to;
     1228  else if (from_valid_name || from_valid_id)
     1229    trigger_mode = rtems_capture_to_any;
     1230  else if (to_valid_name || to_valid_id)
     1231    trigger_mode = rtems_capture_from_any;
     1232
     1233  if (set)
     1234    sc = rtems_capture_set_trigger (from_name, from_id, to_name, to_id,
     1235                                    trigger_mode,
     1236                                    rtems_capture_cli_triggers[trigger].type);
     1237  else
     1238    sc = rtems_capture_clear_trigger (from_name, from_id, to_name, to_id,
     1239                                      trigger_mode,
     1240                                      rtems_capture_cli_triggers[trigger].type);
     1241
     1242  if (sc != RTEMS_SUCCESSFUL)
     1243  {
     1244    fprintf (stdout, "error: %sing the trigger failed: %s\n",
     1245             set ? "sett" : "clear", rtems_status_text (sc));
     1246    return;
     1247  }
     1248
     1249  fprintf (stdout, "trigger %s.\n", set ? "set" : "cleared");
     1250}
     1251
     1252/*
     1253 * rtems_capture_cli_trigger_set
     1254 *
     1255 *  DESCRIPTION:
     1256 *
     1257 * This function is a monitor command that sets a trigger.
     1258 *
     1259 */
     1260
     1261static void
     1262rtems_capture_cli_trigger_set (int                          argc,
     1263                               char**                       argv,
     1264                               rtems_monitor_command_arg_t* command_arg,
     1265                               boolean                      verbose)
     1266{
     1267  rtems_capture_cli_trigger_worker (1, argc, argv);
     1268}
     1269
     1270/*
     1271 * rtems_capture_cli_trigger_clear
     1272 *
     1273 *  DESCRIPTION:
     1274 *
     1275 * This function is a monitor command that clears a trigger.
     1276 *
     1277 */
     1278
     1279static void
     1280rtems_capture_cli_trigger_clear (int                          argc,
     1281                                 char**                       argv,
     1282                                 rtems_monitor_command_arg_t* command_arg,
     1283                                 boolean                      verbose)
     1284{
     1285  rtems_capture_cli_trigger_worker (0, argc, argv);
     1286}
     1287
     1288/*
     1289 * rtems_capture_cli_trace_records
     1290 *
     1291 *  DESCRIPTION:
     1292 *
     1293 * This function is a monitor command that dumps trace records.
     1294 *
     1295 */
     1296
     1297static void
     1298rtems_capture_cli_trace_records (int                          argc,
     1299                                 char**                       argv,
     1300                                 rtems_monitor_command_arg_t* command_arg,
     1301                                 boolean                      verbose)
     1302{
     1303  rtems_status_code       sc;
     1304  rtems_boolean           csv = 0;
     1305  static int              dump_total = 22;
     1306  int                     total;
     1307  int                     count;
     1308  uint32_t                read;
     1309  rtems_capture_record_t* rec;
     1310  int                     arg;
     1311
     1312  for (arg = 1; arg < argc; arg++)
     1313  {
     1314    if (argv[arg][0] == '-')
     1315    {
     1316      if (argv[arg][1] == 'c')
     1317        csv = 1;
     1318      else
     1319        fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
     1320    }
     1321    else
     1322    {
     1323      int i;
     1324      int l;
     1325
     1326      l = strlen (argv[arg]);
     1327
     1328      for (i = 0; i < l; i++)
     1329        if (!isdigit (argv[arg][i]))
     1330        {
     1331          fprintf (stdout, "error: not a number\n");
    10551332          return;
    10561333        }
    1057         trigger_set = 1;
    1058       }
    1059       else
    1060       {
    1061         if (trigger == rtems_capture_to_any)
    1062         {
    1063           if (from_valid_name && from_valid_id)
    1064             fprintf(stdout,"warning: extra arguments ignored\n");
    1065           else if (!rtems_capture_cli_get_name_id (argv[arg], &from_valid_name, &from_valid_id,
    1066                                            &from_name, &from_id))
    1067             return;
    1068         }
    1069         else if (trigger == rtems_capture_from_any)
    1070         {
    1071           if (to_valid_name && to_valid_id)
    1072             fprintf(stdout,"warning: extra arguments ignored\n");
    1073           else if (!rtems_capture_cli_get_name_id (argv[arg], &to_valid_name, &to_valid_id,
    1074                                            &to_name, &to_id))
    1075             return;
    1076         }
    1077         else if (trigger == rtems_capture_from_to)
    1078         {
    1079           if (from_valid_name && from_valid_id && to_valid_name && to_valid_id)
    1080             fprintf(stdout,"warning: extra arguments ignored\n");
    1081           else
    1082           {
    1083             if (!rtems_capture_cli_get_name_id (argv[arg], &valid_name, &valid_id,
    1084                                         &name, &id))
    1085               return;
    1086 
    1087             if (valid_name)
    1088             {
    1089               if (!from_valid_name && !from_valid_id)
    1090               {
    1091                 from_valid_name = 1;
    1092                 from_name       = name;
    1093               }
    1094               else if (to_valid_name)
    1095                 fprintf(stdout,"warning: extra arguments ignored\n");
    1096               else
    1097               {
    1098                 to_valid_name = 1;
    1099                 to_name       = name;
    1100               }
    1101             }
    1102             if (valid_id)
    1103             {
    1104               if (!from_valid_id && !to_valid_name)
    1105               {
    1106                 from_valid_id = 1;
    1107                 from_id       = id;
    1108               }
    1109               else if (to_valid_id)
    1110                 fprintf(stdout,"warning: extra arguments ignored\n");
    1111               else
    1112               {
    1113                 to_valid_id = 1;
    1114                 to_id       = id;
    1115               }
    1116             }
    1117           }
    1118         }
    1119       }
    1120     }
    1121   }
    1122 
    1123   if ((trigger == rtems_capture_to_any) && !from_valid_name && !from_valid_id)
    1124   {
    1125     fprintf(stdout,"error: a from trigger need a to name or id\n");
    1126     return;
    1127   }
    1128 
    1129   if ((trigger == rtems_capture_from_any) && !to_valid_name && !to_valid_id)
    1130   {
    1131     fprintf(stdout,"error: a to trigger need a from name or id\n");
    1132     return;
    1133   }
    1134 
    1135   if ((trigger == rtems_capture_from_to) &&
    1136       ((!from_valid_name && !from_valid_id) || (!to_valid_name && !to_valid_id)))
    1137   {
    1138     fprintf(stdout,"error: an edge trigger need a from and to name or id\n");
    1139     return;
    1140   }
    1141 
    1142   sc = rtems_capture_set_trigger (from_name, from_id, to_name, to_id, trigger);
    1143 
    1144   if (sc != RTEMS_SUCCESSFUL)
    1145   {
    1146     fprintf(stdout,"error: setting the trigger failed: %s\n", rtems_status_text (sc));
    1147     return;
    1148   }
    1149 
    1150   fprintf(stdout,"trigger set.\n");
    1151 }
    1152 
    1153 /*
    1154  * rtems_capture_cli_trace_records
    1155  *
    1156  *  DESCRIPTION:
    1157  *
    1158  * This function is a monitor command that dumps trace records.
    1159  *
    1160  */
    1161 
    1162 static void
    1163 rtems_capture_cli_trace_records (
    1164   int argc,
    1165   char **argv,
    1166   rtems_monitor_command_arg_t *command_arg,
    1167   boolean verbose )
    1168 {
    1169   rtems_status_code       sc;
    1170   rtems_boolean           csv = 0;
    1171   static int              dump_total = 32;
    1172   int                     total;
    1173   int                     count;
    1174   uint32_t          read;
    1175   rtems_capture_record_t* rec;
    1176   int                     arg;
    1177 
    1178   for (arg = 1; arg < argc; arg++)
    1179   {
    1180     if (argv[arg][0] == '-')
    1181     {
    1182       if (argv[arg][1] == 'c')
    1183         csv = 1;
    1184       else if (argv[arg][1] == 'r')
    1185       {
    1186         int i;
    1187         int l;
    1188 
    1189         arg++;
    1190         if (arg == argc)
    1191         {
    1192           fprintf(stdout,"error: option -r requires number\n");
    1193           return;
    1194         }
    1195 
    1196         l = strlen (argv[arg]);
    1197 
    1198         for (i = 0; i < l; i++)
    1199           if (!isdigit (argv[arg][i]))
    1200           {
    1201             fprintf(stdout,"error: option -r requires number and currently it is not\n");
    1202             return;
    1203           }
    1204 
    1205         dump_total = strtoul (argv[arg], 0, 0);
    1206       }
    1207       else
    1208         fprintf(stdout,"warning: option -%c ignored\n", argv[arg][1]);
     1334
     1335      dump_total = strtoul (argv[arg], 0, 0);
    12091336    }
    12101337  }
     
    12181345    if (sc != RTEMS_SUCCESSFUL)
    12191346    {
    1220       fprintf(stdout,"error: trace read failed: %s\n", rtems_status_text (sc));
     1347      fprintf (stdout, "error: trace read failed: %s\n", rtems_status_text (sc));
    12211348      rtems_capture_flush (0);
    12221349      return;
    12231350    }
    12241351
     1352    /*
     1353     * If we have no records then just exist. We still need to release
     1354     * the reader lock.
     1355     */
     1356   
    12251357    if (read == 0)
     1358    {
     1359      rtems_capture_release (read);
    12261360      break;
    1227 
    1228     for (count = 0; count < read; count++, rec++)
     1361    }
     1362
     1363    count = total < read ? total : read;
     1364   
     1365    while (count--)
    12291366    {
    12301367      if (csv)
    1231         fprintf(stdout,"%08" PRIx32 ",%03" PRIu32
     1368        fprintf (stdout, "%08" PRIx32 ",%03" PRIu32
    12321369                   ",%03" PRIu32 ",%04" PRIx32 ",%" PRId32 ",%" PRId32 "\n",
    12331370                (uint32_t) rec->task,
     
    12521389          if (event & 1)
    12531390          {
    1254             fprintf(stdout,"%9li.%06li ", (unsigned long) (t / 1000000),
     1391            fprintf (stdout, "%9li.%06li ", (unsigned long) (t / 1000000),
    12551392                    (unsigned long) (t % 1000000));
    12561393            rtems_monitor_dump_id (rtems_capture_task_id (rec->task));
    1257             fprintf(stdout," ");
     1394            fprintf (stdout, " ");
    12581395            rtems_monitor_dump_name (rtems_capture_task_name (rec->task));
    1259             fprintf(stdout," %3" PRId32 " %3" PRId32 " %s\n",
     1396            fprintf (stdout, " %3" PRId32 " %3" PRId32 " %s\n",
    12601397                    (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
    12611398                    (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
     
    12651402        }
    12661403      }
    1267     }
    1268 
    1269     if (read < total)
    1270       total -= read;
     1404      rec++;
     1405    }
     1406
     1407    count = total < read ? total : read;
     1408   
     1409    if (count < total)
     1410      total -= count;
    12711411    else
    12721412      total = 0;
    12731413
    1274     rtems_capture_release (read);
     1414    rtems_capture_release (count);
    12751415  }
    12761416}
     
    12871427
    12881428static void
    1289 rtems_capture_cli_flush (
    1290   int argc,
    1291   char **argv,
    1292   rtems_monitor_command_arg_t *command_arg,
    1293   boolean verbose )
     1429rtems_capture_cli_flush (int                          argc,
     1430                         char**                       argv,
     1431                         rtems_monitor_command_arg_t* command_arg,
     1432                         boolean                      verbose)
    12941433{
    12951434  rtems_status_code sc;
     
    13041443        prime = 0;
    13051444      else
    1306         fprintf(stdout,"warning: option -%c ignored\n", argv[arg][1]);
     1445        fprintf (stdout, "warning: option -%c ignored\n", argv[arg][1]);
    13071446    }
    13081447  }
     
    13121451  if (sc != RTEMS_SUCCESSFUL)
    13131452  {
    1314     fprintf(stdout,"error: flush failed: %s\n", rtems_status_text (sc));
    1315     return;
    1316   }
    1317 
    1318   fprintf(stdout,"trace buffer flushed and %s.\n", prime ? "primed" : "not primed");
     1453    fprintf (stdout, "error: flush failed: %s\n", rtems_status_text (sc));
     1454    return;
     1455  }
     1456
     1457  fprintf (stdout, "trace buffer flushed and %s.\n",
     1458           prime ? "primed" : "not primed");
    13191459}
    13201460
     
    14341574  },
    14351575  {
    1436     "ctrig",
    1437     "usage: ctrig type [from name] [from id] [to name] [to id]\n",
     1576    "ctset",
     1577    "usage: ctset -h\n",
    14381578    0,
    14391579    rtems_capture_cli_trigger_set,
     1580    { 0 },
     1581    0
     1582  },
     1583  {
     1584    "ctclear",
     1585    "usage: ctclear -?\n",
     1586    0,
     1587    rtems_capture_cli_trigger_clear,
    14401588    { 0 },
    14411589    0
  • cpukit/libmisc/capture/capture.c

    rf41dd23 r1374fd3  
    3939 * These events are always recorded and are not part of the
    4040 * watch filters.
    41  */
     41 *
     42 * This feature has been disabled as it becomes confusing when
     43 * setting up filters and some event leak.
     44 */
     45#if defined (RTEMS_CAPTURE_ENGINE_ALLOW_RELATED_EVENTS)
    4246#define RTEMS_CAPTURE_RECORD_EVENTS  (RTEMS_CAPTURE_CREATED_BY_EVENT | \
    4347                                      RTEMS_CAPTURE_CREATED_EVENT | \
     
    5054                                      RTEMS_CAPTURE_BEGIN_EVENT | \
    5155                                      RTEMS_CAPTURE_EXITTED_EVENT)
     56#else
     57#define RTEMS_CAPTURE_RECORD_EVENTS  (0)
     58#endif
    5259
    5360/*
     
    6168#define RTEMS_CAPTURE_READER_WAITING (1 << 5)
    6269#define RTEMS_CAPTURE_GLOBAL_WATCH   (1 << 6)
     70#define RTEMS_CAPTURE_ONLY_MONITOR   (1 << 7)
    6371
    6472/*
     
    6674 */
    6775static rtems_capture_record_t*  capture_records;
    68 static uint32_t           capture_size;
    69 static uint32_t           capture_count;
     76static uint32_t                 capture_size;
     77static uint32_t                 capture_count;
    7078static rtems_capture_record_t*  capture_in;
    71 static uint32_t           capture_out;
    72 static uint32_t           capture_flags;
     79static uint32_t                 capture_out;
     80static uint32_t                 capture_flags;
    7381static rtems_capture_task_t*    capture_tasks;
    7482static rtems_capture_control_t* capture_controls;
     
    7886static rtems_task_priority      capture_ceiling;
    7987static rtems_task_priority      capture_floor;
    80 static uint32_t           capture_tick_period;
     88static uint32_t                 capture_tick_period;
    8189static rtems_id                 capture_reader;
    82 int rtems_capture_free_info_on_task_delete;
    8390
    8491/*
     
    110117 * by the user get the time from that.
    111118 */
    112 static inline void rtems_capture_get_time (uint32_t  * ticks,
    113                                            uint32_t  * tick_offset)
     119static inline void rtems_capture_get_time (uint32_t* ticks,
     120                                           uint32_t* tick_offset)
    114121{
    115122  if (capture_timestamp)
     
    139146
    140147/*
    141  * rtems_capture_dup_name
    142  *
    143  *  DESCRIPTION:
    144  *
    145  * This function duplicates an rtems_names. It protects the
    146  * capture engine from a change to the way names are supported
     148 * rtems_capture_match_id
     149 *
     150 *  DESCRIPTION:
     151 *
     152 * This function compares rtems_ids. It protects the
     153 * capture engine from a change to the way id are supported
    147154 * in RTEMS.
    148155 *
    149156 */
    150 static inline void
    151 rtems_capture_dup_name (rtems_name* dst, rtems_name src)
    152 {
    153   *dst = src;
    154 }
    155 
    156 /*
    157  * rtems_capture_name_in_group
    158  *
    159  *  DESCRIPTION:
    160  *
    161  * This function sees if a name is in a group of names.
    162  *
    163  */
    164157static inline rtems_boolean
    165 rtems_capture_name_in_group (rtems_name task, rtems_name* tasks)
    166 {
    167   if (tasks)
    168   {
    169     int i;
    170     for (i = 0; i < RTEMS_CAPTURE_TRIGGER_TASKS; i++)
    171       if (rtems_capture_match_names (task, *tasks++))
    172         return 1;
    173   }
    174   return 0;
     158rtems_capture_match_ids (rtems_id lhs, rtems_id rhs)
     159{
     160  return lhs == rhs;
    175161}
    176162
     
    202188
    203189/*
     190 * rtems_capture_dup_name
     191 *
     192 *  DESCRIPTION:
     193 *
     194 * This function duplicates an rtems_names. It protects the
     195 * capture engine from a change to the way names are supported
     196 * in RTEMS.
     197 *
     198 */
     199static inline void
     200rtems_capture_dup_name (rtems_name* dst, rtems_name src)
     201{
     202  *dst = src;
     203}
     204
     205/*
     206 * rtems_capture_by_in_to
     207 *
     208 *  DESCRIPTION:
     209 *
     210 * This function sees if a BY control is in the BY names. The use
     211 * of the valid_mask in this way assumes the number of trigger
     212 * tasks is the number of bits in uint32_t.
     213 *
     214 */
     215static inline rtems_boolean
     216rtems_capture_by_in_to (uint32_t                 events,
     217                        rtems_capture_task_t*    by,
     218                        rtems_capture_control_t* to)
     219{
     220  uint32_t valid_mask = RTEMS_CAPTURE_CONTROL_FROM_MASK (0);
     221  uint32_t valid_remainder = 0xffffffff;
     222  int      i;
     223 
     224  for (i = 0; i < RTEMS_CAPTURE_TRIGGER_TASKS; i++)
     225  {
     226    /*
     227     * If there are no more valid BY entries then
     228     * we are finished.
     229     */
     230    if ((valid_remainder & to->by_valid) == 0)
     231      break;
     232
     233    /*
     234     * Is the froby entry valid and does its name or id match.
     235     */
     236    if ((valid_mask & to->by_valid) &&
     237        (to->by[i].trigger & events))
     238    {
     239      /*
     240       * We have the BY task on the right hand side so we
     241       * match with id's first then labels if the id's are
     242       * not set.
     243       */
     244      if (rtems_capture_match_name_id (to->by[i].name, to->by[i].id,
     245                                       by->name, by->id))
     246        return 1;
     247    }
     248   
     249    valid_mask >>= 1;
     250    valid_remainder >>= 1;
     251  }
     252 
     253  return 0;
     254}
     255
     256/*
     257 * rtems_capture_refcount_up
     258 *
     259 *  DESCRIPTION:
     260 *
     261 * This function raises the reference count.
     262 *
     263 */
     264static inline void
     265rtems_capture_refcount_up (rtems_capture_task_t* task)
     266{
     267  task->refcount++;
     268}
     269
     270/*
     271 * rtems_capture_refcount_down
     272 *
     273 *  DESCRIPTION:
     274 *
     275 * This function lowers the reference count and if the count
     276 * reaches 0 the task control block is returned to the heap.
     277 *
     278 */
     279static inline void
     280rtems_capture_refcount_down (rtems_capture_task_t* task)
     281{
     282  if (task->refcount)
     283    task->refcount--;
     284}
     285
     286/*
    204287 * rtems_capture_init_stack_usage
    205288 *
     
    213296  if (task->tcb)
    214297  {
    215     uint32_t  * s;
    216     uint32_t    i;
     298    uint32_t* s;
     299    uint32_t  i;
    217300
    218301    task->stack_size  = task->tcb->Start.Initial_stack.size;
     
    275358    }
    276359
    277     control->name  = name;
    278     control->id    = id;
    279     control->flags = 0;
    280 
    281     memset (control->from,    0, sizeof (control->from));
    282     memset (control->from_id, 0, sizeof (control->from_id));
     360    control->name          = name;
     361    control->id            = id;
     362    control->flags         = 0;
     363    control->to_triggers   = 0;
     364    control->from_triggers = 0;
     365    control->by_valid      = 0;
     366
     367    memset (control->by, 0, sizeof (control->by));
    283368
    284369    rtems_interrupt_disable (level);
     
    315400  rtems_capture_task_t*    task;
    316401  rtems_capture_control_t* control;
    317 
     402  rtems_name               name;
     403 
    318404  task = _Workspace_Allocate (sizeof (rtems_capture_task_t));
    319405
     
    324410  }
    325411
    326   rtems_capture_dup_name (&task->name, ((rtems_name) new_task->Object.name));
    327 
     412  /*
     413   * Check the type of name the object has.
     414   */
     415  if (_Objects_Get_API (new_task->Object.id) == OBJECTS_CLASSIC_API)
     416    name = (rtems_name) new_task->Object.name;
     417  else
     418    name = rtems_build_name (((char*) new_task->Object.name)[0],
     419                             ((char*) new_task->Object.name)[1],
     420                             ((char*) new_task->Object.name)[2],
     421                             ((char*) new_task->Object.name)[3]);
     422 
     423  rtems_capture_dup_name (&task->name, name);
     424 
    328425  task->id               = new_task->Object.id;
    329426  task->flags            = 0;
    330427  task->in               = 0;
     428  task->refcount         = 0;
    331429  task->out              = 0;
    332430  task->tcb              = new_task;
     
    369467
    370468/*
     469 * rtems_capture_destroy_capture_task
     470 *
     471 *  DESCRIPTION:
     472 *
     473 * This function destroy the task structure if the reference count
     474 * is 0 and the tcb has been cleared signalling the task has been
     475 * deleted.
     476 *
     477 */
     478static inline void
     479rtems_capture_destroy_capture_task (rtems_capture_task_t* task)
     480{
     481  if (task)
     482  {
     483    rtems_interrupt_level level;
     484
     485    rtems_interrupt_disable (level);
     486
     487    if (task->tcb || task->refcount)
     488      task = 0;
     489
     490    if (task)
     491    {
     492      if (task->forw)
     493        task->forw->back = task->back;
     494      if (task->back)
     495        task->back->forw = task->forw;
     496      else
     497        capture_tasks = task->forw;
     498    }
     499
     500    rtems_interrupt_enable (level);
     501
     502    if (task)
     503      _Workspace_Free (task);
     504  }
     505}
     506
     507/*
    371508 * rtems_capture_record
    372509 *
     
    378515static inline void
    379516rtems_capture_record (rtems_capture_task_t* task,
    380                       uint32_t        events)
     517                      uint32_t              events)
    381518{
    382519  /*
     
    384521   * the task's real priority is lower or equal to the ceiling.
    385522   */
    386   if (task)
     523  if (task &&
     524      ((capture_flags &
     525        (RTEMS_CAPTURE_TRIGGERED | RTEMS_CAPTURE_ONLY_MONITOR)) ==
     526       RTEMS_CAPTURE_TRIGGERED))
    387527  {
    388528    rtems_capture_control_t* control;
     
    423563        else
    424564          capture_in++;
     565
     566        rtems_capture_refcount_up (task);
    425567      }
    426568      else
     
    432574
    433575/*
     576 * rtems_capture_trigger
     577 *
     578 *  DESCRIPTION:
     579 *
     580 * See if we have triggered and if not see if this event is a
     581 * cause of a trigger.
     582 */
     583rtems_boolean
     584rtems_capture_trigger (rtems_capture_task_t* ft,
     585                       rtems_capture_task_t* tt,
     586                       uint32_t              events)
     587{
     588  /*
     589   * If we have not triggered then see if this is a trigger condition.
     590   */
     591  if (!(capture_flags & RTEMS_CAPTURE_TRIGGERED))
     592  {
     593    rtems_capture_control_t* fc = NULL;
     594    rtems_capture_control_t* tc = NULL;
     595    uint32_t                 from_events = 0;
     596    uint32_t                 to_events = 0;
     597    uint32_t                 from_to_events = 0;
     598 
     599    if (ft)
     600    {
     601      fc = ft->control;
     602      if (fc)
     603        from_events = fc->from_triggers & events;
     604    }
     605   
     606    if (tt)
     607    {
     608      tc = tt->control;
     609      if (tc)
     610      {
     611        to_events = tc->to_triggers & events;
     612        if (ft && tc->by_valid)
     613          from_to_events = tc->by_triggers & events;
     614      }
     615    }
     616
     617    /*
     618     * Check if we have any from or to events. These are the
     619     * from any or to any type triggers. All from/to triggers are
     620     * listed in the to's control with the from in the from list.
     621     *
     622     * The masking above means any flag set is a trigger.
     623     */
     624    if (from_events || to_events)
     625    {
     626      capture_flags |= RTEMS_CAPTURE_TRIGGERED;
     627      return 1;
     628    }
     629
     630    /*
     631     * Check the from->to events.
     632     */
     633    if (from_to_events)
     634    {
     635      if (rtems_capture_by_in_to (events, ft, tc))
     636      {
     637        capture_flags |= RTEMS_CAPTURE_TRIGGERED;
     638        return 1;
     639      }
     640    }
     641
     642    return 0;
     643  }
     644 
     645  return 1;
     646}
     647
     648/*
    434649 * rtems_capture_create_task
    435650 *
     
    449664
    450665  /*
    451    * The task ponters may not be known as the task may have
     666   * The task pointers may not be known as the task may have
    452667   * been created before the capture engine was open. Add them.
    453668   */
     
    461676  nt = rtems_capture_create_capture_task (new_task);
    462677
    463   /*
    464    * If we are logging then record this fact.
    465    */
    466   rtems_capture_record (ct, RTEMS_CAPTURE_CREATED_BY_EVENT);
    467   rtems_capture_record (nt, RTEMS_CAPTURE_CREATED_EVENT);
     678  if (rtems_capture_trigger (ct, nt, RTEMS_CAPTURE_CREATE))
     679  {
     680    rtems_capture_record (ct, RTEMS_CAPTURE_CREATED_BY_EVENT);
     681    rtems_capture_record (nt, RTEMS_CAPTURE_CREATED_EVENT);
     682  }
    468683
    469684  return 1 == 1;
     
    493708
    494709  /*
    495    * The task ponters may not be known as the task may have
     710   * The task pointers may not be known as the task may have
    496711   * been created before the capture engine was open. Add them.
    497712   */
     
    502717  if (st == NULL)
    503718    st = rtems_capture_create_capture_task (started_task);
    504 
    505   rtems_capture_record (ct, RTEMS_CAPTURE_STARTED_BY_EVENT);
    506   rtems_capture_record (st, RTEMS_CAPTURE_STARTED_EVENT);
     719 
     720  if (rtems_capture_trigger (ct, st, RTEMS_CAPTURE_START))
     721  {
     722    rtems_capture_record (ct, RTEMS_CAPTURE_STARTED_BY_EVENT);
     723    rtems_capture_record (st, RTEMS_CAPTURE_STARTED_EVENT);
     724  }
    507725
    508726  rtems_capture_init_stack_usage (st);
     
    532750
    533751  /*
    534    * The task ponters may not be known as the task may have
     752   * The task pointers may not be known as the task may have
    535753   * been created before the capture engine was open. Add them.
    536754   */
     
    542760    rt = rtems_capture_create_capture_task (restarted_task);
    543761
    544   rtems_capture_record (ct, RTEMS_CAPTURE_RESTARTED_BY_EVENT);
    545   rtems_capture_record (rt, RTEMS_CAPTURE_RESTARTED_EVENT);
     762  if (rtems_capture_trigger (ct, rt, RTEMS_CAPTURE_RESTART))
     763  {
     764    rtems_capture_record (ct, RTEMS_CAPTURE_RESTARTED_BY_EVENT);
     765    rtems_capture_record (rt, RTEMS_CAPTURE_RESTARTED_EVENT);
     766  }
    546767
    547768  rtems_capture_task_stack_usage (rt);
     
    569790
    570791  /*
    571    * The task ponters may not be known as the task may have
     792   * The task pointers may not be known as the task may have
    572793   * been created before the capture engine was open. Add them.
    573794   */
     
    582803    dt = rtems_capture_create_capture_task (deleted_task);
    583804
    584   rtems_capture_record (ct, RTEMS_CAPTURE_DELETED_BY_EVENT);
    585   rtems_capture_record (dt, RTEMS_CAPTURE_DELETED_EVENT);
    586 
     805  if (rtems_capture_trigger (ct, dt, RTEMS_CAPTURE_DELETE))
     806  {
     807    rtems_capture_record (ct, RTEMS_CAPTURE_DELETED_BY_EVENT);
     808    rtems_capture_record (dt, RTEMS_CAPTURE_DELETED_EVENT);
     809  }
     810 
    587811  rtems_capture_task_stack_usage (dt);
    588812
    589813  /*
    590    * This task's tcb will be invalid.
     814   * This task's tcb will be invalid. This signals the
     815   * task has been deleted.
    591816   */
    592817  dt->tcb = 0;
    593818
    594   /*
    595    * Unlink
    596    */
    597   if (rtems_capture_free_info_on_task_delete) {
    598     if (dt->forw)
    599       dt->forw->back = dt->back;
    600     if (dt->back)
    601       dt->back->forw = dt->forw;
    602     else
    603       capture_tasks = dt->forw;
    604     _Workspace_Free (dt);
    605   }
     819  rtems_capture_destroy_capture_task (dt);
    606820}
    607821
     
    626840
    627841  /*
    628    * The task ponters may not be known as the task may have
     842   * The task pointers may not be known as the task may have
    629843   * been created before the capture engine was open. Add them.
    630844   */
     
    633847    bt = rtems_capture_create_capture_task (begin_task);
    634848
    635   rtems_capture_record (bt, RTEMS_CAPTURE_BEGIN_EVENT);
     849  if (rtems_capture_trigger (NULL, bt, RTEMS_CAPTURE_BEGIN))
     850    rtems_capture_record (bt, RTEMS_CAPTURE_BEGIN_EVENT);
    636851}
    637852
     
    657872
    658873  /*
    659    * The task ponters may not be known as the task may have
     874   * The task pointers may not be known as the task may have
    660875   * been created before the capture engine was open. Add them.
    661876   */
     
    664879    et = rtems_capture_create_capture_task (exitted_task);
    665880
    666   rtems_capture_record (et, RTEMS_CAPTURE_EXITTED_EVENT);
     881  if (rtems_capture_trigger (NULL, et, RTEMS_CAPTURE_EXITTED))
     882    rtems_capture_record (et, RTEMS_CAPTURE_EXITTED_EVENT);
    667883
    668884  rtems_capture_task_stack_usage (et);
     
    687903  if (capture_flags & RTEMS_CAPTURE_ON)
    688904  {
    689     uint32_t   ticks;
    690     uint32_t   tick_offset;
     905    uint32_t ticks;
     906    uint32_t tick_offset;
    691907
    692908    /*
    693909     * Get the cpature task control block so we can update the
    694      * reference anbd perform any watch or trigger functions.
    695      * The task ponters may not be known as the task may have
     910     * reference and perform any watch or trigger functions.
     911     * The task pointers may not be known as the task may have
    696912     * been created before the capture engine was open. Add them.
    697913     */
     
    761977    }
    762978
    763     /*
    764      * If we have not triggered then see if this is a trigger condition.
    765      */
    766     if (!(capture_flags & RTEMS_CAPTURE_TRIGGERED))
    767     {
    768       rtems_capture_control_t* cc = NULL;
    769       rtems_capture_control_t* hc = NULL;
    770 
    771       if (ct)
    772       {
    773         cc = ct->control;
    774 
    775         /*
    776          * Check the current task for a TO_ANY trigger.
    777          */
    778         if (cc && (cc->flags & RTEMS_CAPTURE_TO_ANY))
    779         {
    780           capture_flags |= RTEMS_CAPTURE_TRIGGERED;
    781           goto triggered;
    782         }
    783       }
    784 
    785       if (ht)
    786       {
    787         hc = ht->control;
    788 
    789         /*
    790          * Check the next task for a FROM_ANY.
    791          */
    792         if (hc && (hc->flags & RTEMS_CAPTURE_FROM_ANY))
    793         {
    794           capture_flags |= RTEMS_CAPTURE_TRIGGERED;
    795           goto triggered;
    796         }
    797       }
    798 
    799       /*
    800        * Check is the trigger is from the current task
    801        * to the next task.
    802        */
    803       if (cc && hc && (hc->flags & RTEMS_CAPTURE_FROM_TO))
    804         if (rtems_capture_name_in_group (cc->name, hc->from))
    805         {
    806           capture_flags |= RTEMS_CAPTURE_TRIGGERED;
    807           goto triggered;
    808         }
    809     }
    810     else
    811     {
    812 triggered:
    813 
     979    if (rtems_capture_trigger (ct, ht, RTEMS_CAPTURE_SWITCH))
     980    {
    814981      rtems_capture_record (ct, RTEMS_CAPTURE_SWITCHED_OUT_EVENT);
    815982      rtems_capture_record (ht, RTEMS_CAPTURE_SWITCHED_IN_EVENT);
     
    9221089  }
    9231090
    924   capture_flags &= ~RTEMS_CAPTURE_ON;
     1091  capture_flags &= ~(RTEMS_CAPTURE_ON | RTEMS_CAPTURE_ONLY_MONITOR);
    9251092
    9261093  records = capture_records;
     
    10011168
    10021169/*
     1170 * rtems_capture_monitor
     1171 *
     1172 *  DESCRIPTION:
     1173 *
     1174 * This function enable the monitor mode. When in the monitor mode
     1175 * the tasks are monitored but no data is saved. This can be used
     1176 * to profile the load on a system.
     1177 */
     1178rtems_status_code
     1179rtems_capture_monitor (rtems_boolean enable)
     1180{
     1181  rtems_interrupt_level level;
     1182
     1183  rtems_interrupt_disable (level);
     1184
     1185  if (!capture_records)
     1186  {
     1187    rtems_interrupt_enable (level);
     1188    return RTEMS_UNSATISFIED;
     1189  }
     1190
     1191  if (enable)
     1192    capture_flags |= RTEMS_CAPTURE_ONLY_MONITOR;
     1193  else
     1194    capture_flags &= ~RTEMS_CAPTURE_ONLY_MONITOR;
     1195
     1196  rtems_interrupt_enable (level);
     1197
     1198  return RTEMS_SUCCESSFUL;
     1199}
     1200
     1201/*
    10031202 * rtems_capture_flush
    10041203 *
     
    10171216
    10181217  for (task = capture_tasks; task != NULL; task = task->forw)
     1218  {
    10191219    task->flags &= ~RTEMS_CAPTURE_TRACED;
     1220    task->refcount = 0;
     1221  }
    10201222
    10211223  if (prime)
     
    10241226    capture_flags &= ~RTEMS_CAPTURE_OVERFLOW;
    10251227
    1026   capture_in     = capture_records;
    1027   capture_out    = 0;
    1028 
     1228  capture_count = 0;
     1229  capture_in    = capture_records;
     1230  capture_out   = 0;
     1231 
    10291232  rtems_interrupt_enable (level);
     1233
     1234  task = capture_tasks;
     1235
     1236  while (task)
     1237  {
     1238    rtems_capture_task_t* check = task;
     1239    task = task->forw;
     1240    rtems_capture_destroy_capture_task (check);
     1241  }
    10301242
    10311243  return RTEMS_SUCCESSFUL;
     
    10891301       control != NULL; )
    10901302  {
    1091     if (rtems_capture_match_name_id (name, id, control->name, control->id))
     1303    if (rtems_capture_match_name_id (control->name, control->id, name, id))
    10921304    {
    10931305      rtems_interrupt_disable (level);
     
    11111323      prev_control = &control->next;
    11121324      control      = control->next;
    1113       }
     1325    }
    11141326  }
    11151327
     
    11411353  for (control = capture_controls; control != NULL; control = control->next)
    11421354  {
    1143     if (rtems_capture_match_name_id (name, id, control->name, control->id))
     1355    if (rtems_capture_match_name_id (control->name, control->id, name, id))
    11441356    {
    11451357      rtems_interrupt_disable (level);
     
    12661478
    12671479/*
     1480 * rtems_capture_map_trigger
     1481 *
     1482 *  DESCRIPTION:
     1483 *
     1484 * Map the trigger to a bit mask.
     1485 *
     1486 */
     1487uint32_t
     1488rtems_capture_map_trigger (rtems_capture_trigger_t trigger)
     1489{
     1490  /*
     1491   * Transform the mode and trigger to a bit map.
     1492   */
     1493  switch (trigger)
     1494  {
     1495    case rtems_capture_switch:
     1496      return RTEMS_CAPTURE_SWITCH;
     1497    case rtems_capture_create:
     1498      return RTEMS_CAPTURE_CREATE;
     1499    case rtems_capture_start:
     1500      return RTEMS_CAPTURE_START;
     1501    case rtems_capture_restart:
     1502      return RTEMS_CAPTURE_RESTART;
     1503    case rtems_capture_delete:
     1504      return RTEMS_CAPTURE_DELETE;
     1505    case rtems_capture_begin:
     1506      return RTEMS_CAPTURE_BEGIN;
     1507    case rtems_capture_exitted:
     1508      return RTEMS_CAPTURE_EXITTED;
     1509    default:
     1510      break;
     1511  }
     1512  return 0;
     1513}
     1514
     1515/*
    12681516 * rtems_capture_set_trigger
    12691517 *
    12701518 *  DESCRIPTION:
    12711519 *
    1272  * This function sets an edge trigger. Left is the left side of
    1273  * the edge and right is right side of the edge. The trigger type
    1274  * can be -
    1275  *
    1276  *  FROM_ANY : a switch from any task to the right side of the edge.
    1277  *  TO_ANY   : a switch from the left side of the edge to any task.
    1278  *  FROM_TO  : a switch from the left side of the edge to the right
    1279  *             side of the edge.
     1520 * This function sets a trigger.
    12801521 *
    12811522 * This set trigger routine will create a capture control for the
     
    12881529 */
    12891530rtems_status_code
    1290 rtems_capture_set_trigger (rtems_name              from,
    1291                            rtems_id                from_id,
    1292                            rtems_name              to,
    1293                            rtems_id                to_id,
    1294                            rtems_capture_trigger_t trigger)
     1531rtems_capture_set_trigger (rtems_name                   from_name,
     1532                           rtems_id                     from_id,
     1533                           rtems_name                   to_name,
     1534                           rtems_id                     to_id,
     1535                           rtems_capture_trigger_mode_t mode,
     1536                           rtems_capture_trigger_t      trigger)
    12951537{
    12961538  rtems_capture_control_t* control;
    1297   int                      i;
    1298 
    1299   /*
    1300    * Find the capture control blocks for the from and to
    1301    * tasks.
    1302    */
    1303   if (trigger == rtems_capture_to_any)
    1304   {
    1305     control = rtems_capture_create_control (from, from_id);
     1539  uint32_t                 flags;
     1540
     1541  flags = rtems_capture_map_trigger (trigger);
     1542
     1543  /*
     1544   * The mode sets the opposite type of trigger. For example
     1545   * FROM ANY means trigger when the event happens TO this
     1546   * task. TO ANY means FROM this task.
     1547   */
     1548 
     1549  if (mode == rtems_capture_to_any)
     1550  {
     1551    control = rtems_capture_create_control (from_name, from_id);
    13061552    if (control == NULL)
    13071553      return RTEMS_NO_MEMORY;
    1308     control->flags |= RTEMS_CAPTURE_TO_ANY;
    1309   }
    1310 
    1311   if ((trigger == rtems_capture_from_to) ||
    1312       (trigger == rtems_capture_from_any))
    1313   {
    1314     control = rtems_capture_create_control (to, to_id);
     1554    control->from_triggers |= flags & RTEMS_CAPTURE_FROM_TRIGS;
     1555  }
     1556  else
     1557  {
     1558    control = rtems_capture_create_control (to_name, to_id);
    13151559    if (control == NULL)
    13161560      return RTEMS_NO_MEMORY;
    1317 
    1318     if (trigger == rtems_capture_from_any)
    1319       control->flags |= RTEMS_CAPTURE_FROM_ANY;
     1561    if (mode == rtems_capture_from_any)
     1562      control->to_triggers |= flags;
    13201563    else
    13211564    {
    1322       control->flags |= RTEMS_CAPTURE_FROM_TO;
     1565      rtems_boolean done = 0;
     1566      int           i;
     1567     
     1568      control->by_triggers |= flags;
     1569     
    13231570      for (i = 0; i < RTEMS_CAPTURE_TRIGGER_TASKS; i++)
    13241571      {
    1325         if (control->from[i] == 0)
     1572        if (rtems_capture_control_by_valid (control, i) &&
     1573            ((control->by[i].name == from_name) ||
     1574             (from_id && (control->by[i].id == from_id))))
    13261575        {
    1327           control->from[i]    = from;
    1328           control->from_id[i] = from_id;
     1576          control->by[i].trigger |= flags;
     1577          done = 1;
    13291578          break;
    13301579        }
     1580      }
     1581
     1582      if (!done)
     1583      {
     1584        for (i = 0; i < RTEMS_CAPTURE_TRIGGER_TASKS; i++)
     1585        {
     1586          if (!rtems_capture_control_by_valid (control, i))
     1587          {
     1588            control->by_valid |= RTEMS_CAPTURE_CONTROL_FROM_MASK (i);
     1589            control->by[i].name = from_name;
     1590            control->by[i].id = from_id;
     1591            control->by[i].trigger = flags;
     1592            done = 1;
     1593            break;
     1594          }
     1595        }
     1596      }
     1597
     1598      if (!done)
     1599        return RTEMS_TOO_MANY;
     1600    }
     1601  }
     1602  return RTEMS_SUCCESSFUL;
     1603}
     1604
     1605/*
     1606 * rtems_capture_clear_trigger
     1607 *
     1608 *  DESCRIPTION:
     1609 *
     1610 * This function clear a trigger.
     1611 */
     1612rtems_status_code
     1613rtems_capture_clear_trigger (rtems_name                   from_name,
     1614                             rtems_id                     from_id,
     1615                             rtems_name                   to_name,
     1616                             rtems_id                     to_id,
     1617                             rtems_capture_trigger_mode_t mode,
     1618                             rtems_capture_trigger_t      trigger)
     1619{
     1620  rtems_capture_control_t* control;
     1621  uint32_t                 flags;
     1622
     1623  flags = rtems_capture_map_trigger (trigger);
     1624 
     1625  if (mode == rtems_capture_to_any)
     1626  {
     1627    control = rtems_capture_find_control (from_name, from_id);
     1628    if (control == NULL)
     1629    {
     1630      if (from_id)
     1631        return RTEMS_INVALID_ID;
     1632      return RTEMS_INVALID_NAME;
     1633    }
     1634    control->from_triggers &= ~flags;
     1635  }
     1636  else
     1637  {
     1638    control = rtems_capture_find_control (to_name, to_id);
     1639    if (control == NULL)
     1640    {
     1641      if (to_id)
     1642        return RTEMS_INVALID_ID;
     1643      return RTEMS_INVALID_NAME;
     1644    }
     1645    if (mode == rtems_capture_from_any)
     1646      control->to_triggers &= ~flags;
     1647    else
     1648    {
     1649      rtems_boolean done = 0;
     1650      int           i;
     1651     
     1652      control->by_triggers &= ~flags;
     1653     
     1654      for (i = 0; i < RTEMS_CAPTURE_TRIGGER_TASKS; i++)
     1655      {
     1656        if (rtems_capture_control_by_valid (control, i) &&
     1657            ((control->by[i].name == from_name) ||
     1658             (control->by[i].id == from_id)))
     1659        {
     1660          control->by[i].trigger &= ~trigger;
     1661          if (control->by[i].trigger == 0)
     1662            control->by_valid &= ~RTEMS_CAPTURE_CONTROL_FROM_MASK (i);
     1663          done = 1;
     1664          break;
     1665        }
     1666      }
     1667
     1668      if (!done)
     1669      {
     1670        if (from_id)
     1671          return RTEMS_INVALID_ID;
     1672        return RTEMS_INVALID_NAME;
    13311673      }
    13321674    }
     
    13671709 */
    13681710rtems_status_code
    1369 rtems_capture_read (uint32_t           threshold,
    1370                     uint32_t           timeout,
    1371                     uint32_t  *        read,
     1711rtems_capture_read (uint32_t                 threshold,
     1712                    uint32_t                 timeout,
     1713                    uint32_t*                read,
    13721714                    rtems_capture_record_t** recs)
    13731715{
    13741716  rtems_interrupt_level level;
    13751717  rtems_status_code     sc = RTEMS_SUCCESSFUL;
    1376   uint32_t        count;
     1718  uint32_t              count;
    13771719
    13781720  *read = 0;
     
    14561798  }
    14571799
    1458   rtems_interrupt_disable (level);
    1459 
    1460   capture_flags &= ~RTEMS_CAPTURE_READER_ACTIVE;
    1461 
    1462   rtems_interrupt_enable (level);
    1463 
    14641800  return sc;
    14651801}
     
    14741810 */
    14751811rtems_status_code
    1476 rtems_capture_release (uint32_t   count)
    1477 {
     1812rtems_capture_release (uint32_t count)
     1813{
     1814  rtems_capture_record_t* rec;
     1815  uint32_t                counted;
     1816 
    14781817  rtems_interrupt_level level;
    14791818
     
    14831822    count = capture_count;
    14841823
     1824  rtems_interrupt_enable (level);
     1825
     1826  counted = count;
     1827 
     1828  rec = &capture_records[capture_out];
     1829
     1830  while (counted--)
     1831  {
     1832    rtems_capture_refcount_down (rec->task);
     1833    rtems_capture_destroy_capture_task (rec->task);
     1834    rec++;
     1835  }
     1836 
     1837  rtems_interrupt_disable (level);
     1838
    14851839  capture_count -= count;
    14861840
    1487   capture_out = (capture_count + count) % capture_size;
     1841  capture_out = (capture_out + count) % capture_size;
     1842
     1843  capture_flags &= ~RTEMS_CAPTURE_READER_ACTIVE;
    14881844
    14891845  rtems_interrupt_enable (level);
     
    15491905  if (task->tcb)
    15501906  {
    1551     uint32_t  * st;
    1552     uint32_t  * s;
     1907    uint32_t* st;
     1908    uint32_t* s;
    15531909
    15541910    /*
     
    15661922
    15671923    task->stack_clean =
    1568       s - (uint32_t  *) task->tcb->Start.Initial_stack.area;
     1924      s - (uint32_t*) task->tcb->Start.Initial_stack.area;
    15691925  }
    15701926
  • cpukit/libmisc/capture/capture.h

    rf41dd23 r1374fd3  
    2323
    2424  RTEMS Performance Monitoring and Measurement Framework.
    25 
    2625  This is the Capture Engine component.
    2726
     
    4342
    4443/**
     44 * rtems_capture_from_t
     45 *
     46 *  DESCRIPTION:
     47 *
     48 * A from capture is a task id and a mask for the type of
     49 * from trigger we are interested in. The mask uses the same
     50 * bit maps as the flags field in the control structure. There
     51 * will only be a from type trigger if the flags in the control
     52 * structure has the specific *_BY bit set.
     53 */
     54typedef struct rtems_capture_from_s
     55{
     56  rtems_name name;
     57  rtems_id   id;
     58  uint32_t   trigger;
     59} rtems_capture_from_t;
     60
     61/**
    4562 * rtems_capture_control_t
    4663 *
     
    4865 *
    4966 * RTEMS control holds the trigger and watch configuration for a group of
    50  * tasks with the same name.
     67 * tasks with the same name. The flags hold global control flags.
     68 *
     69 * The to_triggers fields holds triggers TO this task. The from_triggers holds
     70 * triggers from this task. The by_triggers is an OR or triggers which are
     71 * caused BY the task listed TO this task. The by_valid flag which entries
     72 * in by are valid.
    5173 */
    5274typedef struct rtems_capture_control_s
     
    5476  rtems_name                      name;
    5577  rtems_id                        id;
    56   uint32_t                  flags;
    57   rtems_name                      from[RTEMS_CAPTURE_TRIGGER_TASKS];
    58   rtems_id                        from_id[RTEMS_CAPTURE_TRIGGER_TASKS];
     78  uint32_t                        flags;
     79  uint32_t                        to_triggers;
     80  uint32_t                        from_triggers;
     81  uint32_t                        by_triggers;
     82  uint32_t                        by_valid;
     83  rtems_capture_from_t            by[RTEMS_CAPTURE_TRIGGER_TASKS];
    5984  struct rtems_capture_control_s* next;
    6085} rtems_capture_control_t;
    6186
    6287/**
     88 * The from_valid mask.
     89 */
     90#define RTEMS_CAPTURE_CONTROL_FROM_MASK(_s) \
     91 (1 << (RTEMS_CAPTURE_TRIGGER_TASKS - ((_s) + 1)))
     92
     93/**
    6394 * Control flags.
    6495 */
    6596#define RTEMS_CAPTURE_WATCH         (1 << 0)
    66 #define RTEMS_CAPTURE_FROM_ANY      (1 << 1)
    67 #define RTEMS_CAPTURE_TO_ANY        (1 << 2)
    68 #define RTEMS_CAPTURE_FROM_TO       (1 << 3)
    69 
     97
     98/**
     99 * Control triggers.
     100 */
     101#define RTEMS_CAPTURE_SWITCH        (1 << 0)
     102#define RTEMS_CAPTURE_CREATE        (1 << 1)
     103#define RTEMS_CAPTURE_START         (1 << 2)
     104#define RTEMS_CAPTURE_RESTART       (1 << 3)
     105#define RTEMS_CAPTURE_DELETE        (1 << 4)
     106#define RTEMS_CAPTURE_BEGIN         (1 << 5)
     107#define RTEMS_CAPTURE_EXITTED       (1 << 6)
     108
     109#define RTEMS_CAPTURE_FROM_TRIGS    (RTEMS_CAPTURE_SWITCH  | \
     110                                     RTEMS_CAPTURE_CREATE | \
     111                                     RTEMS_CAPTURE_START | \
     112                                     RTEMS_CAPTURE_RESTART | \
     113                                     RTEMS_CAPTURE_DELETE)
     114
     115#define RTEMS_CAPTURE_TO_TRIGS      (RTEMS_CAPTURE_SWITCH | \
     116                                     RTEMS_CAPTURE_CREATE | \
     117                                     RTEMS_CAPTURE_START | \
     118                                     RTEMS_CAPTURE_RESTART | \
     119                                     RTEMS_CAPTURE_DELETE | \
     120                                     RTEMS_CAPTURE_BEGIN | \
     121                                     RTEMS_CAPTURE_EXITTED)
     122                                     
    70123/**
    71124 * rtems_capture_control_t
     
    75128 * RTEMS capture control provdes the information about a task, along
    76129 * with its trigger state. The control is referenced by each
    77  * capture record. This is* information neeed by the decoder. The
     130 * capture record. This is information neeed by the decoder. The
    78131 * capture record cannot assume the task will exist when the record is
    79132 * dumped via the target interface so task info needed for tracing is
    80  * copied and held here.
    81  *
    82  * The inline heper functions provide more details about the info
     133 * copied and held here. Once the references in the trace buffer
     134 * have been removed and the task is deleted this structure is
     135 * released back to the heap.
     136 *
     137 * The inline helper functions provide more details about the info
    83138 * contained in this structure.
    84139 *
     
    90145  rtems_name                   name;
    91146  rtems_id                     id;
    92   uint32_t               flags;
     147  uint32_t                     flags;
     148  uint32_t                     refcount;
    93149  rtems_tcb*                   tcb;
    94   uint32_t               in;
    95   uint32_t               out;
     150  uint32_t                     in;
     151  uint32_t                     out;
    96152  rtems_task_priority          start_priority;
    97   uint32_t               stack_size;
    98   uint32_t               stack_clean;
    99   uint32_t               ticks;
    100   uint32_t               tick_offset;
    101   uint32_t               ticks_in;
    102   uint32_t               tick_offset_in;
    103   uint32_t               last_ticks;
    104   uint32_t               last_tick_offset;
     153  uint32_t                     stack_size;
     154  uint32_t                     stack_clean;
     155  uint32_t                     ticks;
     156  uint32_t                     tick_offset;
     157  uint32_t                     ticks_in;
     158  uint32_t                     tick_offset_in;
     159  uint32_t                     last_ticks;
     160  uint32_t                     last_tick_offset;
    105161  rtems_capture_control_t*     control;
    106162  struct rtems_capture_task_s* forw;
     
    125181{
    126182  rtems_capture_task_t* task;
    127   uint32_t        events;
    128   uint32_t        ticks;
    129   uint32_t        tick_offset;
     183  uint32_t              events;
     184  uint32_t              ticks;
     185  uint32_t              tick_offset;
    130186} rtems_capture_record_t;
    131187
     
    133189 * The capture record event flags.
    134190 */
    135 #define RTEMS_CAPTURE_REAL_PRI_EVENT_MASK UINT32_C(0x000000ff)
    136 #define RTEMS_CAPTURE_CURR_PRI_EVENT_MASK UINT32_C(0x0000ff00)
     191#define RTEMS_CAPTURE_REAL_PRI_EVENT_MASK UINT32_C (0x000000ff)
     192#define RTEMS_CAPTURE_CURR_PRI_EVENT_MASK UINT32_C (0x0000ff00)
    137193#define RTEMS_CAPTURE_REAL_PRIORITY_EVENT (0)
    138194#define RTEMS_CAPTURE_CURR_PRIORITY_EVENT (8)
    139195#define RTEMS_CAPTURE_EVENT_START         (16)
    140 #define RTEMS_CAPTURE_CREATED_BY_EVENT    UINT32_C(0x00010000)
    141 #define RTEMS_CAPTURE_CREATED_EVENT       UINT32_C(0x00020000)
    142 #define RTEMS_CAPTURE_STARTED_BY_EVENT    UINT32_C(0x00040000)
    143 #define RTEMS_CAPTURE_STARTED_EVENT       UINT32_C(0x00080000)
    144 #define RTEMS_CAPTURE_RESTARTED_BY_EVENT  UINT32_C(0x00100000)
    145 #define RTEMS_CAPTURE_RESTARTED_EVENT     UINT32_C(0x00200000)
    146 #define RTEMS_CAPTURE_DELETED_BY_EVENT    UINT32_C(0x00400000)
    147 #define RTEMS_CAPTURE_DELETED_EVENT       UINT32_C(0x00800000)
    148 #define RTEMS_CAPTURE_BEGIN_EVENT         UINT32_C(0x01000000)
    149 #define RTEMS_CAPTURE_EXITTED_EVENT       UINT32_C(0x02000000)
    150 #define RTEMS_CAPTURE_SWITCHED_OUT_EVENT  UINT32_C(0x04000000)
    151 #define RTEMS_CAPTURE_SWITCHED_IN_EVENT   UINT32_C(0x08000000)
    152 #define RTEMS_CAPTURE_TIMESTAMP           UINT32_C(0x10000000)
     196#define RTEMS_CAPTURE_CREATED_BY_EVENT    UINT32_C (0x00010000)
     197#define RTEMS_CAPTURE_CREATED_EVENT       UINT32_C (0x00020000)
     198#define RTEMS_CAPTURE_STARTED_BY_EVENT    UINT32_C (0x00040000)
     199#define RTEMS_CAPTURE_STARTED_EVENT       UINT32_C (0x00080000)
     200#define RTEMS_CAPTURE_RESTARTED_BY_EVENT  UINT32_C (0x00100000)
     201#define RTEMS_CAPTURE_RESTARTED_EVENT     UINT32_C (0x00200000)
     202#define RTEMS_CAPTURE_DELETED_BY_EVENT    UINT32_C (0x00400000)
     203#define RTEMS_CAPTURE_DELETED_EVENT       UINT32_C (0x00800000)
     204#define RTEMS_CAPTURE_BEGIN_EVENT         UINT32_C (0x01000000)
     205#define RTEMS_CAPTURE_EXITTED_EVENT       UINT32_C (0x02000000)
     206#define RTEMS_CAPTURE_SWITCHED_OUT_EVENT  UINT32_C (0x04000000)
     207#define RTEMS_CAPTURE_SWITCHED_IN_EVENT   UINT32_C (0x08000000)
     208#define RTEMS_CAPTURE_TIMESTAMP           UINT32_C (0x10000000)
    153209#define RTEMS_CAPTURE_EVENT_END           (28)
    154210
    155211/**
    156  * rtems_capture_trigger_t
    157  *
    158  *  DESCRIPTION:
    159  *
    160  * The types of triggers that exist. FIXME: add more here.
    161  */
    162 typedef enum rtems_capture_trigger_t
     212 * rtems_capture_trigger_mode_t
     213 *
     214 *  DESCRIPTION:
     215 *
     216 * The types of trigger modes that exist.
     217 */
     218typedef enum rtems_capture_trigger_mode_e
    163219{
    164220  rtems_capture_to_any,
    165221  rtems_capture_from_any,
    166222  rtems_capture_from_to
     223} rtems_capture_trigger_mode_t;
     224
     225/**
     226 * rtems_capture_trigger_t
     227 *
     228 *  DESCRIPTION:
     229 *
     230 * The types of triggers that exist.
     231 */
     232typedef enum rtems_capture_trigger_e
     233{
     234  rtems_capture_switch,
     235  rtems_capture_create,
     236  rtems_capture_start,
     237  rtems_capture_restart,
     238  rtems_capture_delete,
     239  rtems_capture_begin,
     240  rtems_capture_exitted
    167241} rtems_capture_trigger_t;
    168242
     
    178252
    179253typedef void (*rtems_capture_timestamp)
    180                 (uint32_t  * ticks, uint32_t  * micro);
     254                (uint32_t* ticks, uint32_t* micro);
    181255
    182256/**
     
    185259 *  DESCRIPTION:
    186260 *
    187  * This function initialises the realtime trace manager allocating the capture
    188  * buffer. It is assumed we have a working heap at stage of initialisation.
    189  *
    190  */
    191 rtems_status_code
    192 rtems_capture_open (uint32_t          size,
     261 * This function initialises the realtime trace manager allocating the
     262 * capture buffer. It is assumed we have a working heap at stage of
     263 * initialisation.
     264 *
     265 */
     266rtems_status_code
     267rtems_capture_open (uint32_t                size,
    193268                    rtems_capture_timestamp timestamp);
    194 
    195 /**
    196  * rtems_capture_free_info_on_task_delete
    197  *
    198  *  DESCRIPTION:
    199  *
    200  * If non-zero task informaion if freed when a task is deleted.
    201  *
    202  */
    203 extern int rtems_capture_free_info_on_task_delete;
    204269
    205270/**
     
    223288rtems_status_code
    224289rtems_capture_control (rtems_boolean enable);
     290
     291/**
     292 * rtems_capture_monitor
     293 *
     294 *  DESCRIPTION:
     295 *
     296 * This function enable the monitor mode. When in the monitor mode
     297 * the tasks are monitored but no data is saved. This can be used
     298 * to profile the load on a system.
     299 */
     300rtems_status_code
     301rtems_capture_monitor (rtems_boolean enable);
    225302
    226303/*
     
    269346 */
    270347rtems_status_code
    271 rtems_capture_watch_ctrl (rtems_name name, rtems_id id, rtems_boolean enable);
     348rtems_capture_watch_ctrl (rtems_name    name,
     349                          rtems_id      id,
     350                          rtems_boolean enable);
    272351
    273352/**
     
    276355 *  DESCRIPTION:
    277356 *
    278  * This function allows control of a global watch. The watch can be enabled or
    279  * disabled. A global watch configures all tasks below the ceiling and above
    280  * the floor to be traced.
     357 * This function allows control of a global watch. The watch can
     358 * be enabled or disabled. A global watch configures all tasks below
     359 * the ceiling and above the floor to be traced.
    281360 */
    282361rtems_status_code
     
    344423 *  DESCRIPTION:
    345424 *
    346  * This function sets an edge trigger. Left is the left side of
    347  * the edge and right is right side of the edge. The trigger type
    348  * can be -
    349  *
    350  *  FROM_ANY : a switch from any task to the right side of the edge.
    351  *  TO_ANY   : a switch from the left side of the edge to any task.
    352  *  FROM_TO  : a switch from the left side of the edge to the right
    353  *             side of the edge.
     425 * This function sets a trigger.
    354426 *
    355427 * This set trigger routine will create a trace control for the
     
    362434 */
    363435rtems_status_code
    364 rtems_capture_set_trigger (rtems_name              from,
    365                            rtems_id                from_id,
    366                            rtems_name              to,
    367                            rtems_id                to_id,
    368                            rtems_capture_trigger_t trigger);
     436rtems_capture_set_trigger (rtems_name                   from_name,
     437                           rtems_id                     from_id,
     438                           rtems_name                   to_name,
     439                           rtems_id                     to_id,
     440                           rtems_capture_trigger_mode_t mode,
     441                           rtems_capture_trigger_t      trigger);
     442
     443/**
     444 * rtems_capture_clear_trigger
     445 *
     446 *  DESCRIPTION:
     447 *
     448 * This function clears a trigger.
     449 *
     450 * This clear trigger routine will not clear a watch.
     451 */
     452rtems_status_code
     453rtems_capture_clear_trigger (rtems_name                   from_name,
     454                             rtems_id                     from_id,
     455                             rtems_name                   to_name,
     456                             rtems_id                     to_id,
     457                             rtems_capture_trigger_mode_t mode,
     458                             rtems_capture_trigger_t      trigger);
    369459
    370460/**
     
    395485 * a user configured latiency to be applied for single events.
    396486 *
    397  * The 'timeout' parameter is in micro-seconds. A value of 0 will disable
    398  * the timeout.
    399  *
    400  */
    401 rtems_status_code
    402 rtems_capture_read (uint32_t           threshold,
    403                     uint32_t           timeout,
    404                     uint32_t  *        read,
     487 * The 'timeout' parameter is in micro-seconds. A value of 0 will
     488 * disable the timeout.
     489 *
     490 */
     491rtems_status_code
     492rtems_capture_read (uint32_t                 threshold,
     493                    uint32_t                 timeout,
     494                    uint32_t*                read,
    405495                    rtems_capture_record_t** recs);
    406496
     
    414504 */
    415505rtems_status_code
    416 rtems_capture_release (uint32_t   count);
     506rtems_capture_release (uint32_t count);
    417507
    418508/**
     
    826916
    827917/**
    828  * rtems_capture_control_from_name
    829  *
    830  *  DESCRIPTION:
    831  *
    832  * This function returns the control from task name.
     918 * rtems_capture_control_to_triggers
     919 *
     920 *  DESCRIPTION:
     921 *
     922 * This function returns the task control to triggers.
     923 */
     924static inline uint32_t
     925rtems_capture_control_to_triggers (rtems_capture_control_t* control)
     926{
     927  return control->to_triggers;
     928}
     929
     930/**
     931 * rtems_capture_control_from_triggers
     932 *
     933 *  DESCRIPTION:
     934 *
     935 * This function returns the task control from triggers.
     936 */
     937static inline uint32_t
     938rtems_capture_control_from_triggers (rtems_capture_control_t* control)
     939{
     940  return control->from_triggers;
     941}
     942
     943/**
     944 * rtems_capture_control_all_by_triggers
     945 *
     946 *  DESCRIPTION:
     947 *
     948 * This function returns the task control by triggers.
     949 */
     950static inline uint32_t
     951rtems_capture_control_all_by_triggers (rtems_capture_control_t* control)
     952{
     953  return control->by_triggers;
     954}
     955
     956/**
     957 * rtems_capture_control_by_valid
     958 *
     959 *  DESCRIPTION:
     960 *
     961 * This function returns the control valid BY flags.
     962 */
     963static inline int
     964rtems_capture_control_by_valid (rtems_capture_control_t* control, int slot)
     965{
     966  return control->by_valid & RTEMS_CAPTURE_CONTROL_FROM_MASK (slot);
     967}
     968
     969/**
     970 * rtems_capture_control_by_name
     971 *
     972 *  DESCRIPTION:
     973 *
     974 * This function returns the control BY task name.
    833975 */
    834976static inline rtems_name
    835 rtems_capture_control_from_name (rtems_capture_control_t* control, int from)
    836 {
    837   if (from < RTEMS_CAPTURE_TRIGGER_TASKS)
    838     return control->from[from];
    839   return control->from[0];
    840 }
    841 
    842 /**
    843  * rtems_capture_control_from_id
    844  *
    845  *  DESCRIPTION:
    846  *
    847  * This function returns the control from task id.
     977rtems_capture_control_by_name (rtems_capture_control_t* control, int by)
     978{
     979  if (by < RTEMS_CAPTURE_TRIGGER_TASKS)
     980    return control->by[by].name;
     981  return control->by[0].name;
     982}
     983
     984/**
     985 * rtems_capture_control_by_id
     986 *
     987 *  DESCRIPTION:
     988 *
     989 * This function returns the control BY task id.
    848990 */
    849991static inline rtems_id
    850 rtems_capture_control_from_id (rtems_capture_control_t* control, int from)
    851 {
    852   if (from < RTEMS_CAPTURE_TRIGGER_TASKS)
    853     return control->from_id[from];
    854   return control->from_id[0];
     992rtems_capture_control_by_id (rtems_capture_control_t* control, int by)
     993{
     994  if (by < RTEMS_CAPTURE_TRIGGER_TASKS)
     995    return control->by[by].id;
     996  return control->by[0].id;
     997}
     998
     999/**
     1000 * rtems_capture_control_by_triggers
     1001 *
     1002 *  DESCRIPTION:
     1003 *
     1004 * This function returns the control BY task triggers.
     1005 */
     1006static inline uint32_t
     1007rtems_capture_control_by_triggers (rtems_capture_control_t* control,
     1008                                   int                      by)
     1009{
     1010  if (by < RTEMS_CAPTURE_TRIGGER_TASKS)
     1011    return control->by[by].trigger;
     1012  return control->by[0].trigger;
    8551013}
    8561014
     
    8671025{
    8681026  rtems_capture_control_t* control = rtems_capture_get_control_list ();
    869   uint32_t           count = 0;
     1027  uint32_t                 count = 0;
    8701028
    8711029  while (control)
Note: See TracChangeset for help on using the changeset viewer.