Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 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 | #include <vlib/vlib.h> |
| 16 | |
| 17 | #include <vppinfra/serialize.h> |
| 18 | |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 19 | /* serialized representation of state strings */ |
| 20 | |
| 21 | #define foreach_state_string_code \ |
| 22 | _(STATE_DONE, "done") \ |
| 23 | _(STATE_DISABLED, "disabled") \ |
| 24 | _(STATE_TIME_WAIT, "time wait") \ |
| 25 | _(STATE_EVENT_WAIT, "event wait") \ |
| 26 | _(STATE_ANY_WAIT, "any wait") \ |
| 27 | _(STATE_POLLING, "polling") \ |
| 28 | _(STATE_INTERRUPT_WAIT, "interrupt wait") \ |
| 29 | _(STATE_INTERNAL, "internal") |
| 30 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 31 | typedef enum |
| 32 | { |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 33 | #define _(a,b) a, |
| 34 | foreach_state_string_code |
| 35 | #undef _ |
| 36 | } state_string_enum_t; |
| 37 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 38 | static char *state_strings[] = { |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 39 | #define _(a,b) b, |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 40 | foreach_state_string_code |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 41 | #undef _ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 42 | }; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 43 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 44 | /* |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 45 | * Serialize a vlib_node_main_t. Appends the result to vector. |
| 46 | * Pass 0 to create a new vector, use vec_reset_length(vector) |
| 47 | * to recycle a vector / avoid memory allocation, etc. |
| 48 | * Switch heaps before/after to serialize into API client shared memory. |
| 49 | */ |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 50 | u8 * |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 51 | vlib_node_serialize (vlib_main_t * vm, vlib_node_t *** node_dups, u8 * vector, |
| 52 | int include_nexts, int include_stats) |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 53 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 54 | serialize_main_t _sm, *sm = &_sm; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 55 | vlib_node_t *n; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 56 | vlib_node_t **nodes; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 57 | u8 *namep; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 58 | u32 name_bytes; |
| 59 | uword i, j, k; |
Dave Barach | ec595ef | 2019-01-24 10:34:24 -0500 | [diff] [blame] | 60 | u64 l, v, c, d; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 61 | state_string_enum_t state_code; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 62 | |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 63 | serialize_open_vector (sm, vector); |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 64 | serialize_likely_small_unsigned_integer (sm, vec_len (node_dups)); |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 65 | |
Florin Coras | e86a8ed | 2018-01-05 03:20:25 -0800 | [diff] [blame] | 66 | for (j = 0; j < vec_len (node_dups); j++) |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 67 | { |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 68 | nodes = node_dups[j]; |
| 69 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 70 | serialize_likely_small_unsigned_integer (sm, vec_len (nodes)); |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 71 | |
| 72 | for (i = 0; i < vec_len (nodes); i++) |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 73 | { |
| 74 | n = nodes[i]; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 75 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 76 | l = n->stats_total.clocks - n->stats_last_clear.clocks; |
| 77 | v = n->stats_total.vectors - n->stats_last_clear.vectors; |
| 78 | c = n->stats_total.calls - n->stats_last_clear.calls; |
| 79 | d = n->stats_total.suspends - n->stats_last_clear.suspends; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 80 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 81 | state_code = STATE_INTERNAL; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 82 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 83 | if (n->type == VLIB_NODE_TYPE_PROCESS) |
| 84 | { |
| 85 | vlib_process_t *p = vlib_get_process_from_node (vm, n); |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 86 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 87 | switch (p->flags |
| 88 | & (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK |
| 89 | | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT)) |
| 90 | { |
| 91 | default: |
| 92 | if (!(p->flags & VLIB_PROCESS_IS_RUNNING)) |
| 93 | state_code = STATE_DONE; |
| 94 | break; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 95 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 96 | case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK: |
| 97 | state_code = STATE_TIME_WAIT; |
| 98 | break; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 99 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 100 | case VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT: |
| 101 | state_code = STATE_EVENT_WAIT; |
| 102 | break; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 103 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 104 | case (VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT | VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_CLOCK): |
| 105 | state_code = |
| 106 | STATE_ANY_WAIT; |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | else if (n->type != VLIB_NODE_TYPE_INTERNAL) |
| 111 | { |
| 112 | state_code = STATE_POLLING; |
| 113 | if (n->state == VLIB_NODE_STATE_DISABLED) |
| 114 | state_code = STATE_DISABLED; |
| 115 | else if (n->state == VLIB_NODE_STATE_INTERRUPT) |
| 116 | state_code = STATE_INTERRUPT_WAIT; |
| 117 | } |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 118 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 119 | /* See unserialize_cstring */ |
| 120 | name_bytes = vec_len (n->name); |
| 121 | serialize_likely_small_unsigned_integer (sm, name_bytes); |
| 122 | namep = serialize_get (sm, name_bytes); |
| 123 | memcpy (namep, n->name, name_bytes); |
| 124 | |
| 125 | serialize_likely_small_unsigned_integer (sm, (u64) state_code); |
| 126 | serialize_likely_small_unsigned_integer (sm, n->type); |
Dave Barach | 1ddbc01 | 2018-06-13 09:26:05 -0400 | [diff] [blame] | 127 | serialize_likely_small_unsigned_integer (sm, n->flags); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 128 | |
| 129 | if (include_nexts) |
| 130 | { |
| 131 | serialize_likely_small_unsigned_integer |
| 132 | (sm, vec_len (n->next_nodes)); |
| 133 | for (k = 0; k < vec_len (n->next_nodes); k++) |
| 134 | serialize_likely_small_unsigned_integer (sm, |
| 135 | n->next_nodes[k]); |
| 136 | } |
| 137 | else |
| 138 | serialize_likely_small_unsigned_integer (sm, 0); |
| 139 | |
| 140 | if (include_stats) |
| 141 | { |
| 142 | /* stats present */ |
| 143 | serialize_likely_small_unsigned_integer (sm, 1); |
| 144 | /* total clocks */ |
| 145 | serialize_integer (sm, l, 8); |
| 146 | /* Total calls */ |
| 147 | serialize_integer (sm, c, 8); |
| 148 | /* Total vectors */ |
| 149 | serialize_integer (sm, v, 8); |
| 150 | /* Total suspends */ |
| 151 | serialize_integer (sm, d, 8); |
| 152 | } |
| 153 | else /* no stats */ |
| 154 | serialize_likely_small_unsigned_integer (sm, 0); |
| 155 | } |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 156 | } |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 157 | return (serialize_close_vector (sm)); |
| 158 | } |
| 159 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 160 | vlib_node_t *** |
| 161 | vlib_node_unserialize (u8 * vector) |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 162 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 163 | serialize_main_t _sm, *sm = &_sm; |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 164 | u32 nnodes, nnexts; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 165 | u32 nstat_vms; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 166 | vlib_node_t *node; |
| 167 | vlib_node_t **nodes; |
| 168 | vlib_node_t ***nodes_by_thread = 0; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 169 | int i, j, k; |
Dave Barach | ec595ef | 2019-01-24 10:34:24 -0500 | [diff] [blame] | 170 | u64 l, v, c, d; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 171 | state_string_enum_t state_code; |
| 172 | int stats_present; |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 173 | |
| 174 | serialize_open_vector (sm, vector); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 175 | |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 176 | nstat_vms = unserialize_likely_small_unsigned_integer (sm); |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 177 | |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 178 | vec_validate (nodes_by_thread, nstat_vms - 1); |
| 179 | _vec_len (nodes_by_thread) = 0; |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 180 | |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 181 | for (i = 0; i < nstat_vms; i++) |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 182 | { |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 183 | nnodes = unserialize_likely_small_unsigned_integer (sm); |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 184 | |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 185 | nodes = 0; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 186 | vec_validate (nodes, nnodes - 1); |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 187 | vec_add1 (nodes_by_thread, nodes); |
| 188 | |
| 189 | for (j = 0; j < nnodes; j++) |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 190 | { |
| 191 | node = 0; |
| 192 | vec_validate (node, 0); |
| 193 | nodes[j] = node; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 194 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 195 | unserialize_cstring (sm, (char **) &(node->name)); |
| 196 | state_code = unserialize_likely_small_unsigned_integer (sm); |
| 197 | node->state_string = (u8 *) state_strings[state_code]; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 198 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 199 | node->type = unserialize_likely_small_unsigned_integer (sm); |
Dave Barach | 1ddbc01 | 2018-06-13 09:26:05 -0400 | [diff] [blame] | 200 | node->flags = unserialize_likely_small_unsigned_integer (sm); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 201 | nnexts = unserialize_likely_small_unsigned_integer (sm); |
| 202 | if (nnexts > 0) |
| 203 | vec_validate (node->next_nodes, nnexts - 1); |
| 204 | for (k = 0; k < nnexts; k++) |
| 205 | node->next_nodes[k] = |
| 206 | unserialize_likely_small_unsigned_integer (sm); |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 207 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 208 | stats_present = unserialize_likely_small_unsigned_integer (sm); |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 209 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 210 | if (stats_present) |
| 211 | { |
| 212 | /* total clocks */ |
| 213 | unserialize_integer (sm, &l, 8); |
| 214 | node->stats_total.clocks = l; |
| 215 | node->stats_last_clear.clocks = 0; |
| 216 | |
| 217 | /* Total calls */ |
| 218 | unserialize_integer (sm, &c, 8); |
| 219 | node->stats_total.calls = c; |
| 220 | |
| 221 | /* Total vectors */ |
| 222 | unserialize_integer (sm, &v, 8); |
| 223 | node->stats_total.vectors = v; |
| 224 | |
| 225 | /* Total suspends */ |
| 226 | unserialize_integer (sm, &d, 8); |
| 227 | node->stats_total.suspends = d; |
| 228 | } |
| 229 | } |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 230 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 231 | return nodes_by_thread; |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 232 | } |
| 233 | |
Dave Barach | 80f54e2 | 2017-03-08 19:08:56 -0500 | [diff] [blame] | 234 | #if TEST_CODE |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 235 | |
| 236 | static clib_error_t * |
| 237 | test_node_serialize_command_fn (vlib_main_t * vm, |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 238 | unformat_input_t * input, |
| 239 | vlib_cli_command_t * cmd) |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 240 | { |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 241 | vlib_node_main_t *nm = &vm->node_main; |
| 242 | u8 *vector = 0; |
| 243 | vlib_node_t ***nodes_by_thread; |
| 244 | vlib_node_t **nodes; |
| 245 | vlib_node_t *node; |
| 246 | vlib_node_t *next_node; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 247 | int i, j, k; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 248 | u32 max_threads = (u32) ~ 0; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 249 | int include_nexts = 0; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 250 | int include_stats = 0; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 251 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 252 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 253 | { |
| 254 | if (unformat (input, "max-threads %d", &max_threads)) |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 255 | ; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 256 | else if (unformat (input, "stats")) |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 257 | include_stats = 1; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 258 | else if (unformat (input, "nexts")) |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 259 | include_nexts = 1; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 260 | else |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 261 | break; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 262 | } |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 263 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 264 | /* |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 265 | * Keep the number of memcpy ops to a minimum (e.g. 1). |
| 266 | * The current size of the serialized vector is |
| 267 | * slightly under 4K. |
| 268 | */ |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 269 | vec_validate (vector, 16383); |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 270 | vec_reset_length (vector); |
| 271 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 272 | vector = vlib_node_serialize (nm, vector, max_threads, |
| 273 | include_nexts, include_stats); |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 274 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 275 | vlib_cli_output (vm, "result vector %d bytes", vec_len (vector)); |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 276 | |
| 277 | nodes_by_thread = vlib_node_unserialize (vector); |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 278 | |
| 279 | vec_free (vector); |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 280 | |
| 281 | for (i = 0; i < vec_len (nodes_by_thread); i++) |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 282 | { |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 283 | nodes = nodes_by_thread[i]; |
| 284 | |
| 285 | vlib_cli_output (vm, "thread %d", i); |
| 286 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 287 | for (j = 0; j < vec_len (nodes); j++) |
| 288 | { |
| 289 | node = nodes[j]; |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 290 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 291 | vlib_cli_output (vm, "[%d] %s state %s", j, node->name, |
| 292 | node->state_string); |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 293 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 294 | vlib_cli_output |
| 295 | (vm, " clocks %lld calls %lld suspends" |
| 296 | " %lld vectors %lld", |
| 297 | node->stats_total.clocks, |
| 298 | node->stats_total.calls, |
| 299 | node->stats_total.suspends, node->stats_total.vectors); |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 300 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 301 | for (k = 0; k < vec_len (node->next_nodes); k++) |
| 302 | { |
| 303 | if (node->next_nodes[k] != ~0) |
Ed Warnicke | 853e720 | 2016-08-12 11:42:26 -0700 | [diff] [blame] | 304 | { |
| 305 | next_node = nodes[node->next_nodes[k]]; |
| 306 | vlib_cli_output (vm, " [%d] %s", k, next_node->name); |
| 307 | } |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | } |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 311 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 312 | for (j = 0; j < vec_len (nodes_by_thread); j++) |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 313 | { |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 314 | nodes = nodes_by_thread[j]; |
| 315 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 316 | for (i = 0; i < vec_len (nodes); i++) |
| 317 | { |
| 318 | vec_free (nodes[i]->name); |
| 319 | vec_free (nodes[i]->next_nodes); |
| 320 | vec_free (nodes[i]); |
| 321 | } |
| 322 | vec_free (nodes); |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 323 | } |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 324 | vec_free (nodes_by_thread); |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 329 | /* *INDENT-OFF* */ |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 330 | VLIB_CLI_COMMAND (test_node_serialize_node, static) = { |
| 331 | .path = "test node serialize", |
Dave Barach | 6931f59 | 2016-05-13 12:55:01 -0400 | [diff] [blame] | 332 | .short_help = "test node serialize [max-threads NN] nexts stats", |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 333 | .function = test_node_serialize_command_fn, |
| 334 | }; |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 335 | /* *INDENT-ON* */ |
Dave Barach | b44e9bc | 2016-02-19 09:06:23 -0500 | [diff] [blame] | 336 | #endif |
Dave Barach | 371e4e1 | 2016-07-08 09:38:52 -0400 | [diff] [blame] | 337 | |
| 338 | /* |
| 339 | * fd.io coding-style-patch-verification: ON |
| 340 | * |
| 341 | * Local Variables: |
| 342 | * eval: (c-set-style "gnu") |
| 343 | * End: |
| 344 | */ |