HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
executionStatsProcessor.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_EXEC_VDF_EXECUTION_STATS_PROCESSOR_H
8 #define PXR_EXEC_VDF_EXECUTION_STATS_PROCESSOR_H
9 
10 /// \file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/vdf/api.h"
16 #include "pxr/exec/vdf/types.h"
17 
18 #include <optional>
19 #include <thread>
20 
22 
24 {
25 public:
26 
27  /// A per-thread id.
28  ///
30 
31  /// Destructor.
32  ///
33  VDF_API
34  virtual ~VdfExecutionStatsProcessor();
35 
36  /// Processes the given execution stats to fill the processor with processed
37  /// stats.
38  ///
39  VDF_API
40  void Process(const VdfExecutionStats* stats);
41 
42  /// Returns the network pointer. Should only be called after Process has
43  /// been called.
44  ///
45  /// XXX :
46  /// In the future, we should remove direct network access and limit network
47  /// access via an API in the processor that only allows client classes to
48  /// access node pointers if they are valid / current.
49  ///
50  VDF_API
51  const VdfNetwork* GetNetwork() const;
52 
53 protected:
54  /// Protected constructor.
55  ///
56  VDF_API
58 
59  /// Virtual method for processing a single event given a thread id and
60  /// an event. Called by _ProcessEvents.
61  ///
62  virtual void _ProcessEvent(
63  ThreadId threadId,
64  const VdfExecutionStats::Event& event) = 0;
65 
66  /// Virtual method for processing a single sub stat given a sub stat.
67  /// Called by _ProcessSubStats.
68  /// NOTE : No child class hold on to the subStats pointer. The lifetime of
69  /// substats is managed inside MfExecInterpreter, so there is no
70  /// guarantee that the subStats pointer will be valid except during
71  /// scope of this function.
72  ///
73  virtual void _ProcessSubStat(const VdfExecutionStats* subStat) = 0;
74 
75  /// Virtual method that runs before processing. Should be used to set up
76  /// results.
77  ///
78  virtual void _PreProcess() {}
79 
80  /// Virtual method that runs after processing. Should be used to aggregate
81  /// results.
82  ///
83  virtual void _PostProcess() {}
84 
85 private:
86  /// Goes through all event vectors and calls _ProcessEvent on each event.
87  /// Arbitrarily assigns a thread id to each event vector. So it is
88  /// guaranteed that events in the same event vector will have the same
89  /// thread id. However, this does not necessarily map to the os thread id.
90  ///
91  VDF_API
92  void _ProcessEvents(const VdfExecutionStats* stats);
93 
94  /// Goes through all sub stats and calls _ProcessSubStat on each substat.
95  ///
96  VDF_API
97  void _ProcessSubStats(const VdfExecutionStats* stats);
98 
99 private:
100  const VdfNetwork* _network;
101  std::optional<VdfId> _invokingNodeId;
102 };
103 
105 
106 #endif /* VDF_EXECUTION_STATS_PROCESSOR */
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
#define VDF_API
Definition: api.h:25
struct _cl_event * event
Definition: glcorearb.h:2961
GLuint id
Definition: glcorearb.h:655
#define VDF_API_TYPE
Definition: api.h:26
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74