Skip to content

Commit

Permalink
refactor: Add some const-correctness
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Aponte <[email protected]>
  • Loading branch information
federico-sysdig committed Dec 22, 2023
1 parent e9333d9 commit 99a8816
Show file tree
Hide file tree
Showing 38 changed files with 344 additions and 363 deletions.
72 changes: 36 additions & 36 deletions userspace/chisel/chisel_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ typedef struct table_row_cmp
if(src.m_values[m_colid].m_cnt > 1 ||
dst.m_values[m_colid].m_cnt > 1)
{
return flt_compare_avg(op, m_type,
src.m_values[m_colid].m_val,
dst.m_values[m_colid].m_val,
src.m_values[m_colid].m_len,
return flt_compare_avg(op, m_type,
src.m_values[m_colid].m_val,
dst.m_values[m_colid].m_val,
src.m_values[m_colid].m_len,
dst.m_values[m_colid].m_len,
src.m_values[m_colid].m_cnt,
src.m_values[m_colid].m_cnt,
dst.m_values[m_colid].m_cnt);
}
else
{
return flt_compare(op, m_type,
src.m_values[m_colid].m_val,
dst.m_values[m_colid].m_val,
src.m_values[m_colid].m_len,
return flt_compare(op, m_type,
src.m_values[m_colid].m_val,
dst.m_values[m_colid].m_val,
src.m_values[m_colid].m_len,
dst.m_values[m_colid].m_len);
}
}
Expand All @@ -74,7 +74,7 @@ typedef struct table_row_cmp
bool m_ascending;
}table_row_cmp;

