NarrowPhaseStats.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #include <Jolt/Jolt.h>
  4. #include <Jolt/Physics/Collision/NarrowPhaseStats.h>
  5. #ifdef JPH_TRACK_NARROWPHASE_STATS
  6. JPH_NAMESPACE_BEGIN
  7. NarrowPhaseStat NarrowPhaseStat::sCollideShape[NumSubShapeTypes][NumSubShapeTypes];
  8. NarrowPhaseStat NarrowPhaseStat::sCastShape[NumSubShapeTypes][NumSubShapeTypes];
  9. thread_local TrackNarrowPhaseStat *TrackNarrowPhaseStat::sRoot = nullptr;
  10. void NarrowPhaseStat::ReportStats(const char *inName, EShapeSubType inType1, EShapeSubType inType2) const
  11. {
  12. uint64 ticks_per_sec = GetProcessorTicksPerSecond();
  13. double total_time = 1000.0 * double(mTotalTicks) / double(ticks_per_sec);
  14. double total_time_excl_children = 1000.0 * double(mTotalTicks - mChildTicks) / double(ticks_per_sec);
  15. stringstream str;
  16. str << inName << ", " << sSubShapeTypeNames[(int)inType1] << ", " << sSubShapeTypeNames[(int)inType2] << ", " << mNumQueries << ", " << total_time << ", " << total_time_excl_children << ", " << total_time_excl_children / mNumQueries << ", " << mHitsReported;
  17. Trace(str.str().c_str());
  18. }
  19. void NarrowPhaseStat::sReportStats()
  20. {
  21. Trace("Query Type, Shape Type 1, Shape Type 2, Num Queries, Total Time (ms), Total Time Excl Children (ms), Total Time Excl. Children / Query (ms), Hits Reported");
  22. for (EShapeSubType t1 : sAllSubShapeTypes)
  23. for (EShapeSubType t2 : sAllSubShapeTypes)
  24. {
  25. const NarrowPhaseStat &stat = sCollideShape[(int)t1][(int)t2];
  26. if (stat.mNumQueries > 0)
  27. stat.ReportStats("CollideShape", t1, t2);
  28. }
  29. for (EShapeSubType t1 : sAllSubShapeTypes)
  30. for (EShapeSubType t2 : sAllSubShapeTypes)
  31. {
  32. const NarrowPhaseStat &stat = sCastShape[(int)t1][(int)t2];
  33. if (stat.mNumQueries > 0)
  34. stat.ReportStats("CastShape", t1, t2);
  35. }
  36. }
  37. JPH_NAMESPACE_END
  38. #endif // JPH_TRACK_NARROWPHASE_STATS