"Fossies" - the Fresh Open Source Software Archive

Member "sysdig-0.26.1/userspace/sysdig/fields_info.cpp" (24 May 2019, 6457 Bytes) of package /linux/misc/sysdig-0.26.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "fields_info.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 0.24.2_vs_0.25.

    1 /*
    2 Copyright (C) 2013-2018 Draios Inc dba Sysdig.
    3 
    4 This file is part of sysdig.
    5 
    6 Licensed under the Apache License, Version 2.0 (the "License");
    7 you may not use this file except in compliance with the License.
    8 You may obtain a copy of the License at
    9 
   10     http://www.apache.org/licenses/LICENSE-2.0
   11 
   12 Unless required by applicable law or agreed to in writing, software
   13 distributed under the License is distributed on an "AS IS" BASIS,
   14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15 See the License for the specific language governing permissions and
   16 limitations under the License.
   17 
   18 */
   19 
   20 //
   21 // Various helper functions to render stuff on the screen
   22 //
   23 #define __STDC_FORMAT_MACROS
   24 #include <stdio.h>
   25 #include <iostream>
   26 #include <assert.h>
   27 #include <algorithm> 
   28 
   29 #include <sinsp.h>
   30 #include "chisel.h"
   31 #include "sysdig.h"
   32 
   33 // Must match the value in the zsh tab completion
   34 #define DESCRIPTION_TEXT_START 16
   35 
   36 
   37 #define CONSOLE_LINE_LEN 79
   38 #define PRINTF_WRAP_CPROC(x)  #x
   39 #define PRINTF_WRAP(x) PRINTF_WRAP_CPROC(x)
   40 
   41 void list_fields(bool verbose, bool markdown, bool names_only)
   42 {
   43     uint32_t j, l, m;
   44     int32_t k;
   45 
   46     if(markdown && !names_only)
   47     {
   48         printf("# Sysdig Filter Fields List\n\n");
   49     }
   50 
   51     vector<const filter_check_info*> fc_plugins;
   52     sinsp::get_filtercheck_fields_info(&fc_plugins);
   53 
   54     for(j = 0; j < fc_plugins.size(); j++)
   55     {
   56         const filter_check_info* fci = fc_plugins[j];
   57 
   58         if(fci->m_flags & filter_check_info::FL_HIDDEN)
   59         {
   60             continue;
   61         }
   62 
   63         if(!names_only)
   64         {
   65             if(markdown)
   66             {
   67                 printf("## Filter Class: %s\n\n", fci->m_name.c_str());
   68             }
   69             else
   70             {
   71                 printf("\n----------------------\n");
   72                 printf("Field Class: %s\n\n", fci->m_name.c_str());
   73             }
   74         }
   75 
   76         for(k = 0; k < fci->m_nfields; k++)
   77         {
   78             const filtercheck_field_info* fld = &fci->m_fields[k];
   79 
   80             if(fld->m_flags & EPF_TABLE_ONLY)
   81             {
   82                 continue;
   83             }
   84 
   85             if(names_only)
   86             {
   87                 printf("%s\n", fld->m_name);
   88             }
   89             else if(markdown)
   90             {
   91                 printf("**Name**: %s  \n", fld->m_name);
   92                 printf("**Description**: %s  \n", fld->m_description);
   93                 printf("**Type**: %s  \n\n", param_type_to_string(fld->m_type));
   94             }
   95             else
   96             {
   97                 printf("%s", fld->m_name);
   98                 uint32_t namelen = (uint32_t)strlen(fld->m_name);
   99 
  100                 if(namelen >= DESCRIPTION_TEXT_START)
  101                 {
  102                     printf("\n");
  103                     namelen = 0;
  104                 }
  105 
  106                 for(l = 0; l < DESCRIPTION_TEXT_START - namelen; l++)
  107                 {
  108                     printf(" ");
  109                 }
  110 
  111                 string desc(fld->m_description);
  112 
  113                 if(fld->m_flags & EPF_FILTER_ONLY)
  114                 {
  115                     desc = "(FILTER ONLY) " + desc;
  116                 }
  117 
  118                 if(verbose)
  119                 {
  120                     desc += string(" Type:") + param_type_to_string(fld->m_type) + ".";
  121                 }
  122 
  123                 size_t desclen = desc.size();
  124 
  125                 for(l = 0; l < desclen; l++)
  126                 {
  127                     if(l % (CONSOLE_LINE_LEN - DESCRIPTION_TEXT_START) == 0 && l != 0)
  128                     {
  129                         printf("\n");
  130 
  131                         for(m = 0; m < DESCRIPTION_TEXT_START; m++)
  132                         {
  133                             printf(" ");
  134                         }
  135                     }
  136 
  137                     printf("%c", desc[l]);
  138                 }
  139 
  140                 printf("\n");
  141             }
  142         }
  143     }
  144 }
  145 
  146 void list_events(sinsp* inspector)
  147 {
  148     uint32_t j, k;
  149     string tstr;
  150 
  151     sinsp_evttables* einfo = inspector->get_event_info_tables();
  152     const struct ppm_event_info* etable = einfo->m_event_info;
  153 
  154     for(j = 0; j < PPM_EVENT_MAX; j++)
  155     {
  156         const struct ppm_event_info ei = etable[j];
  157         char dir = (PPME_IS_ENTER(j))? '>' : '<';
  158 
  159         if((ei.flags & EF_UNUSED) || (ei.flags & EF_OLD_VERSION) || (ei.category & EC_INTERNAL))
  160         {
  161             continue;
  162         }
  163 
  164         printf("%c %s(", dir, ei.name);
  165 
  166         for(k = 0; k < ei.nparams; k++)
  167         {
  168             if(k != 0)
  169             {
  170                 printf(", ");
  171             }
  172 
  173             printf("%s %s", param_type_to_string(ei.params[k].type), 
  174                 ei.params[k].name);
  175         }
  176                 
  177         printf(")\n");
  178     }
  179 }
  180 
  181 #ifdef HAS_CHISELS
  182 struct summary_chisel_comparer
  183 {
  184     bool operator() (const chisel_desc& first, const chisel_desc& second) const 
  185     {
  186         return (first.m_category == second.m_category) 
  187         ? first.m_name < second.m_name 
  188         : first.m_category < second.m_category;
  189     }
  190 };
  191 
  192 void print_chisel_info(chisel_desc* cd)
  193 {
  194     // First we create a single list composed of
  195     // just this chisel and then run the short_description
  196     // over it in order to get those fields for free.
  197     std::vector<chisel_desc> chlist;
  198     chlist.push_back(cd[0]);
  199 
  200     list_chisels(&chlist, false);
  201 
  202     // Now we have to do the real work
  203     printf("\n");
  204 
  205     uint32_t l;
  206     string astr;
  207 
  208     string desc = cd->m_description;
  209     size_t desclen = desc.size();
  210 
  211     for(l = 0; l < desclen; l++)
  212     {
  213         if(l % CONSOLE_LINE_LEN == 0 && l != 0)
  214         {
  215             printf("\n");
  216         }
  217 
  218         printf("%c", desc[l]);
  219     }
  220 
  221     printf("\n");
  222 
  223     astr += "Args:\n";
  224 
  225     if(cd->m_args.size() != 0)
  226     {
  227 
  228         for(l = 0; l < cd->m_args.size(); l++)
  229         {
  230             astr += "[" + cd->m_args[l].m_type + "] " + cd->m_args[l].m_name + " - ";
  231             astr += cd->m_args[l].m_description + "\n";
  232         }
  233 
  234     }
  235     else
  236     {
  237         astr += "(None)";
  238     }
  239 
  240     size_t astrlen = astr.size();
  241     int linepos = 0;
  242 
  243     for(l = 0; l < astrlen; l++, linepos++)
  244     {
  245         if(astr[l] == '\n')
  246             linepos = -1;
  247         else if(linepos % (CONSOLE_LINE_LEN - DESCRIPTION_TEXT_START) == 0 && linepos != 0)
  248         {
  249             printf("\n%" PRINTF_WRAP(DESCRIPTION_TEXT_START) "s", "");
  250         }
  251 
  252         printf("%c", astr[l]);
  253     }
  254 
  255     // just for good measure
  256     printf("\n");
  257 }
  258 
  259 void list_chisels(vector<chisel_desc>* chlist, bool verbose)
  260 {
  261     uint32_t j, l;
  262 
  263     //
  264     // Sort the list by name
  265     //
  266     sort(chlist->begin(), chlist->end(), summary_chisel_comparer());
  267     string last_category;
  268 
  269     //
  270     // Print the list to the screen
  271     //
  272     for(j = 0; j < chlist->size(); j++)
  273     {
  274         chisel_desc* cd = &(chlist->at(j));
  275 
  276         if(cd->m_viewinfo.m_valid)
  277         {
  278             continue;
  279         }
  280 
  281         string category = cd->m_category;
  282 
  283         if(category != last_category) 
  284         {
  285             string fullcatstr = "Category: " + category;
  286 
  287             printf("\n%s\n", fullcatstr.c_str());
  288             for(l = 0; l < fullcatstr.size(); l++)
  289             {
  290                 putchar('-');
  291             }
  292 
  293             printf("\n");
  294             last_category = category;
  295         }
  296 
  297         printf("%s", cd->m_name.c_str());
  298         uint32_t namelen = (uint32_t)cd->m_name.size();
  299 
  300         if(namelen >= DESCRIPTION_TEXT_START)
  301         {
  302             printf("\n");
  303             namelen = 0;
  304         }
  305 
  306         for(l = 0; l < (DESCRIPTION_TEXT_START - namelen); l++)
  307         {
  308             printf(" ");
  309         }
  310 
  311         string desc = cd->m_shortdesc;
  312         size_t desclen = desc.size();
  313 
  314         for(l = 0; l < desclen; l++)
  315         {
  316             if(l % (CONSOLE_LINE_LEN - DESCRIPTION_TEXT_START) == 0 && l != 0)
  317             {
  318                 printf("\n%" PRINTF_WRAP(DESCRIPTION_TEXT_START) "s", "");
  319             }
  320 
  321             printf("%c", desc[l]);
  322         }
  323 
  324         printf("\n");
  325     }
  326 
  327     if(verbose)
  328     {
  329         printf("\nUse the -i flag to get detailed information about a specific chisel\n");
  330     }
  331 }
  332 #endif // HAS_CHISELS