Files
spark/src/lib/os/os.h
T

92 lines
2.4 KiB
C++
Executable File

#ifndef OS_H_
#define OS_H_
#include "lib/utils/bts_export.h"
#include <string>
#include <vector>
#include <map>
#include <stdint.h>
#include <memory>
#include <limits>
#include <cmath>
namespace bts {
namespace os {
#ifdef _WIN32
#define ALIGNED_(x) __declspec(align(x))
#else
#define ALIGNED_(x) __attribute__((aligned(x)))
#endif
#define CACHE_LINE 64
inline bool is_windows() {
#ifdef _WIN32
return true;
#else
return false;
#endif
}
BTS_EXPORT char const* platform_name ();
BTS_EXPORT unsigned int process_id ();
BTS_EXPORT bool is_running(unsigned int pid);
struct ProcInfo
{
ProcInfo ():pid (0), exe (), args ()
{}
int pid;
std::string exe;
std::vector<std::string> args;
};
class BTS_EXPORT RunningProcessesQuerier
{
public:
RunningProcessesQuerier(std::vector<std::string> const&exe_name_hints);
std::vector<ProcInfo> query ();
~RunningProcessesQuerier();
private:
struct PImpl;
std::unique_ptr<PImpl> me;
};
BTS_EXPORT std::vector<ProcInfo> running_processes ();
BTS_EXPORT std::string host_name ();
BTS_EXPORT std::string default_host_ip ();
BTS_EXPORT std::string host_ip (std::string const &interface_name);
BTS_EXPORT std::map<std::string,std::string> host_ips ();
BTS_EXPORT uint64_t tick_count ();
BTS_EXPORT std::string get_install_path();
BTS_EXPORT std::string get_application_name();
BTS_EXPORT std::string get_cwd();
BTS_EXPORT void gen_uuid (unsigned char out[16]);
BTS_EXPORT std::string& normalize_path(std::string& path, char separator='/');
BTS_EXPORT std::string sanitize_file_name(std::string const& file_name);
BTS_EXPORT std::vector<std::string> get_command_line();
BTS_EXPORT std::string get_qualifier();
BTS_EXPORT void enable_core_dumps();
extern "C" BTS_EXPORT int get_random_port();
extern "C" BTS_EXPORT int num_cores();
std::string sparkd_wd();
std::string sparkdata_path(const std::string&);
std::string bts_data_path();
std::string username();
BTS_EXPORT char* strncpy(char* dest, const char* src, size_t count);
BTS_EXPORT void setenv(const char* name, const char* value);
BTS_EXPORT void set_thread_name(std::string const&);
BTS_EXPORT void set_thread_name(const char* name);
BTS_EXPORT void get_thread_name(std::string *out);
inline bool is_nan(double d) { return std::isnan(d); }
inline bool is_nan(float f) { return std::isnan(f); }
inline double nan () { return std::numeric_limits<double>::quiet_NaN(); }
BTS_EXPORT float fnan ();
BTS_EXPORT bool is_finite(double d);
int cache_size_l3_bytes();
}}
#endif