165 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			165 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /* Copyright (c) 2021-2024 Barcelona Supercomputing Center (BSC)
 | |
|  * SPDX-License-Identifier: MIT */
 | |
| 
 | |
| #ifndef OVNI_H
 | |
| #define OVNI_H
 | |
| 
 | |
| #pragma GCC visibility push(default)
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| #include <limits.h>
 | |
| #include <linux/limits.h>
 | |
| #include <stdint.h>
 | |
| #include <stdio.h>
 | |
| #include <stdlib.h>
 | |
| #include <string.h>
 | |
| #include <sys/types.h>
 | |
| 
 | |
| #define OVNI_METADATA_VERSION 3
 | |
| 
 | |
| #define OVNI_TRACEDIR "ovni"
 | |
| #define OVNI_MAX_HOSTNAME 512
 | |
| 
 | |
| /* Reserved buffer for event allocation per thread */
 | |
| #define OVNI_MAX_EV_BUF (2 * 1024LL * 1024LL) /* 2 MiB */
 | |
| 
 | |
| #define OVNI_STREAM_MAGIC "ovni"
 | |
| #define OVNI_STREAM_VERSION 1
 | |
| 
 | |
| #define OVNI_STREAM_EXT ".obs"
 | |
| 
 | |
| /* Version of the ovni model for events */
 | |
| #define OVNI_MODEL_VERSION "1.1.0"
 | |
| 
 | |
| /* Follow https://semver.org rules for versioning */
 | |
| #define OVNI_LIB_VERSION "@PROJECT_VERSION@"
 | |
| #define OVNI_GIT_COMMIT  "@OVNI_GIT_COMMIT@"
 | |
| 
 | |
| /* ----------------------- common ------------------------ */
 | |
| 
 | |
| enum ovni_ev_flags {
 | |
| 	OVNI_EV_JUMBO = 0x10,
 | |
| };
 | |
| 
 | |
| struct __attribute__((__packed__)) ovni_jumbo_payload {
 | |
| 	uint32_t size;
 | |
| 	uint8_t data[1];
 | |
| };
 | |
| 
 | |
| union __attribute__((__packed__)) ovni_ev_payload {
 | |
| 	int8_t i8[16];
 | |
| 	int16_t i16[8];
 | |
| 	int32_t i32[4];
 | |
| 	int64_t i64[2];
 | |
| 
 | |
| 	uint8_t u8[16];
 | |
| 	uint16_t u16[8];
 | |
| 	uint32_t u32[4];
 | |
| 	uint64_t u64[2];
 | |
| 
 | |
| 	struct ovni_jumbo_payload jumbo;
 | |
| };
 | |
| 
 | |
| struct __attribute__((__packed__)) ovni_ev_header {
 | |
| 	/* first 4 bits reserved, last 4 for payload size */
 | |
| 	uint8_t flags;
 | |
| 	uint8_t model;
 | |
| 	uint8_t category;
 | |
| 	uint8_t value;
 | |
| 	uint64_t clock;
 | |
| };
 | |
| 
 | |
| struct __attribute__((__packed__)) ovni_ev {
 | |
| 	struct ovni_ev_header header;
 | |
| 
 | |
| 	/* The payload size may vary depending on the ev type:
 | |
| 	 *   - normal: 0, or 2 to 16 bytes
 | |
| 	 *   - jumbo: 0 to 2^32 - 1 bytes */
 | |
| 	union ovni_ev_payload payload;
 | |
| };
 | |
| 
 | |
| struct __attribute__((__packed__)) ovni_stream_header {
 | |
| 	char magic[4];
 | |
| 	uint32_t version;
 | |
| };
 | |
| 
 | |
| /* ----------------------- runtime ------------------------ */
 | |
| 
 | |
| #define ovni_version_check() ovni_version_check_str(OVNI_LIB_VERSION)
 | |
| void ovni_version_check_str(const char *version);
 | |
| void ovni_version_get(const char **version, const char **commit);
 | |
| 
 | |
| void ovni_proc_init(int app, const char *loom, int pid);
 | |
| 
 | |
| /* Sets the MPI rank of the current process and the number of total nranks */
 | |
| void ovni_proc_set_rank(int rank, int nranks);
 | |
| 
 | |
| void ovni_proc_fini(void);
 | |
| 
 | |
| void ovni_thread_init(pid_t tid);
 | |
| 
 | |
| void ovni_thread_require(const char *model, const char *version);
 | |
| 
 | |
| void ovni_thread_free(void);
 | |
| 
 | |
| int ovni_thread_isready(void);
 | |
| 
 | |
| void ovni_ev_set_mcv(struct ovni_ev *ev, const char *mcv);
 | |
| 
 | |
| /* Gets the event clock in ns */
 | |
| uint64_t ovni_ev_get_clock(const struct ovni_ev *ev);
 | |
| 
 | |
| /* Sets the event clock in ns */
 | |
| void ovni_ev_set_clock(struct ovni_ev *ev, uint64_t clock);
 | |
| 
 | |
| /* Returns the current value of the ovni clock in ns */
 | |
| uint64_t ovni_clock_now(void);
 | |
| 
 | |
| void ovni_payload_add(struct ovni_ev *ev, const uint8_t *buf, int size);
 | |
| 
 | |
| int ovni_ev_size(const struct ovni_ev *ev);
 | |
| 
 | |
| int ovni_payload_size(const struct ovni_ev *ev);
 | |
| 
 | |
| void ovni_add_cpu(int index, int phyid);
 | |
| 
 | |
| /* Adds the event to the events buffer. The buffer is flushed first if the event
 | |
|  * doesn't fit in the buffer. */
 | |
| void ovni_ev_emit(struct ovni_ev *ev);
 | |
| void ovni_ev_jumbo_emit(struct ovni_ev *ev, const uint8_t *buf, uint32_t bufsize);
 | |
| 
 | |
| void ovni_flush(void);
 | |
| 
 | |
| /* Attributes */
 | |
| int ovni_attr_has(const char *key);
 | |
| void ovni_attr_set_double(const char *key, double num);
 | |
| void ovni_attr_set_boolean(const char *key, int value);
 | |
| void ovni_attr_set_str(const char *key, const char *value);
 | |
| void ovni_attr_set_json(const char *key, const char *json);
 | |
| double ovni_attr_get_double(const char *key);
 | |
| int ovni_attr_get_boolean(const char *key);
 | |
| const char *ovni_attr_get_str(const char *key);
 | |
| char *ovni_attr_get_json(const char *key);
 | |
| void ovni_attr_flush(void);
 | |
| 
 | |
| /* Mark */
 | |
| enum ovni_mark_flags {
 | |
| 	OVNI_MARK_STACK = 1, /*< Use push/pop instead of set */
 | |
| };
 | |
| void ovni_mark_type(int32_t type, long flags, const char *title);
 | |
| void ovni_mark_label(int32_t type, int64_t value, const char *label);
 | |
| void ovni_mark_push(int32_t type, int64_t value);
 | |
| void ovni_mark_pop(int32_t type, int64_t value);
 | |
| void ovni_mark_set(int32_t type, int64_t value);
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #pragma GCC visibility pop
 | |
| 
 | |
| #endif /* OVNI_H */
 |