FD.io VPP  v16.06
Vector Packet Processing
elog_samples.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #include <vlib/vlib.h>
17 #include <vppinfra/elog.h>
18 
19 static inline void elog_four_int_sample (u32 *data)
20 {
21  ELOG_TYPE_DECLARE(e) =
22  {
23  .format = "four int: first %d second %d third %d fourth %d",
24  .format_args = "i4i4i4i4",
25  };
26  struct { u32 data[4];} * ed;
28  ed->data[0] = data[0];
29  ed->data[1] = data[1];
30  ed->data[2] = data[2];
31  ed->data[3] = data[3];
32 }
33 
34 static inline void elog_four_int_track_sample (u32 *data)
35 {
36  ELOG_TYPE_DECLARE(e) =
37  {
38  .format = "four_int_track: first %d second %d third %d fourth %d",
39  .format_args = "i4i4i4i4",
40  };
41  struct { u32 data[4];} * ed;
42  ELOG_TRACK(sample_track);
43  ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, e, sample_track);
44  ed->data[0] = data[0];
45  ed->data[1] = data[1];
46  ed->data[2] = data[2];
47  ed->data[3] = data[3];
48 }
49 
50 static inline void elog_enum_sample (u8 which)
51 {
52  ELOG_TYPE_DECLARE (e) =
53  {
54  .format = "my enum: %s",
55  .format_args = "t1",
56  .n_enum_strings = 2,
57  .enum_strings =
58  {
59  "string 1",
60  "string 2",
61  },
62  };
63  struct { u8 which;} * ed;
65  ed->which = which;
66 }
67 
68 static inline void elog_one_datum_sample (u32 data)
69 {
70  ELOG_TYPE_DECLARE (e) =
71  {
72  .format = "one datum: %d",
73  .format_args = "i4",
74  };
75 
76  elog (&vlib_global_main.elog_main, &e, data);
77 }
78 
79 static clib_error_t *
81  unformat_input_t * input,
82  vlib_cli_command_t * cmd)
83 {
84  int i;
85  u32 samples[4];
86 
87  for (i = 0; i < 10; i++)
88  {
89  samples[0] = i;
90  samples[1] = i+1;
91  samples[2] = i+2;
92  samples[3] = i+3;
93 
94  elog_four_int_sample (samples);
96  elog_enum_sample (0);
97  elog_enum_sample (1);
99  }
100 
101  return 0;
102 }
103 
104 VLIB_CLI_COMMAND (test_elog_command, static) = {
105  .path = "test elog sample",
106  .short_help = "test elog sample",
107  .function = test_elog_command_fn,
108 };
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:267
static clib_error_t * test_elog_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: elog_samples.c:80
static void elog_four_int_sample(u32 *data)
Definition: elog_samples.c:19
always_inline void elog(elog_main_t *em, elog_event_type_t *type, u32 data)
Definition: elog.h:278
#define ELOG_TRACK(f)
Definition: elog.h:373
#define ELOG_DATA(em, f)
Definition: elog.h:386
static void elog_four_int_track_sample(u32 *data)
Definition: elog_samples.c:34
elog_main_t elog_main
Definition: main.h:141
vlib_main_t vlib_global_main
Definition: main.c:1505
#define ELOG_TYPE_DECLARE(f)
Definition: elog.h:344
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:150
unsigned int u32
Definition: types.h:88
#define ELOG_TRACK_DATA(em, f, track)
Definition: elog.h:380
unsigned char u8
Definition: types.h:56
struct _unformat_input_t unformat_input_t
static void elog_enum_sample(u8 which)
Definition: elog_samples.c:50
static void elog_one_datum_sample(u32 data)
Definition: elog_samples.c:68