LCOV - code coverage report
Current view: top level - vlib - node_format.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 58 80 72.5 %
Date: 2023-07-05 22:20:52 Functions: 5 8 62.5 %

          Line data    Source code
       1             : /*
       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:
       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             :  * node_format.c: node formatting
      17             :  *
      18             :  * Copyright (c) 2008 Eliot Dresselhaus
      19             :  *
      20             :  * Permission is hereby granted, free of charge, to any person obtaining
      21             :  * a copy of this software and associated documentation files (the
      22             :  * "Software"), to deal in the Software without restriction, including
      23             :  * without limitation the rights to use, copy, modify, merge, publish,
      24             :  * distribute, sublicense, and/or sell copies of the Software, and to
      25             :  * permit persons to whom the Software is furnished to do so, subject to
      26             :  * the following conditions:
      27             :  *
      28             :  * The above copyright notice and this permission notice shall be
      29             :  * included in all copies or substantial portions of the Software.
      30             :  *
      31             :  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
      32             :  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
      33             :  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
      34             :  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
      35             :  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
      36             :  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
      37             :  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      38             :  */
      39             : 
      40             : #include <vlib/vlib.h>
      41             : 
      42             : u8 *
      43         282 : format_vlib_node_graph (u8 * s, va_list * va)
      44             : {
      45         282 :   vlib_node_main_t *nm = va_arg (*va, vlib_node_main_t *);
      46         282 :   vlib_node_t *n = va_arg (*va, vlib_node_t *);
      47             :   int i, j;
      48             :   u32 indent;
      49             :   typedef struct
      50             :   {
      51             :     u32 next_node;
      52             :     u32 next_slot;
      53             :     u32 prev_node;
      54             :   } tmp_t;
      55         282 :   tmp_t *tmps = 0;
      56         282 :   tmp_t empty = {.next_node = ~0,.prev_node = ~0 };
      57             : 
      58         282 :   if (!n)
      59         141 :     return format (s, "%=26s%=26s%=26s", "Name", "Next", "Previous");
      60             : 
      61         141 :   s = format (s, "%-26v", n->name);
      62             : 
      63         141 :   indent = format_get_indent (s);
      64             : 
      65        2172 :   for (i = j = 0; i < vec_len (n->next_nodes); i++)
      66             :     {
      67        2031 :       if (n->next_nodes[i] == VLIB_INVALID_NODE_INDEX)
      68           0 :         continue;
      69        4062 :       vec_validate_init_empty (tmps, j, empty);
      70        2031 :       tmps[j].next_node = n->next_nodes[i];
      71        2031 :       tmps[j].next_slot = i;
      72        2031 :       j++;
      73             :     }
      74             : 
      75         141 :   j = 0;
      76             :   /* *INDENT-OFF* */
      77        1168 :   clib_bitmap_foreach (i, n->prev_node_bitmap)  {
      78        1038 :         vec_validate_init_empty (tmps, j, empty);
      79        1027 :         tmps[j].prev_node = i;
      80        1027 :         j++;
      81             :       }
      82             :   /* *INDENT-ON* */
      83             : 
      84        2183 :   for (i = 0; i < vec_len (tmps); i++)
      85             :     {
      86        2042 :       if (i > 0)
      87        1901 :         s = format (s, "\n%U", format_white_space, indent);
      88             : 
      89        2042 :       if (tmps[i].next_node != ~0)
      90             :         {
      91             :           vlib_node_t *x;
      92        2031 :           u8 *t = 0;
      93             : 
      94        2031 :           x = vec_elt (nm->nodes, tmps[i].next_node);
      95        2031 :           t = format (t, "%v [%d]", x->name, tmps[i].next_slot);
      96        2031 :           s = format (s, "%=26v", t);
      97        2031 :           vec_free (t);
      98             :         }
      99             :       else
     100          11 :         s = format (s, "%26s", "");
     101             : 
     102        2042 :       if (tmps[i].prev_node != ~0)
     103             :         {
     104             :           vlib_node_t *x;
     105        1027 :           x = vec_elt (nm->nodes, tmps[i].prev_node);
     106        1027 :           s = format (s, "%=26v", x->name);
     107             :         }
     108             :     }
     109             : 
     110         141 :   vec_free (tmps);
     111             : 
     112         141 :   return s;
     113             : }
     114             : 
     115             : u8 *
     116           0 : format_vlib_node_and_next (u8 * s, va_list * va)
     117             : {
     118           0 :   vlib_main_t *vm = va_arg (*va, vlib_main_t *);
     119           0 :   vlib_node_t *n = va_arg (*va, vlib_node_t *);
     120           0 :   u32 next_index = va_arg (*va, u32);
     121             :   vlib_node_t *n_next;
     122             :   u32 *ni;
     123             : 
     124           0 :   ni = vec_elt_at_index (n->next_nodes, next_index);
     125           0 :   n_next = vlib_get_node (vm, ni[0]);
     126           0 :   return format (s, "%v -> %v", n->name, n_next->name);
     127             : }
     128             : 
     129             : u8 *
     130       26289 : format_vlib_node_name (u8 * s, va_list * va)
     131             : {
     132       26289 :   vlib_main_t *vm = va_arg (*va, vlib_main_t *);
     133       26289 :   u32 node_index = va_arg (*va, u32);
     134       26289 :   vlib_node_t *n = vlib_get_node (vm, node_index);
     135             : 
     136       26289 :   return format (s, "%v", n->name);
     137             : }
     138             : 
     139             : u8 *
     140           0 : format_vlib_next_node_name (u8 * s, va_list * va)
     141             : {
     142           0 :   vlib_main_t *vm = va_arg (*va, vlib_main_t *);
     143           0 :   u32 node_index = va_arg (*va, u32);
     144           0 :   u32 next_index = va_arg (*va, u32);
     145           0 :   vlib_node_t *next = vlib_get_next_node (vm, node_index, next_index);
     146           0 :   return format (s, "%v", next->name);
     147             : }
     148             : 
     149             : /* Parse node name -> node index. */
     150             : uword
     151       17024 : unformat_vlib_node (unformat_input_t * input, va_list * args)
     152             : {
     153       17024 :   vlib_main_t *vm = va_arg (*args, vlib_main_t *);
     154       17024 :   u32 *result = va_arg (*args, u32 *);
     155             : 
     156       17024 :   return unformat_user (input, unformat_hash_vec_string,
     157             :                         vm->node_main.node_by_name, result);
     158             : }
     159             : 
     160             : u8 *
     161       23225 : format_vlib_time (u8 * s, va_list * va)
     162             : {
     163       23225 :   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
     164       23225 :   f64 time = va_arg (*va, f64);
     165       23225 :   return format (s, "%12.4f", time);
     166             : }
     167             : 
     168             : u8 *
     169           0 : format_vlib_cpu_time (u8 * s, va_list * va)
     170             : {
     171           0 :   vlib_main_t *vm = va_arg (*va, vlib_main_t *);
     172           0 :   u64 cpu_time = va_arg (*va, u64);
     173             :   f64 dt;
     174             : 
     175           0 :   dt =
     176           0 :     (cpu_time -
     177           0 :      vm->clib_time.init_cpu_time) * vm->clib_time.seconds_per_clock;
     178           0 :   return format (s, "%U", format_vlib_time, vm, dt);
     179             : }
     180             : 
     181             : uword
     182           6 : unformat_vlib_node_variant (unformat_input_t *input, va_list *args)
     183             : {
     184           6 :   vlib_main_t *vm = vlib_get_main ();
     185           6 :   u32 *march_variant = va_arg (*args, u32 *);
     186             :   uword *p;
     187           6 :   u8 *str = 0;
     188             : 
     189           6 :   if (unformat (input, "%s", &str) == 0)
     190           0 :     return 0;
     191             : 
     192           6 :   p = hash_get (vm->node_main.node_fn_march_variant_by_suffix, str);
     193             : 
     194           6 :   vec_free (str);
     195             : 
     196           6 :   if (p)
     197           6 :     *march_variant = p[0];
     198             : 
     199           6 :   return p ? 1 : 0;
     200             : }
     201             : 
     202             : /*
     203             :  * fd.io coding-style-patch-verification: ON
     204             :  *
     205             :  * Local Variables:
     206             :  * eval: (c-set-style "gnu")
     207             :  * End:
     208             :  */

Generated by: LCOV version 1.14