2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 Copyright (c) 2005 Eliot Dresselhaus
18 Permission is hereby granted, free of charge, to any person obtaining
19 a copy of this software and associated documentation files (the
20 "Software"), to deal in the Software without restriction, including
21 without limitation the rights to use, copy, modify, merge, publish,
22 distribute, sublicense, and/or sell copies of the Software, and to
23 permit persons to whom the Software is furnished to do so, subject to
24 the following conditions:
26 The above copyright notice and this permission notice shall be
27 included in all copies or substantial portions of the Software.
29 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 #include <vppinfra/elog.h>
39 #include <vppinfra/error.h>
40 #include <vppinfra/format.h>
41 #include <vppinfra/random.h>
42 #include <vppinfra/serialize.h>
43 #include <vppinfra/unix.h>
46 g2_test_pattern (elog_main_t * em, int g2_test, char *dump_file)
50 elog_track_t *tracks = 0;
52 elog_init (em, 100000);
53 elog_enable_disable (em, 1 /* enable */ );
55 for (i = 0; i < 100; i++)
58 vec_validate (tracks, i);
60 t->name = (char *) format (0, "Track %3d", i + 1);
61 elog_track_register (em, t);
64 for (i = 0; i < 100; i++)
66 for (j = 0; j < 100; j++)
68 ELOG_TYPE_DECLARE (e) =
70 .format = "0: t%d event %d",.format_args = "i4i4",};
71 ELOG_TYPE_DECLARE (e2) =
73 .format = "1: t%d event %d",.format_args = "i4i4",};
80 ed = ELOG_TRACK_DATA (em, e, tracks[j]);
83 ed = ELOG_TRACK_DATA (em, e2, tracks[j]);
90 dump_file = "/tmp/g2_test.elog";
92 error = elog_write_file (em, dump_file, 1 /* flush ring */ );
95 clib_error_report (error);
100 test_elog_main (unformat_input_t * input)
102 clib_error_t *error = 0;
103 u32 i, n_iter, seed, max_events;
104 elog_main_t _em, *em = &_em;
107 char *dump_file, *load_file, *merge_file, **merge_files;
124 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
126 if (unformat (input, "iter %d", &n_iter))
128 else if (unformat (input, "seed %d", &seed))
130 else if (unformat (input, "dump %s", &dump_file))
132 else if (unformat (input, "load %s", &load_file))
134 else if (unformat (input, "tag %s", &tag))
135 vec_add1 (tags, tag);
136 else if (unformat (input, "merge %s", &merge_file))
137 vec_add1 (merge_files, merge_file);
139 else if (unformat (input, "verbose %=", &verbose, 1))
141 else if (unformat (input, "max-events %d", &max_events))
143 else if (unformat (input, "sample-time %f", &min_sample_time))
145 else if (unformat (input, "align-tweak %f", &align_tweak))
146 vec_add1 (align_tweaks, align_tweak);
147 else if (unformat (input, "g2-test %=", &g2_test, 1))
151 error = clib_error_create ("unknown input `%U'\n",
152 format_unformat_error, input);
159 g2_test_pattern (em, g2_test, dump_file);
166 if ((error = elog_read_file (em, load_file)))
170 else if (merge_files)
174 vec_clone (ems, merge_files);
176 /* Supply default tags as needed */
177 if (vec_len (tags) < vec_len (ems))
179 for (i = vec_len (tags); i < vec_len (ems); i++)
180 vec_add1 (tags, format (0, "F%d%c", i, 0));
183 elog_init (em, max_events);
184 for (i = 0; i < vec_len (ems); i++)
187 elog_read_file (i == 0 ? em : &ems[i], merge_files[i])))
192 if (i <= vec_len (align_tweaks))
193 align_tweak = align_tweaks[i - 1];
194 elog_merge (em, tags[0], &ems[i], tags[i], align_tweak);
201 #endif /* CLIB_UNIX */
205 elog_init (em, max_events);
206 elog_enable_disable (em, 1);
207 t[0] = unix_time_now ();
209 for (i = 0; i < n_iter; i++)
213 n = 1 + (random_u32 (&seed) % 128);
215 for (j = 0; j < n; j++)
216 sum += random_u32 (&seed);
225 ELOG (em, e, sum + 1);
234 ELOG_TYPE_DECLARE (e) =
236 .format = "fumble %s %.9f",.format_args =
237 "t4f4",.n_enum_strings = 4,.enum_strings =
239 "string0", "string1", "string2", "string3",},};
241 d = ELOG_DATA (em, e);
243 d->string_index = sum & 3;
244 d->f = (sum & 0xff) / 128.;
248 ELOG_TYPE_DECLARE (e) =
250 .format = "bar %d.%d.%d.%d",.format_args = "i1i1i1i1",};
251 ELOG_TRACK (my_track);
252 u8 *d = ELOG_TRACK_DATA (em, e, my_track);
260 ELOG_TYPE_DECLARE (e) =
262 .format = "bar `%s'",.format_args = "s20",};
269 d = ELOG_DATA (em, e);
270 v = format (0, "foo %d%c", i, 0);
271 clib_memcpy (d->s, v, clib_min (vec_len (v), sizeof (d->s)));
275 ELOG_TYPE_DECLARE (e) =
277 .format = "bar `%s'",.format_args = "T4",};
283 d = ELOG_DATA (em, e);
284 d->offset = elog_string (em, "string table %d", i);
290 t[1] = unix_time_now ();
292 while (t[1] - t[0] < min_sample_time);
299 elog_write_file (em, dump_file, 0 /* do not flush ring */ )))
306 elog_event_t *e, *es;
307 es = elog_get_events (em);
310 clib_warning ("%18.9f: %12U %U\n", e->time,
311 format_elog_track_name, em, e, format_elog_event, em,
318 clib_error_report (error);
324 main (int argc, char *argv[])
329 clib_mem_init (0, 3ULL << 30);
331 unformat_init_command_line (&i, argv);
332 r = test_elog_main (&i);
339 * @brief GDB callable function: vl - Return vector length of vector
341 * @param *p - void - address of vector
343 * @return length - u32
353 * @brief GDB callable function: pe - call pool_elts - number of elements in a pool
355 * @param *v - void - address of pool
357 * @return number - uword
360 #include <vppinfra/pool.h>
364 return (pool_elts (v));
367 #include <vppinfra/hash.h>
371 return (hash_elts (v));
375 * fd.io coding-style-patch-verification: ON
378 * eval: (c-set-style "gnu")