Adaptyst
A comprehensive and architecture-agnostic performance analysis tool
Loading...
Searching...
No Matches
adaptyst::Process Class Reference

#include <process.hpp>

Classes

class  EmptyCommandException
 
class  NotImplementedException
 
class  NotNotifiableException
 
class  NotReadableException
 
class  NotStartedException
 
class  NotWritableException
 
class  StartException
 
class  WaitException
 

Public Member Functions

 Process (std::function< int()> command, unsigned int buf_size=1024)
 
 Process (std::vector< std::string > &command, unsigned int buf_size=1024)
 
 ~Process ()
 
void add_env (std::string key, std::string value)
 
void set_redirect_stdout (fs::path path)
 
void set_redirect_stdout_to_terminal ()
 
void set_redirect_stdout (Process &process)
 
void set_redirect_stderr (fs::path path)
 
int start (bool wait_for_notify, const CPUConfig &cpu_config, bool is_profiler, fs::path working_path=fs::current_path())
 
int start (fs::path working_path=fs::current_path())
 
void notify ()
 
std::string read_line ()
 
void write_stdin (char *buf, unsigned int size)
 
int join ()
 
bool is_running ()
 
void close_stdin ()
 
void terminate ()
 

Static Public Attributes

static const int ERROR_START = 200
 
static const int ERROR_STDOUT = 201
 
static const int ERROR_STDERR = 202
 
static const int ERROR_STDOUT_DUP2 = 203
 
static const int ERROR_STDERR_DUP2 = 204
 
static const int ERROR_AFFINITY = 205
 
static const int ERROR_STDIN_DUP2 = 206
 
static const int ERROR_NOT_FOUND = 207
 
static const int ERROR_NO_ACCESS = 208
 
static const int ERROR_SETENV = 209
 
static const int ERROR_ABNORMAL_EXIT = 210
 

Detailed Description

This class represents an arbitrary code running in a separate program process.

Constructor & Destructor Documentation

◆ Process() [1/2]

adaptyst::Process::Process ( std::function< int()> command,
unsigned int buf_size = 1024 )
inline

Constructs a Process object.

Parameters
commandFunction returning an exit code to execute in a separate process.
buf_sizeInternal buffer size in bytes.

◆ Process() [2/2]

adaptyst::Process::Process ( std::vector< std::string > & command,
unsigned int buf_size = 1024 )
inline

Constructs a Process object.

Parameters
commandShell command to execute in a separate process.
buf_sizeInternal buffer size in bytes.

◆ ~Process()

adaptyst::Process::~Process ( )
inline

Member Function Documentation

◆ add_env()

void adaptyst::Process::add_env ( std::string key,
std::string value )
inline

Adds an environment variable in form of a key-value pair.

Parameters
keyEnvironment variable key.
valueEnvironment variable value.

◆ close_stdin()

void adaptyst::Process::close_stdin ( )
inline

Closes stdin for writing. This is equivalent to sending EOF to stdin.

◆ is_running()

bool adaptyst::Process::is_running ( )
inline

Returns whether the process is currently running.

Returns
Whether the process is running.

◆ join()

int adaptyst::Process::join ( )
inline

Waits for the process to finish executing.

Returns
Exit code of the process.

◆ notify()

void adaptyst::Process::notify ( )
inline

Notifies the process that it can start. Relevant when start() has been called with wait_for_notify set to true.

◆ read_line()

std::string adaptyst::Process::read_line ( )
inline

Reads a line from stdout.

◆ set_redirect_stderr()

void adaptyst::Process::set_redirect_stderr ( fs::path path)
inline

Redirects stderr to a specified file.

Parameters
pathPath to a stderr file.

◆ set_redirect_stdout() [1/2]

void adaptyst::Process::set_redirect_stdout ( fs::path path)
inline

Redirects stdout to a specified file.

Parameters
pathPath to a stdout file.

◆ set_redirect_stdout() [2/2]

void adaptyst::Process::set_redirect_stdout ( Process & process)
inline

Redirects stdout to another process.

Parameters
processProcess to pipe stdout to.

◆ set_redirect_stdout_to_terminal()

void adaptyst::Process::set_redirect_stdout_to_terminal ( )
inline

Redirects stdout to the terminal.

◆ start() [1/2]

int adaptyst::Process::start ( bool wait_for_notify,
const CPUConfig & cpu_config,
bool is_profiler,
fs::path working_path = fs::current_path() )
inline

Spawns a new process executing a code or command specified in the constructor and returns the ID of the process immediately.

Parameters
wait_for_notifyIndicates whether the process should wait for a notification before executing. If true, the notification should be sent via notify().
cpu_configCPU core configuration for the process.
is_analysisWhether the process corresponds to performance analysis (this is important in the context of cpu_config).
working_pathWorking directory of the process.
Returns
ID of the spawned process (PID in case of a Unix-based system like Linux).

◆ start() [2/2]

int adaptyst::Process::start ( fs::path working_path = fs::current_path())
inline

Spawns a new process executing a code or command specified in the constructor and returns the ID of the process immediately, with a simplified set of arguments (no notification, no specific CPU core configuration, no indication of the process as a performance-analysis-related one).

Parameters
working_pathWorking directory of the process.
Returns
ID of the spawned process (PID in case of a Unix-based system like Linux).

◆ terminate()

void adaptyst::Process::terminate ( )
inline

Terminates the process.

◆ write_stdin()

void adaptyst::Process::write_stdin ( char * buf,
unsigned int size )
inline

Writes data to stdin.

Parameters
bufData to write.
sizeNumber of bytes to write.

Member Data Documentation

◆ ERROR_ABNORMAL_EXIT

const int adaptyst::Process::ERROR_ABNORMAL_EXIT = 210
static

Error exit code when a process exited non-gracefully, e.g. due to a segmentation fault.

◆ ERROR_AFFINITY

const int adaptyst::Process::ERROR_AFFINITY = 205
static

Error exit code when setting CPU affinity for the process.

◆ ERROR_NO_ACCESS

const int adaptyst::Process::ERROR_NO_ACCESS = 208
static

Error exit code due to not having sufficient permissions to execute the given command.

◆ ERROR_NOT_FOUND

const int adaptyst::Process::ERROR_NOT_FOUND = 207
static

Error exit code due to failing to find the given executable.

◆ ERROR_SETENV

const int adaptyst::Process::ERROR_SETENV = 209
static

Error exit code when setting environment variables.

◆ ERROR_START

const int adaptyst::Process::ERROR_START = 200
static

Error exit code when receiving a notification to start the process properly.

◆ ERROR_STDERR

const int adaptyst::Process::ERROR_STDERR = 202
static

Error exit code when opening or accessing the file for redirecting stderr.

◆ ERROR_STDERR_DUP2

const int adaptyst::Process::ERROR_STDERR_DUP2 = 204
static

Error exit code when calling dup2() for redirecting stderr.

◆ ERROR_STDIN_DUP2

const int adaptyst::Process::ERROR_STDIN_DUP2 = 206
static

Error exit code when calling dup2() for redirecting stdin.

◆ ERROR_STDOUT

const int adaptyst::Process::ERROR_STDOUT = 201
static

Error exit code when opening or accessing the file for redirecting stdout.

◆ ERROR_STDOUT_DUP2

const int adaptyst::Process::ERROR_STDOUT_DUP2 = 203
static

Error exit code when calling dup2() for redirecting stdout.


The documentation for this class was generated from the following file: