You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I use benchmark.dll inside a non-console application because I want to benchmark different implementations of ways to solve the same problem. And it is not possible to extract the code into a separate project, as the benchmarked code calls several other functions.
Therefore, I rolled my own BenchmarkMain method that does the same as BENCHMARK_MAIN macro, but also creates a console with AllocConsole, creates std::ostream instances for STD_OUTPUT_HANDLE and STD_ERROR_HANDLE, creates a ConsoleReporter instance and calls RunSpecificBenchmarks with this displayReporter.
The console did receive output, but it reported that Color printing was only supported on Windows - which makes no sense as the console being written to is on Windows.
Along the way, the std::cout.rdbuf() is saved, and replaced with the the same .rdbuf() that is used for the std::ostream out instance.
System
OS: Windows 11 23H2 (build 22631.2861)
Compiler and version: Visual C++ 2022 (Visual Studio 2022 17.8.3), cl.exe version 19.38.33133 for x64
To reproduce
Inside a non-console application, add the following function:
Make sure that the function is being called when the application starts - I control this with a command line parameter.
Note that the output written to the console is without any color formatting.
Expected behavior
Output from benchmarking should get color-enabled output in the created console window
Additional context
The application, where I call the benchmark library, is a MFC Windows application created with use of an external library (CodeJock).
The text was updated successfully, but these errors were encountered:
can you point to where the bug in the library is that is causing the issue, as opposed to an issue with how you're redirecting the various streaming buffers?
bstordrup
changed the title
[BUG] Console created through AllocConsole does not receive output
[BUG] Console created through AllocConsole does not receive colored output
Jan 5, 2024
Updated the issue to more precisely describe the problem.
There are two places in code that contributes to this error:
In console_reporter.cc, there is a check on the output stream where std::cout is directly compared to GetOutputStream(), and if different, the "Color printing is only supported..." is reported.
The ColorPrintf (std::ostream& out, LogColor color, const char* fmt, va_list args) method operates directly on stdout for flushing the stream and uses vprintf to make the actual output.
I have a branch in my local fork with changes in these two places that makes color printing work in a Console window created with AllocConsole.
Describe the bug
I use
benchmark.dll
inside a non-console application because I want to benchmark different implementations of ways to solve the same problem. And it is not possible to extract the code into a separate project, as the benchmarked code calls several other functions.Therefore, I rolled my own BenchmarkMain method that does the same as BENCHMARK_MAIN macro, but also creates a console with
AllocConsole
, createsstd::ostream
instances forSTD_OUTPUT_HANDLE
andSTD_ERROR_HANDLE
, creates aConsoleReporter
instance and callsRunSpecificBenchmarks
with this displayReporter.The console did receive output, but it reported that Color printing was only supported on Windows - which makes no sense as the console being written to is on Windows.
Along the way, the
std::cout.rdbuf()
is saved, and replaced with the the same.rdbuf()
that is used for thestd::ostream out
instance.System
To reproduce
Inside a non-console application, add the following function:
Make sure that the function is being called when the application starts - I control this with a command line parameter.
Note that the output written to the console is without any color formatting.
Expected behavior
Output from benchmarking should get color-enabled output in the created console window
Additional context
The application, where I call the benchmark library, is a MFC Windows application created with use of an external library (CodeJock).
The text was updated successfully, but these errors were encountered: