Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

cleanup(libsinsp): remove unused functions from utils.cpp #1697

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 0 additions & 100 deletions userspace/libsinsp/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,54 +861,6 @@ bool sinsp_utils::glob_match(const char *pattern, const char *string, const bool
#endif
}

#ifndef _WIN32
#ifdef __GLIBC__
void sinsp_utils::bt(void)
{
static const char start[] = "BACKTRACE ------------";
static const char end[] = "----------------------";

void *bt[1024];
int bt_size;
char **bt_syms;
int i;

bt_size = backtrace(bt, 1024);
bt_syms = backtrace_symbols(bt, bt_size);
libsinsp_logger()->format("%s", start);
for (i = 1; i < bt_size; i++)
{
libsinsp_logger()->format("%s", bt_syms[i]);
}
libsinsp_logger()->format("%s", end);

free(bt_syms);
}
#endif // __GLIBC__
#endif // _WIN32

bool sinsp_utils::find_first_env(std::string &out, const std::vector<std::string> &env, const std::vector<std::string> &keys)
{
for (const auto& key : keys)
{
for(const auto& env_var : env)
{
if((env_var.size() > key.size()) && !env_var.compare(0, key.size(), key) && (env_var[key.size()] == '='))
{
out = env_var.substr(key.size()+1);
return true;
}
}
}
return false;
}

bool sinsp_utils::find_env(std::string &out, const std::vector<std::string> &env, const std::string &key)
{
const std::vector<std::string> keys = { key };
return find_first_env(out, env, keys);
}

void sinsp_utils::split_container_image(const std::string &image,
std::string &hostname,
std::string &port,
Expand Down Expand Up @@ -973,30 +925,6 @@ void sinsp_utils::split_container_image(const std::string &image,
}
}

void sinsp_utils::parse_suppressed_types(const std::vector<std::string>& supp_strs,
std::vector<ppm_event_code>* supp_ids)
{
for (auto ii = 0; ii < PPM_EVENT_MAX; ii++)
{
auto iter = std::find(supp_strs.begin(), supp_strs.end(),
event_name_by_id(ii));
if (iter != supp_strs.end())
{
supp_ids->push_back(static_cast<ppm_event_code>(ii));
}
}
}

const char* sinsp_utils::event_name_by_id(uint16_t id)
{
if (id >= PPM_EVENT_MAX)
{
ASSERT(false);
return "NA";
}
return g_infotables.m_event_info[id].name;
}

static int32_t gmt2local(time_t t)
{
int dt, dir;
Expand Down Expand Up @@ -1107,34 +1035,6 @@ void sinsp_utils::ts_to_iso_8601(uint64_t ts, OUT std::string* res)
// Time utility functions.
///////////////////////////////////////////////////////////////////////////////

bool sinsp_utils::parse_iso_8601_utc_string(const std::string& time_str, uint64_t &ns)
{
#ifndef _WIN32
tm tm_time{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
char* rem = strptime(time_str.c_str(), "%Y-%m-%dT%H:%M:", &tm_time);
if(rem == NULL || *rem == '\0')
{
return false;
}
tm_time.tm_isdst = -1; // strptime does not set this, signal timegm to determine DST
ns = timegm(&tm_time) * ONE_SECOND_IN_NS;

// Handle the possibly fractional seconds now. Also verify
// that the string ends with Z.
double fractional_secs;
if(sscanf(rem, "%lfZ", &fractional_secs) != 1)
{
return false;
}

ns += (fractional_secs * ONE_SECOND_IN_NS);

return true;
#else
throw sinsp_exception("parse_iso_8601_utc_string() not implemented on Windows");
#endif
}

time_t get_epoch_utc_seconds(const std::string& time_str, const std::string& fmt)
{
#ifndef _WIN32
Expand Down
13 changes: 0 additions & 13 deletions userspace/libsinsp/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ class sinsp_utils
static void bt(void);
#endif // _WIN32

static bool find_first_env(std::string &out, const std::vector<std::string> &env, const std::vector<std::string> &keys);
static bool find_env(std::string &out, const std::vector<std::string> &env, const std::string &key);

static void split_container_image(const std::string &image,
std::string &hostname,
std::string &port,
Expand All @@ -133,20 +130,10 @@ class sinsp_utils
std::string &digest,
bool split_repo = true);

static void parse_suppressed_types(const std::vector<std::string>& supp_strs,
std::vector<ppm_event_code>* supp_ids);

static const char* event_name_by_id(uint16_t id);

static void ts_to_string(uint64_t ts, OUT std::string* res, bool date, bool ns);

static void ts_to_iso_8601(uint64_t ts, OUT std::string* res);

// Limited version of iso 8601 time string parsing, that assumes a
// timezone of Z for UTC, but does support parsing fractional seconds,
// unlike get_epoch_utc_seconds_* below.
static bool parse_iso_8601_utc_string(const std::string& time_str, uint64_t &ns);

//
// Convert caps from their numeric representation to a space-separated string list
//
Expand Down
Loading