-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.c
106 lines (84 loc) · 2.42 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
Copyright NetFoundry Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <uv.h>
#include "utils.h"
#include <ziti/ziti_log.h>
#include <build_config.h>
#if !defined(BUILD_DATE)
#define BUILD_DATE unknown
#endif
#if !defined(ZITI_OS)
#define ZITI_OS unknown
#endif
#if !defined(ZITI_ARCH)
#define ZITI_ARCH unknown
#endif
#if !defined(ZITI_VERSION)
#define ZITI_VERSION unknown
#endif
#if !defined(ZITI_BRANCH)
#define ZITI_BRANCH no-branch
#define ZITI_COMMIT sha
#endif
// #define to_str(x) str(x)
#define str(x) #x
const char* ziti_nodejs_get_version(int verbose) {
if (verbose) {
return "\n\tVersion:\t" to_str(ZITI_NODEJS_VERSION)
"\n\tBuild Date:\t" to_str(BUILD_DATE)
"\n\tGit Branch:\t" to_str(ZITI_NODEJS_BRANCH)
"\n\tGit SHA:\t" to_str(ZITI_NODEJS_COMMIT)
"\n\tOS: \t" to_str(ZITI_OS)
"\n\tArch: \t" to_str(ZITI_ARCH)
"\n\t";
}
return to_str(ZITI_VERSION);
}
const char* ziti_nodejs_git_branch() {
return to_str(ZITI_BRANCH);
}
const char* ziti_nodejs_git_commit() {
return to_str(ZITI_COMMIT);
}
int ziti_nodejs_debug_level = ZITI_LOG_DEFAULT_LEVEL;
FILE *ziti_nodejs_debug_out;
#if _WIN32
LARGE_INTEGER frequency;
LARGE_INTEGER start;
LARGE_INTEGER end;
#else
struct timespec starttime;
#endif
void init_nodejs_debug() {
char *level = getenv("ZITI_NODEJS_LOG");
if (level != NULL) {
ziti_nodejs_debug_level = (int) strtol(level, NULL, 10);
}
ziti_nodejs_debug_out = stderr;
#if _WIN32
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&start);
#else
clock_gettime(CLOCK_MONOTONIC, &starttime);
#endif
}
long get_nodejs_elapsed() {
#if _WIN32
QueryPerformanceCounter(&end);
return end.QuadPart - start.QuadPart;
#else
struct timespec cur;
clock_gettime(CLOCK_MONOTONIC, &cur);
return (cur.tv_sec - starttime.tv_sec) * 1000 + ((cur.tv_nsec - starttime.tv_nsec) / ((long)1e6));
#endif
}