Skip to content

Commit eed6191

Browse files
committed
#2302: perfData: Add doxygen comments
1 parent c0bea90 commit eed6191

File tree

1 file changed

+91
-2
lines changed

1 file changed

+91
-2
lines changed

src/vt/metrics/perf_data.h

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,36 +66,125 @@ namespace vt { namespace metrics {
6666
/**
6767
* \struct PerfData perf_data.h vt/metrics/perf_data.h
6868
*
69-
* \brief Tracks perf metrics per task
69+
* \brief Tracks performance metrics per task
7070
*
71+
* The PerfData component is responsible for initializing, tracking, and retrieving
72+
* performance metrics for specific tasks using Linux performance counters.
7173
*/
7274
struct PerfData: runtime::component::Component<PerfData>
7375
{
7476
public:
77+
/**
78+
* \brief Constructor for PerfData
79+
*
80+
* Initializes performance counters based on the \c VT_EVENTS environment variable,
81+
* which is a comma seperated list of events available in the events header
82+
* (example_events.h by default). For example: \c VT_EVENTS="cache-misses,instructions".
83+
* If \c VT_EVENTS isn't set, will default to measuring instructions.
84+
* Ensures only valid events are configured.
85+
*/
7586
PerfData();
87+
88+
/**
89+
* \brief Destructor for PerfData
90+
*
91+
* Cleans up resources, closing file descriptors associated with performance
92+
* counters.
93+
*/
7694
~PerfData();
7795

96+
/**
97+
* \brief Start performance measurement for a task
98+
*
99+
* Resets and enables the performance counters associated with the tracked events.
100+
*/
78101
void startTaskMeasurement();
102+
103+
/**
104+
* \brief Stop performance measurement for a task
105+
*
106+
* Disables the performance counters associated with the tracked events.
107+
*/
79108
void stopTaskMeasurement();
109+
110+
/**
111+
* \brief Get the measurements collected during the task execution
112+
*
113+
* Reads and retrieves the counter values for all tracked events.
114+
*
115+
* \return A map of event names to their corresponding measurement values.
116+
*
117+
* \throws vtAbort if there is a mismatch in data or an error during reading.
118+
*/
80119
std::unordered_map<std::string, uint64_t> getTaskMeasurements();
81120

121+
/**
122+
* \brief Retrieve the current event map
123+
*
124+
* Returns the mapping of event names to their type and configuration values.
125+
*
126+
* \return A map of event names to pairs of event type and configuration values.
127+
*/
82128
std::unordered_map<std::string, std::pair<uint64_t,uint64_t>> getEventMap() const;
129+
130+
/**
131+
* \brief Component startup method
132+
*/
83133
void startup() override;
134+
135+
/**
136+
* \brief Get the component name
137+
*
138+
* \return The name of the component as a string.
139+
*/
84140
std::string name() override;
85141

142+
/**
143+
* \brief Serialize the PerfData object
144+
*/
86145
template <typename SerializerT>
87-
void PerfData::serialize(SerializerT& s) {
146+
void serialize(SerializerT& s) {
88147
s | event_map_
89148
| event_names_
90149
| event_fds_;
91150
}
92151

93152
private:
153+
/**
154+
* \brief Map of event names to event type and configuration
155+
*/
94156
std::unordered_map<std::string, std::pair<uint64_t,uint64_t>> event_map_;
157+
158+
/**
159+
* \brief List of event names being tracked
160+
*/
95161
std::vector<std::string> event_names_;
162+
163+
/**
164+
* \brief List of file descriptors associated with performance counters
165+
*/
96166
std::vector<int> event_fds_;
97167

168+
/**
169+
* \brief Cleanup resources before aborting
170+
*
171+
* Closes any open file descriptors and clears internal data structures.
172+
*/
98173
void cleanupBeforeAbort();
174+
175+
/**
176+
* \brief Open a performance counter event
177+
*
178+
* Wrapper around the syscall to open a performance counter.
179+
*
180+
* \param[in] hw_event The performance event attributes.
181+
* \param[in] pid The process ID to measure (-1 for calling process).
182+
* \param[in] cpu The CPU to measure (-1 for any CPU).
183+
* \param[in] group_fd Group file descriptor for event grouping.
184+
* \param[in] flags Additional flags for the syscall.
185+
*
186+
* \return The file descriptor for the event, or -1 on failure.
187+
*/
99188
static long perfEventOpen(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags);
100189
};
101190

0 commit comments

Comments
 (0)