From 3522d757fcf919aceefe0314a9d32d24299f307a Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 18 Nov 2017 21:10:54 -1000 Subject: [PATCH] Add `-l` flag to enable logging --- Editor/main.cpp | 23 +++++++++++++++++++---- Runtime/CDvdFile.cpp | 1 + Runtime/CFactoryMgr.cpp | 1 + Runtime/CMakeLists.txt | 1 + Runtime/CResFactory.cpp | 1 + Runtime/CStopwatch.hpp | 21 +++++++++++++++++++++ hecl | 2 +- nod | 2 +- 8 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 Runtime/CStopwatch.hpp diff --git a/Editor/main.cpp b/Editor/main.cpp index 5af94c3f2..fb59ce6f6 100644 --- a/Editor/main.cpp +++ b/Editor/main.cpp @@ -4,6 +4,7 @@ #include "hecl/CVarManager.hpp" #include "Runtime/CBasics.hpp" #include "ViewManager.hpp" +#include "hecl/hecl.hpp" static logvisor::Module AthenaLog("Athena"); static void AthenaExc(athena::error::Level level, const char* file, @@ -125,20 +126,33 @@ struct Application : boo::IApplicationCallback static hecl::SystemChar CwdBuf[1024]; hecl::SystemString ExeDir; -void SetupBasics() +static void SetupBasics(bool logging) { logvisor::RegisterStandardExceptions(); - logvisor::RegisterConsoleLogger(); + if (logging) + logvisor::RegisterConsoleLogger(); atSetExceptionHandler(AthenaExc); } +static bool IsClientLoggingEnabled(int argc, const boo::SystemChar** argv) +{ + bool logging = false; + for (int i = 1; i < argc; ++i) + if (!hecl::StrNCmp(argv[i], _S("-l"), 2)) + { + logging = true; + break; + } + return logging; +} + #if _WIN32 int wmain(int argc, const boo::SystemChar** argv) #else int main(int argc, const boo::SystemChar** argv) #endif { - SetupBasics(); + SetupBasics(IsClientLoggingEnabled(argc, argv)); if (hecl::SystemChar* cwd = hecl::Getcwd(CwdBuf, 1024)) { @@ -182,7 +196,8 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int) for (int i=0 ; i + +namespace urde +{ +class CStopwatch +{ + std::chrono::steady_clock::time_point m_start; +public: + CStopwatch() : m_start(std::chrono::steady_clock::now()) {} + void report(const char* name) const + { + printf("%s %f\n", name, std::chrono::duration_cast( + std::chrono::steady_clock::now() - m_start).count() / 1000000.f); + } +}; +} + +#endif // __URDE_CSTOPWATCH_HPP__ diff --git a/hecl b/hecl index fd8b53d62..5f21d6081 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit fd8b53d626cf1204c8d6dea80f64573afc8e784a +Subproject commit 5f21d60814dcd2dbb5d58db7e78b5efb04435c39 diff --git a/nod b/nod index b5916af70..e20fce1e6 160000 --- a/nod +++ b/nod @@ -1 +1 @@ -Subproject commit b5916af70270185fb6aba5db8f670859483ffa4f +Subproject commit e20fce1e6f45b5dd2740fa4544a9f8471a1d52c0