nrm.h 1.76 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 31 32 33 34 35

/* 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;
};

#define NRM_DEFAULT_URI "ipc:///tmp/nrm-downstream-in"
#define NRM_ENV_URI "ARGO_NRM_DOWNSTREAM_IN_URI"

#define NRM_START_FORMAT "{\"type\":\"application\", \"event\":\"start\", \"container\": \"%s\", \"uuid\": \"%s\", \"progress\": true, \"threads\": null}"
#define NRM_PROGRESS_FORMAT "{\"type\":\"application\", \"event\":\"progress\", \"payload\": \"%lu\", \"uuid\": \"%s\"}"
36
#define NRM_PHASE_CONTEXT_FORMAT "{\"type\":\"application\", \"event\":\"phase_context\", \"cpu\": \"%u\", \"aggregation\": \"%u\", \"computetime\": \"%llu\", \"totaltime\": \"%llu\", \"uuid\": \"%s\"}"
Sridutt Bhalachandra's avatar
Sridutt Bhalachandra committed
37 38 39 40 41
#define NRM_EXIT_FORMAT "{\"type\":\"application\", \"event\":\"exit\", \"uuid\": \"%s\"}"

int nrm_init(struct nrm_context *, const char *);
int nrm_fini(struct nrm_context *);

42 43 44 45 46 47 48 49 50 51 52
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
53
	clock_gettime(CLOCK_MONOTONIC, &now);
54 55
	return ((now.tv_sec * 1e9) + now.tv_nsec);
}
Sridutt Bhalachandra's avatar
Sridutt Bhalachandra committed
56 57 58 59 60 61

#ifdef __cplusplus
}
#endif

#endif