[FR] support any platform through user-provided functions
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 1.8k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 8
Description
**Is your feature request related to a problem? Please describe.**
I'd like to use the benchmark suite in a restricted environment which differs from the currently supported platforms, like linux or windows. There might not be a steady clock provided through the `libstdc++`, nor are `pthreads` available but a compatibility layer and ultimately my platform exposes its own functions to measure CPU usage for example.
**Describe the solution you'd like**
I've seen there are already [platform-specific switches](https://github.com/google/benchmark/blob/main/src/timers.cc#L142-L179) in-place in some functions. I'd like to be able to provide my own implementations or fallbacks for some parts of the suite.
I could think of the following categories, where that would be useful, also including any errors I got:
* **output streams/console**: The user could provide their own `std::cout`, console [color detection](https://github.com/google/benchmark/blob/main/src/colorprint.cc#L184), etc.
* **thread library**: Since this is [detected by CMake](https://github.com/google/benchmark/blob/main/CMakeLists.txt#L295), there's not much you could to at compile-time.
* **timing functions**: Provide your own `ProcessCPUUsage`, `ThreadCPUUsage`, etc.
* [**cycle clock**](https://github.com/google/benchmark/blob/main/src/cycleclock.h#L219)
* **system info**: Like [`GetSystemName`](https://github.com/google/benchmark/blob/main/src/sysinfo.cc#L447)
**Describe alternatives you've considered**
I couldn't really think of any, yet. Maybe I need to write a linux compatible layer, so that the suite would use the linux API, which internally translate all calls according to my platform, but that is quite the undergoing.
**Additional context**
I acknowledge that my request is an bedge-case. However, I think, that by making it possible to provide user-defined fallbacks for all sorts of functionality of the suite, makes it more attractive for other platform and improves its compatibility.
Contributor guide
Assessment
This issue has not been assessed yet.