AGX Dynamics 2.42.3.0
Loading...
Searching...
No Matches
ProfilingTools.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18#include <agx/Thread.h>
19#include <agxTerrain/export.h>
20#include <agx/Referenced.h>
21#include <agx/Name.h>
23#include <agx/HashTable.h>
24#include <agx/HashVector.h>
25#include <iostream>
26#include <iomanip>
27
28namespace agxTerrain
29{
30 namespace Profiler
31 {
33 using Bucket = std::pair<agx::Name, agx::Real>;
34
42 }
43
46 {
47 public:
48 explicit ScopeTimer(const agx::Name& name)
49 : m_timer(false)
50 , m_name(name)
51 {
52 m_timer.start();
53 }
54
55 protected:
56 virtual ~ScopeTimer()
57 {
58 m_timer.stop();
59 Profiler::registerTiming(m_name, m_timer.getTime());
60 }
61
64 };
65}
66
67#define SCOPE_PROFILER(a) agxTerrain::ScopeTimerRef ref = new agxTerrain::ScopeTimer(a);
68#define PRINT_TIMINGS() Profiler::printTimers();
69
70
71namespace agxTerrain {
74 {
75 public:
76 explicit ScopeReportSystemJob(const char* name)
77 : m_name(name)
78 , m_start(0)
79 , m_end(0)
80 {
82 }
83
84 protected:
86 {
88 agx::Thread::getCurrentThread()->reportSystemJob( m_start, m_end, m_name );
89 }
90
91 const char* m_name;
94 };
95}
96#define USE_EXTENDED_TERRAIN_PROFILING 1
97#if defined(USE_EXTENDED_TERRAIN_PROFILING) && USE_EXTENDED_TERRAIN_PROFILING
98 #define GET_TIMESTAMP(varname) agx::UInt64 varname = agx::Timer::getCurrentTick();
99 #define THREAD_LOG_ITEM( textname, var1, var2 ) agx::Thread::getCurrentThread()->reportSystemJob( var1, var2, textname );
100 #define GET_SCOPE_SYSTEM_JOB(scopeName, varname) agxTerrain::ScopeReportSystemJobRef varname = new agxTerrain::ScopeReportSystemJob(scopeName);
101 #define TIMER_BLOCK( str )\
102 auto sjrtb = agxUtil::TimerBlock([]( agx::UInt64 start, agx::UInt64 stop )\
103 {\
104 std::cout << std::left << std::setw( 50 ) << std::setfill( ' ' )\
105 << str\
106 << " : " << agx::Timer::convertToMs( stop - start ) << " ms." << std::endl;\
107 } )
108#else
109 #define GET_TIMESTAMP( varname )
110 #define THREAD_LOG_ITEM( textname, var1, var2 )
111 #define GET_SCOPE_SYSTEM_JOB( scopeName, varname )
112 #define TIMER_BLOCK( str )
113#endif
114
115
116
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXTERRAIN_EXPORT
ScopeReportSystemJob(const char *name)
ScopeTimer(const agx::Name &name)
agx::HighAccuracyTimer m_timer
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:41
The HighAccurayTimer class can replace the regular Timer class in high level applications where the n...
Representation of a name string.
Definition: Name.h:33
Base class providing referencing counted objects.
Definition: Referenced.h:120
static Thread * getCurrentThread()
void reportSystemJob(UInt64 startTick, UInt64 endTick, const char *description, const char *extraDataTitle=nullptr, agx::Real64 extraData=0.0)
Add an entry to the job duration log.
static UInt64 getCurrentTick()
Definition: Timer.h:207
AGXTERRAIN_EXPORT agx::Real & currentTime()
AGXTERRAIN_EXPORT TimingStorage & getStorage()
AGXTERRAIN_EXPORT void resetFile(const agx::String &filename)
AGXTERRAIN_EXPORT void registerTiming(const agx::Name &name, agx::Real value)
AGXTERRAIN_EXPORT void printTimers(const agx::String &title)
agx::HashVector< agx::Name, agx::Real > TimingStorage
std::pair< agx::Name, agx::Real > Bucket
AGXTERRAIN_EXPORT void clear()
AGXTERRAIN_EXPORT void printToFile(agx::Real time, const agx::String &filename)
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:59
uint64_t UInt64
Definition: Integer.h:33
double Real
Definition: Real.h:41