NarrowPhaseStats.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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, uint64 inTicks100Pct) const
  12. {
  13. double total_pct = 100.0 * double(mTotalTicks) / double(inTicks100Pct);
  14. double total_pct_excl_children = 100.0 * double(mTotalTicks - mChildTicks) / double(inTicks100Pct);
  15. std::stringstream str;
  16. str << inName << ", " << sSubShapeTypeNames[(int)inType1] << ", " << sSubShapeTypeNames[(int)inType2] << ", " << mNumQueries << ", " << total_pct << ", " << total_pct_excl_children << ", " << total_pct_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 (%%), Total Time Excl Children (%%), Total Time Excl. Children / Query (%%), Hits Reported");
  22. uint64 total_ticks = 0;
  23. for (EShapeSubType t1 : sAllSubShapeTypes)
  24. for (EShapeSubType t2 : sAllSubShapeTypes)
  25. {
  26. const NarrowPhaseStat &collide_stat = sCollideShape[(int)t1][(int)t2];
  27. total_ticks += collide_stat.mTotalTicks - collide_stat.mChildTicks;
  28. const NarrowPhaseStat &cast_stat = sCastShape[(int)t1][(int)t2];
  29. total_ticks += cast_stat.mTotalTicks - cast_stat.mChildTicks;
  30. }
  31. for (EShapeSubType t1 : sAllSubShapeTypes)
  32. for (EShapeSubType t2 : sAllSubShapeTypes)
  33. {
  34. const NarrowPhaseStat &stat = sCollideShape[(int)t1][(int)t2];
  35. if (stat.mNumQueries > 0)
  36. stat.ReportStats("CollideShape", t1, t2, total_ticks);
  37. }
  38. for (EShapeSubType t1 : sAllSubShapeTypes)
  39. for (EShapeSubType t2 : sAllSubShapeTypes)
  40. {
  41. const NarrowPhaseStat &stat = sCastShape[(int)t1][(int)t2];
  42. if (stat.mNumQueries > 0)
  43. stat.ReportStats("CastShape", t1, t2, total_ticks);
  44. }
  45. }
  46. JPH_NAMESPACE_END
  47. #endif // JPH_TRACK_NARROWPHASE_STATS