NarrowPhaseStats.cpp 1.9 KB

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