CoreTracer.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Core/Common.h>
  7. #include <AnKi/Util/Thread.h>
  8. #include <AnKi/Util/List.h>
  9. #include <AnKi/Util/File.h>
  10. #include <AnKi/Util/CVarSet.h>
  11. namespace anki {
  12. /// @addtogroup core
  13. /// @{
  14. ANKI_CVAR(BoolCVar, Core, TracingEnabled, false, "Enable or disable tracing")
  15. #if ANKI_OS_ANDROID
  16. ANKI_CVAR(BoolCVar, Core, StreamlineAnnotations, false, "Enable or disable Streamline annotations")
  17. #endif
  18. #if ANKI_TRACING_ENABLED
  19. /// A system that sits on top of the tracer and processes the counters and events.
  20. class CoreTracer : public MakeSingleton<CoreTracer>
  21. {
  22. template<typename>
  23. friend class MakeSingleton;
  24. public:
  25. /// @param directory The directory to store the trace and counters.
  26. Error init(CString directory);
  27. /// It will flush everything.
  28. void flushFrame(U64 frame);
  29. private:
  30. class ThreadWorkItem;
  31. class PerFrameCounters;
  32. Thread m_thread;
  33. ConditionVariable m_cvar;
  34. Mutex m_mtx;
  35. CoreDynamicArray<CoreString> m_counterNames;
  36. IntrusiveList<PerFrameCounters> m_frameCounters;
  37. IntrusiveList<ThreadWorkItem> m_workItems; ///< Items for the thread to process.
  38. CoreString m_traceJsonFilename;
  39. CoreString m_countersCsvFilename;
  40. File m_traceJsonFile;
  41. Bool m_quit = false;
  42. CoreTracer();
  43. ~CoreTracer();
  44. Error threadWorker();
  45. Error writeEvents(ThreadWorkItem& item);
  46. void gatherCounters(ThreadWorkItem& item);
  47. Error writeCountersOnShutdown();
  48. };
  49. #endif
  50. /// @}
  51. } // end namespace anki