Skip to content

Commit

Permalink
refactor(userspace/libsinsp): pass by reference when possible
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dellaluce <[email protected]>
  • Loading branch information
jasondellaluce authored and poiana committed Jul 19, 2024
1 parent f4c94e6 commit ae6b268
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion userspace/libsinsp/gvisor_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ static const std::vector<gvisor_point_info_t> s_gvisor_points = {

constexpr unsigned int max_retries = 3;

std::string generate(std::string socket_path)
std::string generate(const std::string& socket_path)
{
Json::Value jpoints;
for(const auto &point_info : s_gvisor_points)
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/gvisor_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ limitations under the License.

namespace gvisor_config
{
std::string generate(std::string socket_path);
std::string generate(const std::string& socket_path);
}
3 changes: 2 additions & 1 deletion userspace/libsinsp/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ sinsp_logger::severity sinsp_logger::get_severity() const
return m_sev;
}

void sinsp_logger::log(std::string msg, const severity sev)
void sinsp_logger::log(const std::string& m, const severity sev)
{
sinsp_logger_callback cb = nullptr;

Expand All @@ -153,6 +153,7 @@ void sinsp_logger::log(std::string msg, const severity sev)
return;
}

std::string msg = m;
if((m_flags & sinsp_logger::OT_NOTS) == 0)
{
struct timeval ts = {};
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class SINSP_PUBLIC sinsp_logger
* Emit the given msg to the configured log sink if the given sev
* is greater than or equal to the minimum configured logging severity.
*/
void log(std::string msg, severity sev = SEV_INFO);
void log(const std::string& m, severity sev = SEV_INFO);

/**
* Write the given printf-style log message of the given severity
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ std::shared_ptr<sinsp_plugin> sinsp_plugin::create(
return plugin;
}

bool sinsp_plugin::is_plugin_loaded(std::string &filepath)
bool sinsp_plugin::is_plugin_loaded(const std::string &filepath)
{
return plugin_is_loaded(filepath.c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class sinsp_plugin
/**
* @brief Return whether a filesystem dynamic library object is loaded.
*/
static bool is_plugin_loaded(std::string& filepath);
static bool is_plugin_loaded(const std::string& filepath);

/**
* @brief If the plugin has CAP_EXTRACTION capability, returns a
Expand Down
4 changes: 2 additions & 2 deletions userspace/libsinsp/sinsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ bool sinsp::check_current_engine(const std::string& engine_name) const

/*=============================== Engine related ===============================*/

std::string sinsp::generate_gvisor_config(std::string socket_path)
std::string sinsp::generate_gvisor_config(const std::string& socket_path)
{
return gvisor_config::generate(socket_path);
}
Expand Down Expand Up @@ -1800,7 +1800,7 @@ void sinsp::set_log_callback(sinsp_logger_callback cb)
}
}

void sinsp::set_log_file(std::string filename)
void sinsp::set_log_file(const std::string& filename)
{
libsinsp_logger()->add_file_log(filename);
}
Expand Down
4 changes: 2 additions & 2 deletions userspace/libsinsp/sinsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class SINSP_PUBLIC sinsp : public capture_stats_source
scap_fseek(m_h, filepos);
}

std::string generate_gvisor_config(std::string socket_path);
std::string generate_gvisor_config(const std::string& socket_path);


/*!
Expand Down Expand Up @@ -338,7 +338,7 @@ class SINSP_PUBLIC sinsp : public capture_stats_source
/*!
\brief Instruct sinsp to write its log messages to the given file.
*/
void set_log_file(std::string filename);
void set_log_file(const std::string& filename);

/*!
\brief Instruct sinsp to write its log messages to stderr.
Expand Down
10 changes: 5 additions & 5 deletions userspace/libsinsp/threadinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ void sinsp_threadinfo::set_args(const char* args, size_t len)
set_args(sinsp_split(args, len, '\0'));
}

void sinsp_threadinfo::set_args(std::vector<std::string> args)
void sinsp_threadinfo::set_args(const std::vector<std::string>& args)
{
m_args = args;
}
Expand Down Expand Up @@ -742,11 +742,11 @@ void sinsp_threadinfo::set_cgroups(const char* cgroups, size_t len)
set_cgroups(sinsp_split(cgroups, len, '\0'));
}

void sinsp_threadinfo::set_cgroups(std::vector<std::string> cgroups)
void sinsp_threadinfo::set_cgroups(const std::vector<std::string>& cgroups)
{
decltype(m_cgroups) tmp_cgroups(new cgroups_t);
auto tmp_cgroups = std::make_unique<sinsp_threadinfo::cgroups_t>();

for( auto &def : cgroups)
for(const auto &def : cgroups)
{
std::string::size_type eq_pos = def.find("=");
if (eq_pos == std::string::npos)
Expand Down Expand Up @@ -2050,7 +2050,7 @@ const threadinfo_map_t::ptr_t& sinsp_thread_manager::get_thread_ref(int64_t tid,
{
libsinsp_logger()->format(sinsp_logger::SEV_INFO, "%s: Unable to complete for tid=%"
PRIu64 ": sinsp::scap_t* is uninitialized", __func__, tid);
return NULL;
return m_nullptr_tinfo_ret;
}

scap_threadinfo scap_proc {};
Expand Down
4 changes: 2 additions & 2 deletions userspace/libsinsp/threadinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,10 @@ class SINSP_PUBLIC sinsp_threadinfo : public libsinsp::state::table_entry
void remove_fd(int64_t fd);
void update_cwd(std::string_view cwd);
void set_args(const char* args, size_t len);
void set_args(std::vector<std::string> args);
void set_args(const std::vector<std::string>& args);
void set_env(const char* env, size_t len);
void set_cgroups(const char* cgroups, size_t len);
void set_cgroups(std::vector<std::string> cgroups);
void set_cgroups(const std::vector<std::string>& cgroups);
bool is_lastevent_data_valid() const;
inline void set_lastevent_data_validity(bool isvalid)
{
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ void sinsp_utils::split_container_image(const std::string &image,
std::string &digest,
bool split_repo)
{
auto split = [](const std::string &src, std::string &part1, std::string &part2, const std::string sep)
auto split = [](const std::string &src, std::string &part1, std::string &part2, const std::string& sep)
{
size_t pos = src.find(sep);
if(pos != std::string::npos)
Expand Down

0 comments on commit ae6b268

Please sign in to comment.