File tree Expand file tree Collapse file tree 4 files changed +39
-6
lines changed Expand file tree Collapse file tree 4 files changed +39
-6
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ CODSPEED_VERSION = "1.1.1"
6
6
# Define the codspeed library
7
7
cc_library (
8
8
name = "codspeed" ,
9
- srcs = glob (["src/**/*.cpp" ]),
9
+ srcs = glob (["src/**/*.cpp" ] + [ "src/**/*.h" ] ),
10
10
hdrs = glob (["include/**/*.h" ] + ["include/**/*.hpp" ]),
11
11
includes = ["include" ],
12
12
defines = [
Original file line number Diff line number Diff line change
1
+ #ifndef CODSPEED_UTILS_H
2
+ #define CODSPEED_UTILS_H
3
+
4
+ #include < string>
5
+
6
+ namespace codspeed {
7
+
8
+ // Cross-platform getenv wrapper
9
+ std::string safe_getenv (const char * var_name);
10
+
11
+ } // namespace codspeed
12
+
13
+ #endif // CODSPEED_UTILS_H
Original file line number Diff line number Diff line change 9
9
#include < string>
10
10
11
11
#include " codspeed.h"
12
+ #include " utils.h"
12
13
#ifdef _WIN32
13
14
#include < process.h>
14
15
#else
@@ -31,7 +32,7 @@ struct BenchmarkStats {
31
32
double total_time;
32
33
uint64_t iqr_outlier_rounds;
33
34
uint64_t stdev_outlier_rounds;
34
- long iter_per_round;
35
+ uint64_t iter_per_round;
35
36
uint64_t warmup_iters;
36
37
};
37
38
@@ -169,8 +170,8 @@ void write_codspeed_benchmarks_to_json(
169
170
oss << " }" ;
170
171
171
172
// Determine the directory path
172
- const char * profile_folder = std::getenv (" CODSPEED_PROFILE_FOLDER" );
173
- std::string directory = profile_folder ? profile_folder : " ." ;
173
+ std::string profile_folder = safe_getenv (" CODSPEED_PROFILE_FOLDER" );
174
+ std::string directory = profile_folder. empty () ? " ." : profile_folder ;
174
175
175
176
// Create the results directory if it does not exist
176
177
std::filesystem::path results_path = directory + " /results" ;
Original file line number Diff line number Diff line change 3
3
#include < filesystem>
4
4
5
5
#include " codspeed.h"
6
+ #include " utils.h"
6
7
7
8
namespace codspeed {
8
9
9
- std::string get_path_relative_to_workspace (const std::string &path) {
10
+ std::string safe_getenv (const char * var_name) {
11
+ #ifdef _WIN32
12
+ // On Windows, use _dupenv_s instead of std::getenv for thread safety
13
+ char * value;
14
+ size_t len;
15
+ errno_t err = _dupenv_s (&value, &len, var_name);
16
+ if (err == 0 && value) {
17
+ std::string result (value);
18
+ free (value);
19
+ return result;
20
+ }
21
+ return " " ;
22
+ #else
23
+ const char * value = std::getenv (var_name);
24
+ return value ? value : " " ;
25
+ #endif
26
+ }
27
+
28
+ std::string get_path_relative_to_workspace (const std::string& path) {
10
29
// 1. Check for bazel usage, through the BUILD_WORKSPACE_DIRECTORY env var
11
30
// If so, __FILE__ will already be relative to the bazel workspace root
12
- if (std::getenv (" BUILD_WORKSPACE_DIRECTORY" ) != NULL ) {
31
+ if (! safe_getenv (" BUILD_WORKSPACE_DIRECTORY" ). empty () ) {
13
32
return path;
14
33
}
15
34
You can’t perform that action at this time.
0 commit comments