Skip to content

File tirex_tracker.h

File List > c > include > tirex_tracker.h

Go to the documentation of this file

#ifndef TIREX_TRACKER_H
#define TIREX_TRACKER_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

// This header is automatically generated by CMake
#include <tirex_tracker_export.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum tirexLogLevel_enum { TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL } tirexLogLevel;

typedef void (*tirexLogCallback)(tirexLogLevel level, const char* component, const char* message);

TIREX_TRACKER_EXPORT void tirexSetLogCallback(tirexLogCallback callback); // end of logging

typedef enum tirexError_enum { TIREX_SUCCESS = 0, TIREX_INVALID_ARGUMENT = 1 } tirexError;

typedef void (*tirexAbortCallback)(const char* message);

TIREX_TRACKER_EXPORT void tirexSetAbortLevel(tirexLogLevel level);

TIREX_TRACKER_EXPORT void tirexSetAbortCallback(tirexAbortCallback callback); // end of error

typedef enum tirexMeasure_enum {
    TIREX_OS_NAME = 0,   
    TIREX_OS_KERNEL = 1, 
    TIREX_TIME_ELAPSED_WALL_CLOCK_MS = 2,
    TIREX_TIME_ELAPSED_USER_MS = 3,
    TIREX_TIME_ELAPSED_SYSTEM_MS = 4,

    TIREX_CPU_USED_PROCESS_PERCENT = 5,
    TIREX_CPU_USED_SYSTEM_PERCENT = 6,
    TIREX_CPU_AVAILABLE_SYSTEM_CORES = 7,
    TIREX_CPU_ENERGY_SYSTEM_JOULES = 8,
    TIREX_CPU_FEATURES = 9,
    TIREX_CPU_FREQUENCY_MHZ = 10,
    TIREX_CPU_FREQUENCY_MIN_MHZ = 11,
    TIREX_CPU_FREQUENCY_MAX_MHZ = 12,
    TIREX_CPU_VENDOR_ID = 13,
    TIREX_CPU_BYTE_ORDER = 14,
    TIREX_CPU_ARCHITECTURE = 15,
    TIREX_CPU_MODEL_NAME = 16,
    TIREX_CPU_CORES_PER_SOCKET = 17,
    TIREX_CPU_THREADS_PER_CORE = 18,
    TIREX_CPU_CACHES = 19,
    TIREX_CPU_VIRTUALIZATION = 20,

    TIREX_RAM_USED_PROCESS_KB = 21,
    TIREX_RAM_USED_SYSTEM_MB = 22,
    TIREX_RAM_AVAILABLE_SYSTEM_MB = 23,
    TIREX_RAM_ENERGY_SYSTEM_JOULES = 24,

    TIREX_GPU_SUPPORTED = 25,
    TIREX_GPU_MODEL_NAME = 26,
    TIREX_GPU_NUM_CORES = 27,
    TIREX_GPU_USED_PROCESS_PERCENT = 28,
    TIREX_GPU_USED_SYSTEM_PERCENT = 29,
    TIREX_GPU_VRAM_USED_PROCESS_MB = 30,
    TIREX_GPU_VRAM_USED_SYSTEM_MB = 31,
    TIREX_GPU_VRAM_AVAILABLE_SYSTEM_MB = 32,
    TIREX_GPU_ENERGY_SYSTEM_JOULES = 33,

    TIREX_GIT_IS_REPO = 34,
    TIREX_GIT_HASH = 35,
    TIREX_GIT_LAST_COMMIT_HASH = 36,
    TIREX_GIT_BRANCH = 37,
    TIREX_GIT_BRANCH_UPSTREAM = 38,
    TIREX_GIT_TAGS = 39,
    TIREX_GIT_REMOTE_ORIGIN = 40,
    TIREX_GIT_UNCOMMITTED_CHANGES = 41,
    TIREX_GIT_UNPUSHED_CHANGES = 42,
    TIREX_GIT_UNCHECKED_FILES = 43,

    // Note: The `TIREX_TIME_START`/`TIREX_TIME_STOP` measures were added later, and hence, have new enum values (for
    // backwards compatibility).
    TIREX_TIME_START = 44, 
    TIREX_TIME_STOP = 45,  
    TIREX_GIT_ROOT = 46,
    TIREX_GIT_ARCHIVE_PATH = 47,

    TIREX_VERSION_MEASURE = 48, 
    TIREX_INVOCATION = 49,      
    TIREX_DEVCONTAINER_CONF_PATHS = 50,

    TIREX_CPU_TEMPERATURE_CELSIUS = 51,

    TIREX_MEASURE_COUNT,
    TIREX_MEASURE_INVALID = -1
} tirexMeasure;

