Dynamic Load Balance 3.6.1+32-59d1
backend_utils.h
Go to the documentation of this file.
1/*********************************************************************************/
2/* Copyright 2009-2025 Barcelona Supercomputing Center */
3/* */
4/* This file is part of the DLB library. */
5/* */
6/* DLB is free software: you can redistribute it and/or modify */
7/* it under the terms of the GNU Lesser General Public License as published by */
8/* the Free Software Foundation, either version 3 of the License, or */
9/* (at your option) any later version. */
10/* */
11/* DLB is distributed in the hope that it will be useful, */
12/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14/* GNU Lesser General Public License for more details. */
15/* */
16/* You should have received a copy of the GNU Lesser General Public License */
17/* along with DLB. If not, see <https://www.gnu.org/licenses/>. */
18/*********************************************************************************/
19
20#ifndef PLUGIN_UTILS_H
21#define PLUGIN_UTILS_H
22
23#include <stdint.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <time.h>
27
28
29static inline uint64_t get_timestamp(void) {
30 struct timespec t;
31 clock_gettime(CLOCK_MONOTONIC_RAW, &t);
32 return (uint64_t)t.tv_sec * 1000000000LL + (uint64_t)t.tv_nsec;
33}
34
35
36static inline int plugin_is_verbose() {
37 static int initialized = 0;
38 static int verbose = 0;
39
40 if (!initialized) {
41 const char *env = getenv("DLB_PLUGIN_VERBOSE");
42 if (env && (*env == '1' || *env == 'y' || *env == 'Y')) {
43 verbose = 1;
44 }
45 initialized = 1;
46 }
47 return verbose;
48}
49
50#define PLUGIN_PRINT(fmt, ...) \
51 do { if (plugin_is_verbose()) fprintf(stderr, "[DLB PLUGIN] " fmt, ##__VA_ARGS__); } while (0)
52
53#define PLUGIN_ERROR(fmt, ...) \
54 do { fprintf(stderr, "[DLB PLUGIN ERROR] " fmt, ##__VA_ARGS__); } while (0)
55
56#define PLUGIN_WARNING(fmt, ...) \
57 do { fprintf(stderr, "[DLB PLUGIN WARNING] " fmt, ##__VA_ARGS__); } while (0)
58
59
60#endif /* PLUGIN_UTILS_H */
61
#define verbose(flag,...)
Definition: debug.h:73