mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 00:08:53 +02:00
Templatizing the timeProfiler for the task
This commit is contained in:
parent
dd4777bef3
commit
6424b91e86
4 changed files with 46 additions and 43 deletions
|
@ -25,7 +25,7 @@ namespace render {
|
||||||
|
|
||||||
class RenderContext : public task::JobContext {
|
class RenderContext : public task::JobContext {
|
||||||
public:
|
public:
|
||||||
RenderContext() : task::JobContext(trace_render()) {}
|
RenderContext() : task::JobContext() {}
|
||||||
virtual ~RenderContext() {}
|
virtual ~RenderContext() {}
|
||||||
|
|
||||||
RenderArgs* args;
|
RenderArgs* args;
|
||||||
|
@ -33,7 +33,9 @@ namespace render {
|
||||||
};
|
};
|
||||||
using RenderContextPointer = std::shared_ptr<RenderContext>;
|
using RenderContextPointer = std::shared_ptr<RenderContext>;
|
||||||
|
|
||||||
Task_DeclareTypeAliases(RenderContext)
|
Task_DeclareCategoryTimeProfilerClass(RenderTimeProfiler, trace_render);
|
||||||
|
|
||||||
|
Task_DeclareTypeAliases(RenderContext, RenderTimeProfiler)
|
||||||
|
|
||||||
// Versions of the COnfig integrating a gpu & batch timer
|
// Versions of the COnfig integrating a gpu & batch timer
|
||||||
class GPUJobConfig : public JobConfig {
|
class GPUJobConfig : public JobConfig {
|
||||||
|
|
|
@ -12,9 +12,7 @@
|
||||||
|
|
||||||
using namespace task;
|
using namespace task;
|
||||||
|
|
||||||
JobContext::JobContext(const QLoggingCategory& category) :
|
JobContext::JobContext() {
|
||||||
profileCategory(category) {
|
|
||||||
assert(&category);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JobContext::~JobContext() {
|
JobContext::~JobContext() {
|
||||||
|
|
|
@ -15,20 +15,15 @@
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Varying.h"
|
#include "Varying.h"
|
||||||
|
|
||||||
#include "SettingHandle.h"
|
|
||||||
|
|
||||||
#include <Profile.h>
|
|
||||||
#include <PerfStat.h>
|
|
||||||
|
|
||||||
namespace task {
|
namespace task {
|
||||||
|
|
||||||
class JobConcept;
|
class JobConcept;
|
||||||
template <class JC> class JobT;
|
template <class JC, class TP> class JobT;
|
||||||
template <class JC> class TaskT;
|
template <class JC, class TP> class TaskT;
|
||||||
class JobNoIO {};
|
class JobNoIO {};
|
||||||
|
|
||||||
// Task Flow control class is a simple per value object used to communicate flow control commands trhough the graph of tasks.
|
// Task Flow control class is a simple per value object used to communicate flow control commands trhough the graph of tasks.
|
||||||
// From within the Job::Run function, you can access it from the JobCOntext and issue commands which will be picked up by the Task calling for the Job run.
|
// From within the Job::Run function, you can access it from the JobContext and issue commands which will be picked up by the Task calling for the Job run.
|
||||||
// This is first introduced to provide a way to abort all the work from within a task job. see the "abortTask" call
|
// This is first introduced to provide a way to abort all the work from within a task job. see the "abortTask" call
|
||||||
class TaskFlow {
|
class TaskFlow {
|
||||||
public:
|
public:
|
||||||
|
@ -55,11 +50,10 @@ protected:
|
||||||
// The JobContext can be derived to add more global state to it that Jobs can access
|
// The JobContext can be derived to add more global state to it that Jobs can access
|
||||||
class JobContext {
|
class JobContext {
|
||||||
public:
|
public:
|
||||||
JobContext(const QLoggingCategory& category);
|
JobContext();
|
||||||
virtual ~JobContext();
|
virtual ~JobContext();
|
||||||
|
|
||||||
std::shared_ptr<JobConfig> jobConfig { nullptr };
|
std::shared_ptr<JobConfig> jobConfig { nullptr };
|
||||||
const QLoggingCategory& profileCategory;
|
|
||||||
|
|
||||||
// Task flow control
|
// Task flow control
|
||||||
TaskFlow taskFlow{};
|
TaskFlow taskFlow{};
|
||||||
|
@ -115,10 +109,11 @@ template <class T, class JC, class I, class O> void jobRun(T& data, const JC& jo
|
||||||
data.run(jobContext, input, output);
|
data.run(jobContext, input, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class JC>
|
template <class JC, class TP>
|
||||||
class Job {
|
class Job {
|
||||||
public:
|
public:
|
||||||
using Context = JC;
|
using Context = JC;
|
||||||
|
using TimeProfiler = TP;
|
||||||
using ContextPointer = std::shared_ptr<Context>;
|
using ContextPointer = std::shared_ptr<Context>;
|
||||||
using Config = JobConfig;
|
using Config = JobConfig;
|
||||||
using None = JobNoIO;
|
using None = JobNoIO;
|
||||||
|
@ -165,7 +160,7 @@ public:
|
||||||
|
|
||||||
|
|
||||||
void applyConfiguration() override {
|
void applyConfiguration() override {
|
||||||
Duration profileRange(trace_render(), ("configure::" + JobConcept::getName()).c_str());
|
TimeProfiler probe(("configure::" + JobConcept::getName()));
|
||||||
|
|
||||||
jobConfigure(_data, *std::static_pointer_cast<C>(Concept::_config));
|
jobConfigure(_data, *std::static_pointer_cast<C>(Concept::_config));
|
||||||
}
|
}
|
||||||
|
@ -203,14 +198,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void run(const ContextPointer& jobContext) {
|
virtual void run(const ContextPointer& jobContext) {
|
||||||
PerformanceTimer perfTimer(getName().c_str());
|
TimeProfiler probe(getName());
|
||||||
// NOTE: rather than use the PROFILE_RANGE macro, we create a Duration manually
|
|
||||||
Duration profileRange(jobContext->profileCategory, ("run::" + getName()).c_str());
|
|
||||||
|
|
||||||
auto startTime = std::chrono::high_resolution_clock::now();
|
auto startTime = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
_concept->run(jobContext);
|
_concept->run(jobContext);
|
||||||
|
|
||||||
_concept->setCPURunTime((std::chrono::high_resolution_clock::now() - startTime));
|
_concept->setCPURunTime((std::chrono::high_resolution_clock::now() - startTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,13 +216,14 @@ protected:
|
||||||
// The build method is where child Jobs can be added internally to the task
|
// The build method is where child Jobs can be added internally to the task
|
||||||
// where the input of the task can be setup to feed the child jobs
|
// where the input of the task can be setup to feed the child jobs
|
||||||
// and where the output of the task is defined
|
// and where the output of the task is defined
|
||||||
template <class JC>
|
template <class JC, class TP>
|
||||||
class Task : public Job<JC> {
|
class Task : public Job<JC, TP> {
|
||||||
public:
|
public:
|
||||||
using Context = JC;
|
using Context = JC;
|
||||||
|
using TimeProfiler = TP;
|
||||||
using ContextPointer = std::shared_ptr<Context>;
|
using ContextPointer = std::shared_ptr<Context>;
|
||||||
using Config = TaskConfig;
|
using Config = TaskConfig;
|
||||||
using JobType = Job<JC>;
|
using JobType = Job<JC, TP>;
|
||||||
using None = typename JobType::None;
|
using None = typename JobType::None;
|
||||||
using Concept = typename JobType::Concept;
|
using Concept = typename JobType::Concept;
|
||||||
using ConceptPointer = typename JobType::ConceptPointer;
|
using ConceptPointer = typename JobType::ConceptPointer;
|
||||||
|
@ -303,7 +294,7 @@ public:
|
||||||
auto model = std::make_shared<TaskModel>(name, input, std::make_shared<C>());
|
auto model = std::make_shared<TaskModel>(name, input, std::make_shared<C>());
|
||||||
|
|
||||||
{
|
{
|
||||||
Duration profileRange(trace_render(), ("build::" + model->getName()).c_str());
|
TimeProfiler probe("build::" + model->getName());
|
||||||
model->_data.build(*(model), model->_input, model->_output, std::forward<A>(args)...);
|
model->_data.build(*(model), model->_input, model->_output, std::forward<A>(args)...);
|
||||||
}
|
}
|
||||||
// Recreate the Config to use the templated type
|
// Recreate the Config to use the templated type
|
||||||
|
@ -338,7 +329,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void applyConfiguration() override {
|
void applyConfiguration() override {
|
||||||
Duration profileRange(trace_render(), ("configure::" + JobConcept::getName()).c_str());
|
TimeProfiler probe("configure::" + JobConcept::getName());
|
||||||
jobConfigure(_data, *std::static_pointer_cast<C>(Concept::_config));
|
jobConfigure(_data, *std::static_pointer_cast<C>(Concept::_config));
|
||||||
for (auto& job : TaskConcept::_jobs) {
|
for (auto& job : TaskConcept::_jobs) {
|
||||||
job.applyConfiguration();
|
job.applyConfiguration();
|
||||||
|
@ -379,13 +370,13 @@ public:
|
||||||
protected:
|
protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class JC>
|
template <class JC, class TP>
|
||||||
class Engine : public Task<JC> {
|
class Engine : public Task<JC, TP> {
|
||||||
public:
|
public:
|
||||||
using Context = JC;
|
using Context = JC;
|
||||||
using ContextPointer = std::shared_ptr<Context>;
|
using ContextPointer = std::shared_ptr<Context>;
|
||||||
using Config = TaskConfig;
|
using Config = TaskConfig;
|
||||||
using TaskType = Task<JC>;
|
using TaskType = Task<JC, TP>;
|
||||||
using ConceptPointer = typename TaskType::ConceptPointer;
|
using ConceptPointer = typename TaskType::ConceptPointer;
|
||||||
|
|
||||||
Engine(ConceptPointer concept) : TaskType(concept) {}
|
Engine(ConceptPointer concept) : TaskType(concept) {}
|
||||||
|
@ -409,13 +400,13 @@ protected:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define Task_DeclareTypeAliases(ContextType) \
|
#define Task_DeclareTypeAliases(ContextType, TimeProfiler) \
|
||||||
using JobConfig = task::JobConfig; \
|
using JobConfig = task::JobConfig; \
|
||||||
using TaskConfig = task::TaskConfig; \
|
using TaskConfig = task::TaskConfig; \
|
||||||
template <class T> using PersistentConfig = task::PersistentConfig<T>; \
|
template <class T> using PersistentConfig = task::PersistentConfig<T>; \
|
||||||
using Job = task::Job<ContextType>; \
|
using Job = task::Job<ContextType, TimeProfiler>; \
|
||||||
using Task = task::Task<ContextType>; \
|
using Task = task::Task<ContextType, TimeProfiler>; \
|
||||||
using _Engine = task::Engine<ContextType>; \
|
using _Engine = task::Engine<ContextType, TimeProfiler>; \
|
||||||
using Varying = task::Varying; \
|
using Varying = task::Varying; \
|
||||||
template < typename T0, typename T1 > using VaryingSet2 = task::VaryingSet2<T0, T1>; \
|
template < typename T0, typename T1 > using VaryingSet2 = task::VaryingSet2<T0, T1>; \
|
||||||
template < typename T0, typename T1, typename T2 > using VaryingSet3 = task::VaryingSet3<T0, T1, T2>; \
|
template < typename T0, typename T1, typename T2 > using VaryingSet3 = task::VaryingSet3<T0, T1, T2>; \
|
||||||
|
@ -426,4 +417,16 @@ protected:
|
||||||
template < typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7 > using VaryingSet8 = task::VaryingSet8<T0, T1, T2, T3, T4, T5, T6, T7>; \
|
template < typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7 > using VaryingSet8 = task::VaryingSet8<T0, T1, T2, T3, T4, T5, T6, T7>; \
|
||||||
template < class T, int NUM > using VaryingArray = task::VaryingArray<T, NUM>;
|
template < class T, int NUM > using VaryingArray = task::VaryingArray<T, NUM>;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <Profile.h>
|
||||||
|
#include <PerfStat.h>
|
||||||
|
|
||||||
|
#define Task_DeclareCategoryTimeProfilerClass(className, category) \
|
||||||
|
class className : public PerformanceTimer { \
|
||||||
|
public: \
|
||||||
|
className(const std::string& label) : PerformanceTimer(label.c_str()), profileRange(category(), label.c_str()) {} \
|
||||||
|
Duration profileRange; \
|
||||||
|
};
|
||||||
|
|
||||||
#endif // hifi_task_Task_h
|
#endif // hifi_task_Task_h
|
||||||
|
|
|
@ -37,9 +37,9 @@ Rectangle {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
|
|
||||||
spacing: 20
|
spacing: 5
|
||||||
Column {
|
Column {
|
||||||
spacing: 10
|
spacing: 5
|
||||||
// padding: 10
|
// padding: 10
|
||||||
Repeater {
|
Repeater {
|
||||||
model: [
|
model: [
|
||||||
|
@ -61,7 +61,7 @@ Rectangle {
|
||||||
|
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
spacing: 10
|
spacing: 5
|
||||||
Repeater {
|
Repeater {
|
||||||
model: [
|
model: [
|
||||||
"Obscurance:LightingModel:enableObscurance",
|
"Obscurance:LightingModel:enableObscurance",
|
||||||
|
@ -81,7 +81,7 @@ Rectangle {
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
spacing: 10
|
spacing: 5
|
||||||
Repeater {
|
Repeater {
|
||||||
model: [
|
model: [
|
||||||
"Ambient:LightingModel:enableAmbientLight",
|
"Ambient:LightingModel:enableAmbientLight",
|
||||||
|
@ -105,7 +105,7 @@ Rectangle {
|
||||||
Column {
|
Column {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
spacing: 10
|
spacing: 5
|
||||||
Repeater {
|
Repeater {
|
||||||
model: [ "Tone Mapping Exposure:ToneMapping:exposure:5.0:-5.0"
|
model: [ "Tone Mapping Exposure:ToneMapping:exposure:5.0:-5.0"
|
||||||
]
|
]
|
||||||
|
@ -211,9 +211,9 @@ Rectangle {
|
||||||
|
|
||||||
Separator {}
|
Separator {}
|
||||||
Row {
|
Row {
|
||||||
spacing: 10
|
spacing: 5
|
||||||
Column {
|
Column {
|
||||||
spacing: 10
|
spacing: 5
|
||||||
|
|
||||||
HifiControls.CheckBox {
|
HifiControls.CheckBox {
|
||||||
boxSize: 20
|
boxSize: 20
|
||||||
|
@ -254,7 +254,7 @@ Rectangle {
|
||||||
|
|
||||||
}
|
}
|
||||||
Column {
|
Column {
|
||||||
spacing: 10
|
spacing: 5
|
||||||
HifiControls.CheckBox {
|
HifiControls.CheckBox {
|
||||||
boxSize: 20
|
boxSize: 20
|
||||||
text: "Metas"
|
text: "Metas"
|
||||||
|
|
Loading…
Reference in a new issue