source: rtems/cpukit/libmisc/capture/capture_support.c @ 04a13bd

4.115
Last change on this file since 04a13bd was 04a13bd, checked in by Jennifer Averett <jennifer.averett@…>, on 11/06/14 at 14:26:38

capture: Move print methods out of cli for reuse.

Methods to print the data were moved from capture-cli into
a support area and are no longer static so that they can
be shared by test routines, or application code that wants
to use the capture engine without the shell interface.

  • Property mode set to 100644
File size: 9.2 KB
Line 
1/*
2  ------------------------------------------------------------------------
3
4  Copyright Objective Design Systems Pty Ltd, 2002
5  All rights reserved Objective Design Systems Pty Ltd, 2002
6  Chris Johns (ccj@acm.org)
7
8  COPYRIGHT (c) 1989-2014.
9  On-Line Applications Research Corporation (OAR).
10
11  The license and distribution terms for this file may be
12  found in the file LICENSE in this distribution.
13
14  This software with is provided ``as is'' and with NO WARRANTY.
15
16  ------------------------------------------------------------------------
17
18  RTEMS Performance Monitoring and Measurement Framework.
19
20  This is a set of print support routines that may be shared between
21  the RTEMS monitor and direct callers of the capture engine.
22
23*/
24
25#ifdef HAVE_CONFIG_H
26#include "config.h"
27#endif
28
29#include <ctype.h>
30#include <stdlib.h>
31#include <stdio.h>
32#include <string.h>
33#include <inttypes.h>
34
35#include <rtems.h>
36#include <rtems/monitor.h>
37#include <rtems/captureimpl.h>
38
39/*
40 * Structure used during printing of the capture records.
41 */
42
43typedef struct {
44  rtems_capture_record_t* rec;
45  uint32_t                read;
46  uint32_t                last_t;
47  uint32_t                printed;
48} ctrace_per_cpu_t;
49
50/*
51 * rtems_catpure_print_uptime
52 *
53 *  DESCRIPTION:
54 *
55 * This function prints the nanosecond uptime to stdout.
56 */
57void
58rtems_capture_print_timestamp (uint64_t uptime)
59{
60  uint32_t hours;
61  uint32_t minutes;
62  uint32_t seconds;
63  uint32_t nanosecs;
64
65  seconds  = uptime / 1000000000LLU;
66  minutes  = seconds / 60;
67  hours    = minutes / 60;
68  minutes  = minutes % 60;
69  seconds  = seconds % 60;
70  nanosecs = uptime % 1000000000;
71
72  fprintf (stdout, "%5lu:%02lu:%02lu.%09lu", hours, minutes, seconds, nanosecs);
73}
74
75void
76rtems_capture_print_record_task( uint32_t cpu, rtems_capture_record_t* rec)
77{
78  rtems_capture_task_record_t* task_rec = (rtems_capture_task_record_t*) rec;
79
80  fprintf(stdout,"%2" PRId32 " ", cpu);
81  rtems_capture_print_timestamp (rec->time);
82  fprintf (stdout, "            ");
83  rtems_monitor_dump_id (rec->task_id);
84  fprintf (stdout, " %c%c%c%c",
85           (char) (task_rec->name >> 24) & 0xff,
86           (char) (task_rec->name >> 16) & 0xff,
87           (char) (task_rec->name >> 8) & 0xff,
88           (char) (task_rec->name >> 0) & 0xff);
89  fprintf(stdout, " %3" PRId32 " %3" PRId32 " ",
90             (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
91             (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff );
92   fprintf (stdout, "%3" PRId32   " %3" PRId32 "  TASK_RECORD\n",
93            task_rec->start_priority,
94            task_rec->stack_size);
95}
96
97void
98rtems_capture_print_record_capture(
99  uint32_t                cpu,
100  rtems_capture_record_t* rec,
101  uint64_t                diff
102){
103  uint32_t                     event;
104  int                          e;
105
106  event = rec->events >> RTEMS_CAPTURE_EVENT_START;
107  for (e = RTEMS_CAPTURE_EVENT_START; e < RTEMS_CAPTURE_EVENT_END; e++)
108  {
109    if (event & 1)
110    {
111      fprintf(stdout,"%2" PRId32 " ", cpu);
112      rtems_capture_print_timestamp (rec->time);
113      fprintf (stdout, " %10" PRId64 " ", diff);
114      rtems_monitor_dump_id (rec->task_id);
115      fprintf(stdout, "      %3" PRId32 " %3" PRId32 "           %s\n",
116             (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
117             (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
118             rtems_capture_event_text (e));
119    }
120    event >>= 1;
121  }
122}
123
124/*
125 *  rtems_capture_print_trace_records
126 *
127 *  DESCRIPTION:
128 *
129 * This function is a monitor command that dumps trace records.
130 *
131 */
132
133void
134rtems_capture_print_trace_records ( int total, bool csv )
135{
136  rtems_status_code       sc;
137  int                     count;
138  ctrace_per_cpu_t*       per_cpu;
139  uint8_t*                ptr;
140  uint32_t                i;
141  uint32_t                cpu = 0;
142  rtems_capture_record_t* rec_out;
143
144  count = rtems_get_processor_count();
145  per_cpu = calloc( count, sizeof(*per_cpu) );
146
147  while (total)
148  {
149    /* Prime the per_cpu data */
150    for (i=0; i< count; i++) {
151      if ( per_cpu[i].read == 0 ) {
152        sc = rtems_capture_read (i, &per_cpu[i].read, &per_cpu[i].rec);
153        if (sc != RTEMS_SUCCESSFUL)
154        {
155          fprintf (stdout, "error: trace read failed: %s\n", rtems_status_text (sc));
156          rtems_capture_flush (0);
157          return;
158        }
159        /* Release the buffer if there are no records to read */
160        if (per_cpu[i].read == 0)
161          rtems_capture_release (i, 0);
162      }
163    }
164
165    /* Find the next record to print */
166    rec_out = NULL;
167    for (i=0; i< count; i++) {
168
169      if ((rec_out == NULL) ||
170          ((per_cpu[i].read != 0) && (rec_out->time > per_cpu[i].rec->time))) {
171        rec_out = per_cpu[i].rec;
172        cpu = i;
173      }
174    }
175
176    /*  If we have read all the records abort. */
177    if (rec_out == NULL)
178      break;
179
180    /* Print the record */
181    if (csv)
182      fprintf (stdout, "%03" PRIu32 ",%08" PRIu32 ",%03" PRIu32
183                   ",%03" PRIu32 ",%04" PRIx32 ",%" PRId64 "\n",
184                 cpu, rec_out->task_id,
185                 (rec_out->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff,
186                 (rec_out->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff,
187                 (rec_out->events >> RTEMS_CAPTURE_EVENT_START),
188                 (uint64_t) rec_out->time);
189    else {
190      if ((rec_out->events >> RTEMS_CAPTURE_EVENT_START) == 0)
191          rtems_capture_print_record_task(cpu, rec_out );
192      else {
193        uint64_t diff = 0;
194        if (per_cpu[cpu].last_t)
195          diff = rec_out->time - per_cpu[cpu].last_t;
196        per_cpu[cpu].last_t = rec_out->time;
197
198        rtems_capture_print_record_capture( cpu, rec_out, diff );
199      }
200    }
201
202    /*
203     * If we have not printed all the records read
204     * increment to the next record.  If we have
205     * printed all records release the records printed.
206     */
207    per_cpu[cpu].printed++;
208    if (per_cpu[cpu].printed != per_cpu[cpu].read) {
209      ptr =  (uint8_t *)per_cpu[cpu].rec;
210      ptr += per_cpu[cpu].rec->size;
211      per_cpu[cpu].rec = (rtems_capture_record_t *)ptr;
212    } else {
213      rtems_capture_release (cpu, per_cpu[cpu].printed);
214      per_cpu[cpu].read = 0;
215      per_cpu[cpu].printed = 0;
216    }
217
218    total --;
219  }
220
221  /* Finished so release all the records that were printed. */
222  for (i=0; i< count; i++) {
223    if ( per_cpu[i].read != 0 )  {
224      rtems_capture_release( i, per_cpu[i].printed );
225    }
226  }
227
228  free( per_cpu );
229}
230
231void
232rtems_capture_print_watch_list ()
233{
234  rtems_capture_control_t* control = rtems_capture_get_control_list ();
235  rtems_task_priority      ceiling = rtems_capture_watch_get_ceiling ();
236  rtems_task_priority      floor = rtems_capture_watch_get_floor ();
237
238  fprintf (stdout, "watch priority ceiling is %" PRId32 "\n", ceiling);
239  fprintf (stdout, "watch priority floor is %" PRId32 "\n", floor);
240  fprintf (stdout, "global watch is %s\n",
241          rtems_capture_watch_global_on () ? "enabled" : "disabled");
242  fprintf (stdout, "total %" PRId32 "\n", rtems_capture_control_count ());
243
244  while (control)
245  {
246    uint32_t flags;
247    int      f;
248    int      fshowed;
249    int      lf;
250
251    fprintf (stdout, " ");
252    rtems_monitor_dump_id (rtems_capture_control_id (control));
253    fprintf (stdout, " ");
254    rtems_monitor_dump_name (rtems_capture_control_name (control));
255    flags = rtems_capture_control_flags (control);
256    fprintf (stdout, " %c%c ",
257             rtems_capture_watch_global_on () ? 'g' : '-',
258             flags & RTEMS_CAPTURE_WATCH ? 'w' : '-');
259    flags = rtems_capture_control_to_triggers (control);
260    fprintf (stdout, " T:%c%c%c%c%c%c%c",
261             flags & RTEMS_CAPTURE_SWITCH    ? 'S' : '-',
262             flags & RTEMS_CAPTURE_CREATE ? 'C' : '-',
263             flags & RTEMS_CAPTURE_START ? 'S' : '-',
264             flags & RTEMS_CAPTURE_RESTART ? 'R' : '-',
265             flags & RTEMS_CAPTURE_DELETE ? 'D' : '-',
266             flags & RTEMS_CAPTURE_BEGIN ? 'B' : '-',
267             flags & RTEMS_CAPTURE_EXITTED ? 'E' : '-');
268    flags = rtems_capture_control_from_triggers (control);
269    fprintf (stdout, " F:%c%c%c%c%c",
270             flags & RTEMS_CAPTURE_SWITCH  ? 'S' : '-',
271             flags & RTEMS_CAPTURE_CREATE  ? 'C' : '-',
272             flags & RTEMS_CAPTURE_START   ? 'S' : '-',
273             flags & RTEMS_CAPTURE_RESTART ? 'R' : '-',
274             flags & RTEMS_CAPTURE_DELETE  ? 'D' : '-');
275
276    for (f = 0, fshowed = 0, lf = 1; f < RTEMS_CAPTURE_TRIGGER_TASKS; f++)
277    {
278      if (rtems_capture_control_by_valid (control, f))
279      {
280        if (lf && ((fshowed % 3) == 0))
281        {
282          fprintf (stdout, "\n");
283          lf = 0;
284        }
285
286        fprintf (stdout, "  %2i:", f);
287        rtems_monitor_dump_name (rtems_capture_control_by_name (control, f));
288        fprintf (stdout, "/");
289        rtems_monitor_dump_id (rtems_capture_control_by_id (control, f));
290        flags = rtems_capture_control_by_triggers (control, f);
291        fprintf (stdout, ":%c%c%c%c%c",
292                 flags & RTEMS_CAPTURE_SWITCH  ? 'S' : '-',
293                 flags & RTEMS_CAPTURE_CREATE  ? 'C' : '-',
294                 flags & RTEMS_CAPTURE_START   ? 'S' : '-',
295                 flags & RTEMS_CAPTURE_RESTART ? 'R' : '-',
296                 flags & RTEMS_CAPTURE_DELETE  ? 'D' : '-');
297        fshowed++;
298        lf = 1;
299      }
300    }
301
302    if (lf)
303      fprintf (stdout, "\n");
304
305    control = rtems_capture_next_control (control);
306  }
307}
Note: See TracBrowser for help on using the repository browser.