CoreTracer.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (C) 2009-2021, 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/Allocator.h>
  9. #include <AnKi/Util/List.h>
  10. #include <AnKi/Util/File.h>
  11. namespace anki
  12. {
  13. /// @addtogroup core
  14. /// @{
  15. /// A system that sits on top of the tracer and processes the counters and events.
  16. class CoreTracer
  17. {
  18. public:
  19. CoreTracer();
  20. ~CoreTracer();
  21. /// @param directory The directory to store the trace and counters.
  22. ANKI_USE_RESULT Error init(GenericMemoryPoolAllocator<U8> alloc, CString directory);
  23. /// It will flush everything.
  24. void flushFrame(U64 frame);
  25. private:
  26. class ThreadWorkItem;
  27. class PerFrameCounters;
  28. GenericMemoryPoolAllocator<U8> m_alloc;
  29. Thread m_thread;
  30. ConditionVariable m_cvar;
  31. Mutex m_mtx;
  32. DynamicArray<String> m_counterNames;
  33. IntrusiveList<PerFrameCounters> m_frameCounters;
  34. IntrusiveList<ThreadWorkItem> m_workItems; ///< Items for the thread to process.
  35. File m_traceJsonFile;
  36. File m_countersCsvFile;
  37. Bool m_quit = false;
  38. Error threadWorker();
  39. Error writeEvents(ThreadWorkItem& item);
  40. void gatherCounters(ThreadWorkItem& item);
  41. Error writeCountersForReal();
  42. };
  43. /// @}
  44. } // end namespace anki