diff options
| author | yum <yum.food.vr@gmail.com> | 2023-09-09 21:41:36 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2023-09-09 21:46:10 -0700 |
| commit | 286dcae5e087db817f3350cf442145107b25bc9c (patch) | |
| tree | 48b3d9d332923f8cc11f8cf9d72d5d223f619a0b /GUI | |
| parent | 80714a0295df71d6dee35182d221648680f5f7d6 (diff) | |
Constrain log file, UI text field, and transcript sizes
Log file is constrained to 1 MB and UI to 100-200 lines. 1k lines is too
high to keep the UI from lagging.
Transcript is constrained to 4k characters.
Also put a 5 ms sleep in the transcription hot path.
Diffstat (limited to 'GUI')
| -rw-r--r-- | GUI/GUI/GUI/Logging.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/GUI/GUI/GUI/Logging.cpp b/GUI/GUI/GUI/Logging.cpp index 6b42bd6..5d0e23e 100644 --- a/GUI/GUI/GUI/Logging.cpp +++ b/GUI/GUI/GUI/Logging.cpp @@ -10,6 +10,7 @@ #include <wx/tokenzr.h>
#include <wx/txtstrm.h>
+#include <filesystem>
#include <fstream>
#include <regex>
#include <sstream>
@@ -34,7 +35,8 @@ void Logging::ThreadLogger::Append(wxTextCtrl* frame, const std::string&& messag void Logging::ThreadLogger::Drain()
{
std::scoped_lock l(mu_);
- std::ofstream log_ofs("Resources/log.txt", std::ios_base::app);
+ const std::filesystem::path log_path("Resources/log.txt");
+ std::ofstream log_ofs(log_path, std::ios_base::app);
for (const auto& [frame, messages] : messages_) {
for (const auto& message : messages) {
if (frame) {
@@ -46,14 +48,15 @@ void Logging::ThreadLogger::Drain() log_ofs << message;
}
- // Constrain wxTextCtrl's to 1000 lines to keep memory in check.
+ // Constrain wxTextCtrl's to 100-200 lines to keep memory usage /
+ // general snappiness in check.
if (frame) {
wxString allText = frame->GetValue();
wxArrayString lines = wxStringTokenize(allText, "\n");
size_t count = lines.GetCount();
- if (count > 2000) {
- // Keep only the last 1000 lines.
- size_t linesToRemove = count - 1000;
+ if (count > 200) {
+ // Keep only the last 100 lines.
+ size_t linesToRemove = count - 100;
// Remove lines from the beginning
lines.RemoveAt(0, linesToRemove);
@@ -67,9 +70,22 @@ void Logging::ThreadLogger::Drain() }
}
}
-
log_ofs.close();
messages_.clear();
+
+ // Drop first 50% of lines in file if larger than 1 MB.
+ if (std::filesystem::file_size(log_path) > 1024 * 1024) {
+ std::vector<std::string> lines;
+ std::ifstream log_ifs(log_path);
+ std::string line;
+ while (std::getline(log_ifs, line)) {
+ lines.push_back(std::move(line));
+ }
+ log_ofs = std::ofstream(log_path);
+ for (int i = lines.size() / 2; i < lines.size(); i++) {
+ log_ofs << lines[i];
+ }
+ }
}
std::string Logging::HidePII(const std::string&& str,
|
