aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-03-11 19:33:12 +0100
committerStefan Boberg <[email protected]>2025-03-11 19:33:12 +0100
commit3e6c2a1d744ac70aa384964236cec28be6caeb4a (patch)
tree532491d2d2f752a646cae5e3ba7e3f0bee4d9e90 /src
parentadd support for `--malloc=<...>` in zen CLI (diff)
downloadzen-3e6c2a1d744ac70aa384964236cec28be6caeb4a.tar.xz
zen-3e6c2a1d744ac70aa384964236cec28be6caeb4a.zip
change ProgressBar so it doesn't use printf
printf by default is very slow on Windows due to weird buffering behaviour. During a 2 minute build download I profiled 35 CPU seconds inside printf
Diffstat (limited to 'src')
-rw-r--r--src/zen/zen.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/zen/zen.cpp b/src/zen/zen.cpp
index 0fcf9d871..b7faddaca 100644
--- a/src/zen/zen.cpp
+++ b/src/zen/zen.cpp
@@ -32,6 +32,7 @@
#include <zencore/scopeguard.h>
#include <zencore/string.h>
#include <zencore/trace.h>
+#include <zencore/windows.h>
#include <zenhttp/httpcommon.h>
#include <zenutil/logging.h>
#include <zenutil/zenserverprocess.h>
@@ -323,7 +324,18 @@ ProgressBar::UpdateState(const State& NewState, bool DoLinebreak)
ETA,
NewState.Details.empty() ? "" : fmt::format(". {}", NewState.Details));
std::string::size_type EraseLength = m_LastOutputLength > Output.length() ? (m_LastOutputLength - Output.length()) : 0;
- printf("%s%s%s", Output.c_str(), std::string(EraseLength, ' ').c_str(), DoLinebreak ? "\n" : "");
+
+ ExtendableStringBuilder<128> LineToPrint;
+ LineToPrint << Output << std::string(EraseLength, ' ');
+ if (DoLinebreak)
+ LineToPrint << "\n";
+
+#if ZEN_PLATFORM_WINDOWS
+ WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), LineToPrint.c_str(), (DWORD)LineToPrint.Size(), 0, 0);
+#else
+ fwrite(LineToPrint.c_str(), 1, LineToPrint.Size(), stdout);
+#endif
+
m_LastOutputLength = DoLinebreak ? 0 : Output.length();
m_State = NewState;
}