6 #ifndef HELPER_HPP_INCLUDE
7 #define HELPER_HPP_INCLUDE
26 template <
class Type,
class ...Args>
29 return std::unique_ptr<Type>(
new Type(std::forward<Args>(args)...));
54 write_file(
const std::string &path,
const std::string &contents);
62 string_split(
const std::string &str,
const std::string &delim);
69 string_join(
const std::vector<std::string> &string_list,
const std::string &delim);
147 static constexpr
int hardware_destructive_interference_size = 64;
153 get_env(
const std::string &name);
172 std::unique_ptr<cpu_set_t, std::function<void(cpu_set_t *)> >
GEOPM_PUBLIC
173 make_cpu_set(
int num_cpu,
const std::set<int> &cpu_enabled);
Definition: Helper.hpp:187
virtual ~DeprecationWarning()=default
DeprecationWarning()=delete
#define GEOPM_PUBLIC
Definition: geopm_public.h:10
bool string_ends_with(std::string str, std::string key)
Returns whether one string ends with another.
Definition: Helper.cpp:165
std::function< std::string(double)> string_format_type_to_function(int format_type)
Convert a format type enum string_format_e to a format function.
Definition: Helper.cpp:216
std::string string_join(const std::vector< std::string > &list, const std::string &delim)
Joins a vector of strings together with a delimiter.
Definition: Helper.cpp:115
std::vector< std::string > string_split(const std::string &str, const std::string &delim)
Splits a string according to a delimiter.
Definition: Helper.cpp:93
std::string get_env(const std::string &name)
Read an environment variable.
Definition: Helper.cpp:265
int string_format_function_to_type(std::function< std::string(double)> format_function)
Convert a format function to a format type enum string_format_e.
Definition: Helper.cpp:248
std::unique_ptr< Type > make_unique(Args &&...args)
Implementation of std::make_unique (C++14) for C++11. Note that this version will only work for non-a...
Definition: Helper.hpp:27
std::string hostname(void)
Returns the current hostname as a string.
Definition: Helper.cpp:129
std::string string_format_raw64(double signal)
Format a string to represent the raw memory supporting a signal as an unsigned hexadecimal integer.
Definition: Helper.cpp:208
std::string string_format_double(double signal)
Format a string to best represent a signal encoding a double precision floating point number.
Definition: Helper.cpp:172
void write_file(const std::string &path, const std::string &contents)
Writes a string to a file. This will replace the file if it exists or create it if it does not exist.
Definition: Helper.cpp:81
std::string read_file(const std::string &path)
Reads the specified file and returns the contents in a string.
Definition: Helper.cpp:38
unsigned int pid_to_gid(const int pid)
Query for the group id associated with the process id.
Definition: Helper.cpp:286
std::string string_format_integer(double signal)
Format a string to best represent a signal encoding a decimal integer.
Definition: Helper.cpp:186
std::vector< std::string > list_directory_files(const std::string &path)
List all files in the given directory.
Definition: Helper.cpp:140
std::unique_ptr< cpu_set_t, std::function< void(cpu_set_t *)> > make_cpu_set(int num_cpu, const std::set< int > &cpu_enabled)
Wrapper around CPU_ALLOC and CPU_FREE.
Definition: Helper.cpp:298
bool has_cap_sys_admin(void)
Check if the caller has effective capability CAP_SYS_ADMIN.
Definition: Helper.cpp:358
std::string string_format_float(double signal)
Format a string to best represent a signal encoding a single precision floating point number.
Definition: Helper.cpp:179
string_format_e
Definition: Helper.hpp:88
@ STRING_FORMAT_RAW64
Definition: Helper.hpp:92
@ STRING_FORMAT_DOUBLE
Definition: Helper.hpp:89
@ STRING_FORMAT_INTEGER
Definition: Helper.hpp:90
@ STRING_FORMAT_HEX
Definition: Helper.hpp:91
std::string string_format_hex(double signal)
Format a string to best represent a signal encoding an unsigned hexadecimal integer.
Definition: Helper.cpp:198
std::function< std::string(double)> string_format_name_to_function(const std::string &format_name)
Convert a format function to a format name to a format function.
Definition: Helper.cpp:232
unsigned int pid_to_uid(const int pid)
Query for the user id associated with the process id.
Definition: Helper.cpp:275
bool string_begins_with(const std::string &str, const std::string &key)
Returns whether one string begins with another.
Definition: Helper.cpp:160
double read_double_from_file(const std::string &path, const std::string &expected_units)
Read a file and return a double read from the file.
Definition: Helper.cpp:57