1313
1414namespace hydrochrono ::hydro {
1515
16+ /* *
17+ * @brief Profiling statistics for HydroSystem components.
18+ *
19+ * Tracks cumulative execution time and call counts for each component type.
20+ */
21+ struct HydroSystemProfileStats {
22+ double hydrostatics_seconds = 0.0 ;
23+ double radiation_seconds = 0.0 ;
24+ double excitation_seconds = 0.0 ;
25+ int hydrostatics_calls = 0 ;
26+ int radiation_calls = 0 ;
27+ int excitation_calls = 0 ;
28+
29+ // / Reset all counters to zero
30+ void Reset () {
31+ hydrostatics_seconds = radiation_seconds = excitation_seconds = 0.0 ;
32+ hydrostatics_calls = radiation_calls = excitation_calls = 0 ;
33+ }
34+ };
35+
1636/* *
1737 * @brief HydroSystem: orchestrates force components to compute total forces.
1838 *
@@ -36,12 +56,13 @@ class HydroSystem {
3656 *
3757 * Computes force contributions from all components for the given
3858 * system state and time, accumulating them into a single result.
59+ * Also updates profiling statistics for each component type.
3960 *
4061 * @param state Current system state (positions, velocities for all bodies)
4162 * @param time Current simulation time
4263 * @return BodyForces Total forces (one GeneralizedForce per body, 6 DOF each)
4364 */
44- BodyForces Evaluate (const SystemState& state, double time) const ;
65+ BodyForces Evaluate (const SystemState& state, double time);
4566
4667 /* *
4768 * @brief Get number of bodies in the system.
@@ -50,9 +71,43 @@ class HydroSystem {
5071 */
5172 int num_bodies () const { return num_bodies_; }
5273
74+ /* *
75+ * @brief Get profiling statistics.
76+ *
77+ * Returns cumulative timing and call counts for each component type.
78+ *
79+ * @return HydroSystemProfileStats Profiling statistics
80+ */
81+ HydroSystemProfileStats GetProfileStats () const { return profile_stats_; }
82+
83+ /* *
84+ * @brief Reset profiling statistics.
85+ *
86+ * Clears all timing and call counts.
87+ */
88+ void ResetProfileStats () { profile_stats_.Reset (); }
89+
90+ /* *
91+ * @brief Enable or disable profiling.
92+ *
93+ * When disabled (default), Evaluate() skips timing measurements.
94+ *
95+ * @param enabled True to enable profiling, false to disable
96+ */
97+ void SetProfilingEnabled (bool enabled) { profiling_enabled_ = enabled; }
98+
99+ /* *
100+ * @brief Check if profiling is enabled.
101+ *
102+ * @return True if profiling is enabled
103+ */
104+ bool ProfilingEnabled () const { return profiling_enabled_; }
105+
53106private:
54107 int num_bodies_;
55108 std::vector<std::unique_ptr<IHydroForceComponent>> components_;
109+ mutable HydroSystemProfileStats profile_stats_;
110+ bool profiling_enabled_ = false ; // /< Profiling disabled by default
56111};
57112
58113} // namespace hydrochrono::hydro
0 commit comments