1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2012. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may in |
---|
6 | * the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.org/license/LICENSE. |
---|
8 | */ |
---|
9 | |
---|
10 | #define CONFIGURE_INIT |
---|
11 | |
---|
12 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include "system.h" |
---|
17 | #include <ctype.h> |
---|
18 | #include <stdlib.h> |
---|
19 | #include <stdio.h> |
---|
20 | #include <string.h> |
---|
21 | #include <inttypes.h> |
---|
22 | |
---|
23 | #include <rtems.h> |
---|
24 | #include <rtems/capture-cli.h> |
---|
25 | #include <rtems/monitor.h> |
---|
26 | #include <rtems/shell.h> |
---|
27 | #include <assert.h> |
---|
28 | |
---|
29 | #define ASSERT_SC(sc) assert((sc) == RTEMS_SUCCESSFUL) |
---|
30 | |
---|
31 | /* forward declarations to avoid warnings */ |
---|
32 | rtems_task Init(rtems_task_argument argument); |
---|
33 | |
---|
34 | const char rtems_test_name[] = "CAPTURE ENGINE"; |
---|
35 | |
---|
36 | static void cwlist(void); |
---|
37 | static void ctrace(void); |
---|
38 | |
---|
39 | static void cwlist () |
---|
40 | { |
---|
41 | rtems_capture_control_t* control = rtems_capture_get_control_list (); |
---|
42 | rtems_task_priority ceiling = rtems_capture_watch_get_ceiling (); |
---|
43 | rtems_task_priority floor = rtems_capture_watch_get_floor (); |
---|
44 | |
---|
45 | fprintf (stdout, "watch priority ceiling is %" PRId32 "\n", ceiling); |
---|
46 | fprintf (stdout, "watch priority floor is %" PRId32 "\n", floor); |
---|
47 | fprintf (stdout, "global watch is %s\n", |
---|
48 | rtems_capture_watch_global_on () ? "enabled" : "disabled"); |
---|
49 | fprintf (stdout, "total %" PRId32 "\n", rtems_capture_control_count ()); |
---|
50 | |
---|
51 | while (control) |
---|
52 | { |
---|
53 | uint32_t flags; |
---|
54 | int f; |
---|
55 | int fshowed; |
---|
56 | int lf; |
---|
57 | |
---|
58 | fprintf (stdout, " "); |
---|
59 | rtems_monitor_dump_id (rtems_capture_control_id (control)); |
---|
60 | fprintf (stdout, " "); |
---|
61 | rtems_monitor_dump_name (rtems_capture_control_name (control)); |
---|
62 | flags = rtems_capture_control_flags (control); |
---|
63 | fprintf (stdout, " %c%c ", |
---|
64 | rtems_capture_watch_global_on () ? 'g' : '-', |
---|
65 | flags & RTEMS_CAPTURE_WATCH ? 'w' : '-'); |
---|
66 | flags = rtems_capture_control_to_triggers (control); |
---|
67 | fprintf (stdout, " T:%c%c%c%c%c%c%c", |
---|
68 | flags & RTEMS_CAPTURE_SWITCH ? 'S' : '-', |
---|
69 | flags & RTEMS_CAPTURE_CREATE ? 'C' : '-', |
---|
70 | flags & RTEMS_CAPTURE_START ? 'S' : '-', |
---|
71 | flags & RTEMS_CAPTURE_RESTART ? 'R' : '-', |
---|
72 | flags & RTEMS_CAPTURE_DELETE ? 'D' : '-', |
---|
73 | flags & RTEMS_CAPTURE_BEGIN ? 'B' : '-', |
---|
74 | flags & RTEMS_CAPTURE_EXITTED ? 'E' : '-'); |
---|
75 | flags = rtems_capture_control_from_triggers (control); |
---|
76 | fprintf (stdout, " F:%c%c%c%c%c", |
---|
77 | flags & RTEMS_CAPTURE_SWITCH ? 'S' : '-', |
---|
78 | flags & RTEMS_CAPTURE_CREATE ? 'C' : '-', |
---|
79 | flags & RTEMS_CAPTURE_START ? 'S' : '-', |
---|
80 | flags & RTEMS_CAPTURE_RESTART ? 'R' : '-', |
---|
81 | flags & RTEMS_CAPTURE_DELETE ? 'D' : '-'); |
---|
82 | |
---|
83 | for (f = 0, fshowed = 0, lf = 1; f < RTEMS_CAPTURE_TRIGGER_TASKS; f++) |
---|
84 | { |
---|
85 | if (rtems_capture_control_by_valid (control, f)) |
---|
86 | { |
---|
87 | if (lf && ((fshowed % 3) == 0)) |
---|
88 | { |
---|
89 | fprintf (stdout, "\n"); |
---|
90 | lf = 0; |
---|
91 | } |
---|
92 | |
---|
93 | fprintf (stdout, " %2i:", f); |
---|
94 | rtems_monitor_dump_name (rtems_capture_control_by_name (control, f)); |
---|
95 | fprintf (stdout, "/"); |
---|
96 | rtems_monitor_dump_id (rtems_capture_control_by_id (control, f)); |
---|
97 | flags = rtems_capture_control_by_triggers (control, f); |
---|
98 | fprintf (stdout, ":%c%c%c%c%c", |
---|
99 | flags & RTEMS_CAPTURE_SWITCH ? 'S' : '-', |
---|
100 | flags & RTEMS_CAPTURE_CREATE ? 'C' : '-', |
---|
101 | flags & RTEMS_CAPTURE_START ? 'S' : '-', |
---|
102 | flags & RTEMS_CAPTURE_RESTART ? 'R' : '-', |
---|
103 | flags & RTEMS_CAPTURE_DELETE ? 'D' : '-'); |
---|
104 | fshowed++; |
---|
105 | lf = 1; |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | if (lf) |
---|
110 | fprintf (stdout, "\n"); |
---|
111 | |
---|
112 | control = rtems_capture_next_control (control); |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | static void ctrace() |
---|
117 | { |
---|
118 | rtems_status_code sc; |
---|
119 | bool csv = false; |
---|
120 | static int dump_total = 22; |
---|
121 | int total; |
---|
122 | int count; |
---|
123 | uint32_t read; |
---|
124 | rtems_capture_record_t* rec; |
---|
125 | |
---|
126 | total = dump_total; |
---|
127 | |
---|
128 | while (total) |
---|
129 | { |
---|
130 | sc = rtems_capture_read (0, 0, &read, &rec); |
---|
131 | |
---|
132 | if (sc != RTEMS_SUCCESSFUL) |
---|
133 | { |
---|
134 | fprintf (stdout, "error: trace read failed: %s\n", rtems_status_text (sc)); |
---|
135 | rtems_capture_flush (0); |
---|
136 | return; |
---|
137 | } |
---|
138 | |
---|
139 | /* |
---|
140 | * If we have no records then just exist. We still need to release |
---|
141 | * the reader lock. |
---|
142 | */ |
---|
143 | |
---|
144 | if (read == 0) |
---|
145 | { |
---|
146 | rtems_capture_release (read); |
---|
147 | break; |
---|
148 | } |
---|
149 | |
---|
150 | count = total < read ? total : read; |
---|
151 | |
---|
152 | while (count--) |
---|
153 | { |
---|
154 | if (csv) |
---|
155 | fprintf (stdout, "%08" PRIxPTR ",%03" PRIu32 |
---|
156 | ",%03" PRIu32 ",%04" PRIx32 ",%" PRId64 "\n", |
---|
157 | (uintptr_t) rec->task, |
---|
158 | (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff, |
---|
159 | (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff, |
---|
160 | (rec->events >> RTEMS_CAPTURE_EVENT_START), |
---|
161 | (uint64_t) rec->time); |
---|
162 | else |
---|
163 | { |
---|
164 | uint32_t event; |
---|
165 | int e; |
---|
166 | |
---|
167 | event = rec->events >> RTEMS_CAPTURE_EVENT_START; |
---|
168 | |
---|
169 | for (e = RTEMS_CAPTURE_EVENT_START; e <= RTEMS_CAPTURE_EVENT_END; e++) |
---|
170 | { |
---|
171 | if (event & 1) |
---|
172 | { |
---|
173 | rtems_monitor_dump_id (rtems_capture_task_id (rec->task)); |
---|
174 | fprintf (stdout, " %c%c%c%c", |
---|
175 | (char) (rec->task->name >> 24) & 0xff, |
---|
176 | (char) (rec->task->name >> 16) & 0xff, |
---|
177 | (char) (rec->task->name >> 8) & 0xff, |
---|
178 | (char) (rec->task->name >> 0) & 0xff); |
---|
179 | fprintf (stdout, " %3" PRId32 " %3" PRId32 " %s\n", |
---|
180 | (rec->events >> RTEMS_CAPTURE_REAL_PRIORITY_EVENT) & 0xff, |
---|
181 | (rec->events >> RTEMS_CAPTURE_CURR_PRIORITY_EVENT) & 0xff, |
---|
182 | rtems_capture_event_text (e)); |
---|
183 | } |
---|
184 | event >>= 1; |
---|
185 | } |
---|
186 | } |
---|
187 | rec++; |
---|
188 | } |
---|
189 | |
---|
190 | count = total < read ? total : read; |
---|
191 | |
---|
192 | if (count < total) |
---|
193 | total -= count; |
---|
194 | else |
---|
195 | total = 0; |
---|
196 | |
---|
197 | rtems_capture_release (count); |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | rtems_task Init( |
---|
202 | rtems_task_argument ignored |
---|
203 | ) |
---|
204 | { |
---|
205 | #if BSP_SMALL_MEMORY |
---|
206 | printf("NO Capture Engine. MEMORY TOO SMALL"); |
---|
207 | #else |
---|
208 | rtems_status_code sc; |
---|
209 | rtems_task_priority old_priority; |
---|
210 | rtems_mode old_mode; |
---|
211 | rtems_name to_name = rtems_build_name('I', 'D', 'L', 'E');; |
---|
212 | |
---|
213 | rtems_test_begin(); |
---|
214 | |
---|
215 | #ifdef RTEMS_SMP |
---|
216 | printf("Capture Engine is broken due to recursive interrupt lock usage\n"); |
---|
217 | assert(0); |
---|
218 | #endif |
---|
219 | |
---|
220 | rtems_task_set_priority(RTEMS_SELF, 20, &old_priority); |
---|
221 | rtems_task_mode(RTEMS_PREEMPT, RTEMS_PREEMPT_MASK, &old_mode); |
---|
222 | |
---|
223 | sc = rtems_capture_open (5000, NULL); |
---|
224 | ASSERT_SC(sc); |
---|
225 | |
---|
226 | sc = rtems_capture_watch_ceiling (100); |
---|
227 | ASSERT_SC(sc); |
---|
228 | |
---|
229 | sc = rtems_capture_watch_floor (102); |
---|
230 | ASSERT_SC(sc); |
---|
231 | |
---|
232 | sc = rtems_capture_watch_global (true); |
---|
233 | ASSERT_SC(sc); |
---|
234 | |
---|
235 | sc = rtems_capture_set_trigger ( |
---|
236 | 0, |
---|
237 | 0, |
---|
238 | to_name, |
---|
239 | 0, |
---|
240 | rtems_capture_from_any, |
---|
241 | rtems_capture_switch |
---|
242 | ); |
---|
243 | ASSERT_SC(sc); |
---|
244 | |
---|
245 | cwlist(); |
---|
246 | |
---|
247 | sc = rtems_capture_control (true); |
---|
248 | ASSERT_SC(sc); |
---|
249 | |
---|
250 | capture_test_1(); |
---|
251 | |
---|
252 | ctrace(); |
---|
253 | ctrace(); |
---|
254 | |
---|
255 | rtems_test_end(); |
---|
256 | exit( 0 ); |
---|
257 | |
---|
258 | #endif |
---|
259 | } |
---|