Skip to content

Commit bdb7561

Browse files
chore: test
1 parent 789fb65 commit bdb7561

File tree

9 files changed

+63
-9
lines changed

9 files changed

+63
-9
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ jobs:
5656
key: ${{ runner.os }}-build-${{ matrix.codspeed-mode }}-${{ hashFiles('**/CMakeLists.txt') }}
5757

5858
- name: Create build directory
59-
run: mkdir examples\google_benchmark_cmake\build
59+
run: |
60+
if (-not (Test-Path examples\google_benchmark_cmake\build)) {
61+
mkdir examples\google_benchmark_cmake\build
62+
}
6063
shell: pwsh
6164

6265
- name: Build benchmark example

core/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CODSPEED_VERSION = "1.1.1"
66
# Define the codspeed library
77
cc_library(
88
name = "codspeed",
9-
srcs = glob(["src/**/*.cpp"]),
9+
srcs = glob(["src/**/*.cpp"] + ["src/**/*.h"]),
1010
hdrs = glob(["include/**/*.h"] + ["include/**/*.hpp"]),
1111
includes = ["include"],
1212
defines = [

core/include/codspeed.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef CODSPEED_H
22
#define CODSPEED_H
33

4+
#include <cstdint>
45
#include <string>
56
#include <vector>
67

@@ -33,7 +34,7 @@ class CodSpeed {
3334
struct RawWalltimeBenchmark {
3435
std::string name;
3536
std::string uri;
36-
long iter_per_round;
37+
int64_t iter_per_round;
3738
double mean_ns;
3839
double median_ns;
3940
double stdev_ns;

core/src/codspeed.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void CodSpeed::start_benchmark(const std::string &name) {
7676

7777
// Sanity check URI and add a placeholder if format is wrong
7878
if (name.find("::") == std::string::npos) {
79-
std::string uri = "unknown_file::" + name;
79+
uri = "unknown_file::" + name;
8080
std::cout << "WARNING: Benchmark name does not contain '::'. Using URI: "
8181
<< uri << std::endl;
8282
}

core/src/utils.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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

core/src/walltime.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <string>
1010

1111
#include "codspeed.h"
12+
#include "utils.h"
1213
#ifdef _WIN32
1314
#include <process.h>
1415
#else
@@ -31,7 +32,7 @@ struct BenchmarkStats {
3132
double total_time;
3233
uint64_t iqr_outlier_rounds;
3334
uint64_t stdev_outlier_rounds;
34-
long iter_per_round;
35+
int64_t iter_per_round;
3536
uint64_t warmup_iters;
3637
};
3738

@@ -169,8 +170,8 @@ void write_codspeed_benchmarks_to_json(
169170
oss << "}";
170171

171172
// 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;
174175

175176
// Create the results directory if it does not exist
176177
std::filesystem::path results_path = directory + "/results";

core/src/workspace.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,31 @@
33
#include <filesystem>
44

55
#include "codspeed.h"
6+
#include "utils.h"
67

78
namespace codspeed {
89

10+
std::string safe_getenv(const char* var_name) {
11+
#ifdef _WIN32
12+
char* value;
13+
size_t len;
14+
errno_t err = _dupenv_s(&value, &len, var_name);
15+
if (err == 0 && value) {
16+
std::string result(value);
17+
free(value);
18+
return result;
19+
}
20+
return "";
21+
#else
22+
const char* value = std::getenv(var_name);
23+
return value ? value : "";
24+
#endif
25+
}
26+
927
std::string get_path_relative_to_workspace(const std::string &path) {
1028
// 1. Check for bazel usage, through the BUILD_WORKSPACE_DIRECTORY env var
1129
// If so, __FILE__ will already be relative to the bazel workspace root
12-
if (std::getenv("BUILD_WORKSPACE_DIRECTORY") != NULL) {
30+
if (!safe_getenv("BUILD_WORKSPACE_DIRECTORY").empty()) {
1331
return path;
1432
}
1533

examples/google_benchmark_cmake/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ project(codspeed_picobench_compat VERSION 0.0.0 LANGUAGES CXX)
66
# Treat warnings as errors
77
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
88
add_compile_options(-Wall -Wextra -Werror)
9+
elseif(MSVC)
10+
add_compile_options(/W4 /WX
11+
/wd5051 # Ignore [[maybe_unused]] C++17 warnings from Google Benchmark
12+
/wd4038 # Ignore STL <filesystem> C++17 warnings
13+
)
914
endif()
1015

1116
# On the small benchmarks of this repo, most of the benches will be optimized out, but this is expected.
1217
set(CMAKE_BUILD_TYPE RelWithDebInfo)
1318

14-
option(BENCHMARK_ENABLE_GTEST_TESTS OFF)
19+
# Disable Google Benchmark tests
20+
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Enable testing of the benchmark library." FORCE)
21+
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Enable testing of the benchmark library." FORCE)
1522

1623
FetchContent_Declare(
1724
google_benchmark

google_benchmark/include/benchmark/benchmark.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,16 +1459,27 @@ class Fixture : public internal::Benchmark {
14591459
#define BENCHMARK_PRIVATE_CONCAT_NAME(BaseClass, Method) \
14601460
BaseClass##_##Method##_Benchmark
14611461

1462+
#ifdef _MSC_VER
1463+
#define BENCHMARK_PRIVATE_DECLARE(n) \
1464+
/* NOLINTNEXTLINE(misc-use-anonymous-namespace) */ \
1465+
static ::benchmark::internal::Benchmark const* const BENCHMARK_PRIVATE_NAME( \
1466+
n)
1467+
#else
14621468
#define BENCHMARK_PRIVATE_DECLARE(n) \
14631469
/* NOLINTNEXTLINE(misc-use-anonymous-namespace) */ \
14641470
static ::benchmark::internal::Benchmark const* const BENCHMARK_PRIVATE_NAME( \
14651471
n) [[maybe_unused]]
1472+
#endif
14661473

14671474
#ifdef CODSPEED_ENABLED
14681475
#define CUR_FILE \
14691476
codspeed::get_path_relative_to_workspace(__FILE__) + "::"
1477+
#ifdef _MSC_VER
1478+
#define NAMESPACE std::string("")
1479+
#else
14701480
#define NAMESPACE \
14711481
(([]() { return codspeed::extract_lambda_namespace(__PRETTY_FUNCTION__); })())
1482+
#endif
14721483
#define STATIC_NAMESPACE_STRING(name) static std::string name = NAMESPACE;
14731484

14741485
#define FILE_AND_NAMESPACE CUR_FILE + NAMESPACE

0 commit comments

Comments
 (0)