nrm.h 1.83 KB
Newer Older
Sridutt Bhalachandra's avatar
Sridutt Bhalachandra committed
1 2 3 4 5 6 7 8 9 10
/* Filename: downstream_api.h
 *
 * Includes required headers, functions and parameters used by NRM downstream 
 * interface
 *
 */

#ifndef NRM_H
#define NRM_H 1

11 12 13 14 15 16
#include <inttypes.h>
#include <time.h>

#ifdef __cplusplus
extern "C" {
#endif
Sridutt Bhalachandra's avatar
Sridutt Bhalachandra committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30

/* min time in nsec between messages: necessary for rate-limiting progress
 * report. For now, 10ms is the threashold. */
#define NRM_RATELIMIT_THRESHOLD (10000000LL)

struct nrm_context {
    void *context;
    void *socket;
    char *container_uuid;
    char *app_uuid;
    struct timespec time;
    unsigned long acc;
};

31 32
#define NRM_DEFAULT_URI "ipc:///tmp/nrm-downstream-event"
#define NRM_ENV_URI "ARGO_NRM_DOWNSTREAM_EVENT_URI"
Sridutt Bhalachandra's avatar
Sridutt Bhalachandra committed
33

34
#define NRM_START_FORMAT "{\"api\":\"down_event\", \"type\":\"application_start\", \"container_uuid\": \"%s\", \"application_uuid\": \"%s\"}"
35
#define NRM_PROGRESS_FORMAT "{\"api\":\"down_event\", \"type\":\"progress\", \"payload\": %lu, \"application_uuid\": \"%s\"}"
36
#define NRM_PHASE_CONTEXT_FORMAT "{\"api\":\"down_event\",\"type\":\"phase_context\", \"cpu\": %u, \"aggregation\": %u, \"computetime\": %llu, \"totaltime\": %llu, \"application_uuid\": \"%s\"}"
37
#define NRM_EXIT_FORMAT "{\"api\": \"down_event\", \"type\":\"application_exit\"}"
Sridutt Bhalachandra's avatar
Sridutt Bhalachandra committed
38

39 40 41
struct nrm_context* nrm_ctxt_create(void);
int nrm_ctxt_delete(struct nrm_context *);

Sridutt Bhalachandra's avatar
Sridutt Bhalachandra committed
42 43 44
int nrm_init(struct nrm_context *, const char *);
int nrm_fini(struct nrm_context *);

45 46 47 48 49 50 51 52 53 54 55
int nrm_send_progress(struct nrm_context *, unsigned long progress);
int nrm_send_phase_context(struct nrm_context *ctxt,
			   unsigned int cpu,
			   unsigned int aggregation,
			   unsigned long long int computeTime,
			   unsigned long long int totalTime);

/* util function */
inline long long int nrm_gettime(void)
{
	struct timespec now;
Valentin Reis's avatar
Valentin Reis committed
56
	clock_gettime(CLOCK_MONOTONIC, &now);
57 58
	return ((now.tv_sec * 1e9) + now.tv_nsec);
}
Sridutt Bhalachandra's avatar
Sridutt Bhalachandra committed
59 60 61 62 63 64

#ifdef __cplusplus
}
#endif

#endif