#define TIREX_AGG_NO (1 << 1)   
#define TIREX_AGG_MAX (1 << 2)  
#define TIREX_AGG_MIN (1 << 3)  
#define TIREX_AGG_MEAN (1 << 4) 
typedef uint8_t tirexAggregateFn;

typedef struct tirexMeasureHandle_st tirexMeasureHandle; // end of measure

typedef enum tirexResultType_enum {
    TIREX_STRING = 0,
    TIREX_INTEGER = 1,
    TIREX_FLOATING = 2,
    TIREX_BOOLEAN = 3,
    TIREX_WSTRING = 4,
    TIREX_LIST = 1 << 7,
    TIREX_STRING_LIST = TIREX_STRING | TIREX_LIST,
    TIREX_INTEGER_LIST = TIREX_INTEGER | TIREX_LIST,
    TIREX_FLOATING_LIST = TIREX_FLOATING | TIREX_LIST,
    TIREX_BOOLEAN_LIST = TIREX_BOOLEAN | TIREX_LIST,
    TIREX_WSTRING_LIST = TIREX_WSTRING | TIREX_LIST,
} tirexResultType;

#if __cplusplus || __STDC_VERSION__ >= 202311L
// Do nothing since static_assert does not need to be included
#elif __STDC_VERSION__ >= 201112L
#include <assert.h>
#else
// Static assertions are not possible so ignore them
#ifndef static_assert
#define static_assert(cond, msg)
#endif
#endif

static_assert(sizeof(tirexResultType) == 4);

typedef struct tirexResult_st tirexResult;

typedef struct tirexResultEntry_st {
    tirexMeasure source;  
    const void* value;    
    tirexResultType type; 
} tirexResultEntry;

TIREX_TRACKER_EXPORT tirexError
tirexResultEntryGetByIndex(const tirexResult* result, size_t index, tirexResultEntry* entry);

TIREX_TRACKER_EXPORT tirexError tirexResultEntryNum(const tirexResult* result, size_t* num);

TIREX_TRACKER_EXPORT void tirexResultFree(tirexResult* result); // end of tirexresult

typedef struct tirexMeasureConf_st {
    tirexMeasure source;        
    tirexAggregateFn aggregate; 
} tirexMeasureConf;

static const tirexMeasureConf tirexNullConf = {.source = TIREX_MEASURE_INVALID};

#define TIREX_PID_SELF ((int64_t)0)

typedef struct tirexTrackingConf_st {
    const tirexMeasureConf* measures;
    int64_t pid;
    bool trackSubprocesses;
    size_t pollIntervalMs;
} tirexTrackingConf;

TIREX_TRACKER_EXPORT tirexError tirexFetchInfo(tirexTrackingConf conf, tirexResult** result);

TIREX_TRACKER_EXPORT tirexError tirexStartTracking(tirexTrackingConf conf, tirexMeasureHandle** handle);

TIREX_TRACKER_EXPORT tirexError tirexStopTracking(tirexMeasureHandle* handle, tirexResult** result); // end of measure

typedef struct tirexDataProvider_st {
    const char* name;        
    const char* description; 
    const char* version;
} tirexDataProvider;

TIREX_TRACKER_EXPORT size_t tirexDataProviderGetAll(tirexDataProvider* providers, size_t bufsize); // end of dataprovider

typedef struct tirexMeasureInfo_st {
    const char* description;  
    tirexResultType datatype; 
    const char* example;      
} tirexMeasureInfo;

TIREX_TRACKER_EXPORT tirexError tirexMeasureInfoGet(tirexMeasure measure, const tirexMeasureInfo** info); // end of measureinfo
#ifdef __cplusplus
}
#endif

#endif