chisel_table::chisel_table(sinsp* inspector, tabletype type, uint64_t refresh_interval_ns,
chisel_table::chisel_table(sinsp* inspector, tabletype type, uint64_t refresh_interval_ns,
chisel_table::output_type output_type, uint32_t json_first_row, uint32_t json_last_row)
{
m_inspector = inspector;
Expand Down Expand Up @@ -133,11 +133,11 @@ chisel_table::~chisel_table()
{
delete m_filter;
}

delete m_printer;
}

void chisel_table::configure(vector<chisel_view_column_info>* entries, const string& filter,
void chisel_table::configure(vector<chisel_view_column_info>* entries, const string& filter,
bool use_defaults, uint32_t view_depth)
{
m_use_defaults = use_defaults;
Expand Down Expand Up @@ -167,7 +167,7 @@ void chisel_table::configure(vector<chisel_view_column_info>* entries, const str

for(auto vit : *entries)
{
sinsp_filter_check* chk = s_filterlist.new_filter_check_from_fldname(vit.get_field(m_view_depth),
sinsp_filter_check* chk = s_filterlist.new_filter_check_from_fldname(vit.get_field(m_view_depth),
m_inspector,
false);

Expand Down Expand Up @@ -209,7 +209,7 @@ void chisel_table::configure(vector<chisel_view_column_info>* entries, const str
}
else
{
sinsp_filter_check* chk = s_filterlist.new_filter_check_from_fldname("util.cnt",
sinsp_filter_check* chk = s_filterlist.new_filter_check_from_fldname("util.cnt",
m_inspector,
false);

Expand Down Expand Up @@ -252,7 +252,7 @@ void chisel_table::configure(vector<chisel_view_column_info>* entries, const str
m_vals_array_sz = m_premerge_vals_array_sz;

//////////////////////////////////////////////////////////////////////////////////////
// If a merge has been specified, configure it
// If a merge has been specified, configure it
//////////////////////////////////////////////////////////////////////////////////////
uint32_t n_gby_keys = 0;

Expand Down Expand Up @@ -348,7 +348,7 @@ void chisel_table::add_row(bool merging)
{
uint32_t j;

chisel_table_field key(m_fld_pointers[0].m_val,
chisel_table_field key(m_fld_pointers[0].m_val,
m_fld_pointers[0].m_len,
m_fld_pointers[0].m_cnt);

Expand Down Expand Up @@ -549,13 +549,13 @@ void chisel_table::process_proctable(sinsp_evt* evt)
}

void chisel_table::flush(sinsp_evt* evt)
{
{
if(!m_paused)
{
if(m_next_flush_time_ns != 0)
{
//
// Time to emit the sample!
// Time to emit the sample!
// Add the proctable as a sample at the end of the second
//
process_proctable(evt);
Expand All @@ -581,7 +581,7 @@ void chisel_table::flush(sinsp_evt* evt)
if(m_type == chisel_table::TT_TABLE)
{
//
// Switch the data storage so that the current one is still usable by the
// Switch the data storage so that the current one is still usable by the
// consumers of the table.
//
switch_buffers();
Expand Down Expand Up @@ -619,13 +619,13 @@ void chisel_table::print_raw(vector<chisel_sample_row>* sample_data, uint64_t ti
check_wrapper* extractor = m_extractors->at(j + 1);
uint64_t td = 0;

if(extractor->m_aggregation == A_TIME_AVG ||
if(extractor->m_aggregation == A_TIME_AVG ||
extractor->m_merge_aggregation == A_TIME_AVG)
{
td = time_delta;
}

m_printer->set_val(m_types->at(j + 1),
m_printer->set_val(m_types->at(j + 1),
EPF_NONE,
it->m_values[j].m_val,
it->m_values[j].m_len,
Expand Down Expand Up @@ -673,19 +673,19 @@ void chisel_table::print_json(vector<chisel_sample_row>* sample_data, uint64_t t
Json::Value root;
Json::Value jd;
auto row = sample_data->at(k);

for(uint32_t j = 0; j < m_n_fields - 1; j++)
{
check_wrapper* extractor = m_extractors->at(j + 1);
uint64_t td = 0;

if(extractor->m_aggregation == A_TIME_AVG ||
if(extractor->m_aggregation == A_TIME_AVG ||
extractor->m_merge_aggregation == A_TIME_AVG)
{
td = time_delta;
}

m_printer->set_val(m_types->at(j + 1),
m_printer->set_val(m_types->at(j + 1),
EPF_NONE,
row.m_values[j].m_val,
row.m_values[j].m_len,
Expand Down Expand Up @@ -749,13 +749,13 @@ void chisel_table::filter_sample()
type == PT_IPV6ADDR ||
type == PT_UID || type == PT_GID)
{
m_printer->set_val(type,
m_printer->set_val(type,
EPF_NONE,
it.m_values[j].m_val,
it.m_values[j].m_val,
it.m_values[j].m_len,
it.m_values[j].m_cnt,
legend->at(j + 1).m_print_format);

string strval = m_printer->tostring_nice(NULL, 0, 0);

if(strval.find(m_freetext_filter) != string::npos)
Expand Down Expand Up @@ -976,7 +976,7 @@ void chisel_table::set_sorting_col(uint32_t col)
m_sorting_col = col - 1;
}

uint32_t chisel_table::get_sorting_col()
uint32_t chisel_table::get_sorting_col() const
{
return (uint32_t)m_sorting_col + 1;
}
Expand All @@ -990,7 +990,7 @@ void chisel_table::create_sample()
chisel_sample_row row;

//
// If merging is on, perform the merge and switch to the merged table
// If merging is on, perform the merge and switch to the merged table
//
if(m_do_merging)
{
Expand Down Expand Up @@ -1058,7 +1058,7 @@ void chisel_table::add_fields_sum(ppm_param_type type, chisel_table_field *dst,
{
uint8_t* operand1 = dst->m_val;
uint8_t* operand2 = src->m_val;

switch(type)
{
case PT_INT8:
Expand Down Expand Up @@ -1102,7 +1102,7 @@ void chisel_table::add_fields_sum_of_avg(ppm_param_type type, chisel_table_field
uint8_t* operand2 = src->m_val;
uint32_t cnt1 = dst->m_cnt;
uint32_t cnt2 = src->m_cnt;

switch(type)
{
case PT_INT8:
Expand Down Expand Up @@ -1374,10 +1374,10 @@ void chisel_table::add_fields(uint32_t dst_id, chisel_table_field* src, uint32_t
return;
case A_AVG:
dst->m_cnt += src->m_cnt;
add_fields_sum(type, dst, src);
add_fields_sum(type, dst, src);
return;
case A_MAX:
add_fields_max(type, dst, src);
add_fields_max(type, dst, src);
return;
case A_MIN:
if(src->m_cnt != 0)
Expand All @@ -1399,7 +1399,7 @@ void chisel_table::add_fields(uint32_t dst_id, chisel_table_field* src, uint32_t
}
}

uint32_t chisel_table::get_field_len(uint32_t id)
uint32_t chisel_table::get_field_len(uint32_t id) const
{
ppm_param_type type;
chisel_table_field *fld;
Expand Down Expand Up @@ -1560,7 +1560,7 @@ pair<filtercheck_field_info*, string> chisel_table::get_row_key_name_and_val(uin

m_printer->set_val(types->at(0),
EPF_NONE,
m_sample_data->at(rownum).m_key.m_val,
m_sample_data->at(rownum).m_key.m_val,
m_sample_data->at(rownum).m_key.m_len,
m_sample_data->at(rownum).m_key.m_cnt,
legend->at(0).m_print_format);
Expand All @@ -1581,7 +1581,7 @@ chisel_table_field* chisel_table::get_row_key(uint32_t rownum)
return &m_sample_data->at(rownum).m_key;
}

int32_t chisel_table::get_row_from_key(chisel_table_field* key)
int32_t chisel_table::get_row_from_key(chisel_table_field* key) const
{
uint32_t j;

Expand Down
26 changes: 13 additions & 13 deletions userspace/chisel/chisel_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class chisel_table_field
uint32_t m_cnt; // For averages, this stores the entry count
uint8_t* m_val;

friend class curses_table;
friend class curses_table;
};

#define STF_STORAGE_BUFSIZE 512
Expand Down Expand Up @@ -138,7 +138,7 @@ struct chisel_table_field_hasher
h = h * 101 + (unsigned) *s++;
}

return h;
return h;
}
};

Expand Down Expand Up @@ -222,15 +222,15 @@ class chisel_sample_row

class chisel_table
{
public:
public:
enum tabletype
{
TT_NONE = 0,
TT_TABLE,
TT_LIST,
};

enum output_type
enum output_type
{
OT_CURSES,
OT_RAW,
Expand All @@ -253,13 +253,13 @@ class chisel_table
{
delete m_check;
}

sinsp_filter_check* m_check;
chisel_field_aggregation m_aggregation;
chisel_field_aggregation m_merge_aggregation;
};

chisel_table(sinsp* inspector, tabletype type,
chisel_table(sinsp* inspector, tabletype type,
uint64_t refresh_interval_ns, chisel_table::output_type output_type,
uint32_t json_first_row, uint32_t json_last_row);
~chisel_table();
Expand All @@ -285,16 +285,16 @@ class chisel_table
}
}
void set_sorting_col(uint32_t col);
uint32_t get_sorting_col();
uint32_t get_sorting_col() const;
std::pair<filtercheck_field_info*, std::string> get_row_key_name_and_val(uint32_t rownum, bool force);
chisel_table_field* get_row_key(uint32_t rownum);
int32_t get_row_from_key(chisel_table_field* key);
int32_t get_row_from_key(chisel_table_field* key) const;
void set_paused(bool paused);
void set_freetext_filter(std::string filter)
{
m_freetext_filter = filter;
}
tabletype get_type()
tabletype get_type() const
{
return m_type;
}
Expand All @@ -303,11 +303,11 @@ class chisel_table
m_refresh_interval_ns = newinterval_ns;
}
void clear();
bool is_merging()
bool is_merging() const
{
return m_do_merging;
}
bool is_sorting_ascending()
bool is_sorting_ascending() const
{
return m_is_sorting_ascending;
}
Expand All @@ -330,7 +330,7 @@ class chisel_table
inline void add_fields_min(ppm_param_type type, chisel_table_field* dst, chisel_table_field* src);
inline void add_fields(uint32_t dst_id, chisel_table_field* src, uint32_t aggr);
void process_proctable(sinsp_evt* evt);
inline uint32_t get_field_len(uint32_t id);
inline uint32_t get_field_len(uint32_t id) const;
inline uint8_t* get_default_val(filtercheck_field_info* fld);
void create_sample();
void switch_buffers();
Expand Down Expand Up @@ -385,6 +385,6 @@ class chisel_table
uint32_t m_json_first_row;
uint32_t m_json_last_row;

friend class curses_table;
friend class curses_table;
friend class sinsp_cursesui;
};
2 changes: 1 addition & 1 deletion userspace/chisel/chisel_viewinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ chisel_view_column_info* chisel_view_info::get_key()
return NULL;
}

string chisel_view_info::get_filter(uint32_t depth)
string chisel_view_info::get_filter(uint32_t depth) const
{
if(m_filter.find("%depth+1") != string::npos)
{
Expand Down
8 changes: 6 additions & 2 deletions userspace/chisel/chisel_viewinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class chisel_view_info

void get_col_names_and_sizes(OUT std::vector<std::string>* colnames, OUT std::vector<int32_t>* colsizes);
chisel_view_column_info* get_key();
std::string get_filter(uint32_t depth);
std::string get_filter(uint32_t depth) const;
viewtype get_type()
{
return m_type;
Expand Down Expand Up @@ -205,14 +205,18 @@ class chisel_view_manager
std::vector<chisel_view_info>* get_views();
uint32_t get_selected_view();
void set_selected_view(std::string viewid);
size_t size()
size_t size() const
{
return m_views.size();
}
chisel_view_info* at(uint32_t viewnum)
{
return &m_views[viewnum];
}
const chisel_view_info* at(uint32_t viewnum) const
{
return &m_views[viewnum];
}

private:
void sort_views();
Expand Down
4 changes: 2 additions & 2 deletions userspace/libscap/engine/gvisor/gvisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ class engine {

int32_t next(scap_evt **pevent, uint16_t *pdevid, uint32_t *pflags);

uint32_t get_vxid(uint64_t pid);
int32_t get_stats(scap_stats *stats);
uint32_t get_vxid(uint64_t pid) const;
int32_t get_stats(scap_stats *stats) const;
const struct scap_stats_v2* get_stats_v2(uint32_t flags, uint32_t* nstats, int32_t* rc);
private:
int32_t process_message_from_fd(int fd);
Expand Down
Loading

0 comments on commit 99a8816

Please sign in to comment.