Add Lock support for Tracy#24
Conversation
Contains: - Added support for Locks in the TracyTestClient. - Updates to CcpMutex - First draft of tests for low-level Tracy lock functions. - First draft of tests for tests on CcpMutex/CcpAutoMutex classes.
Review of classes TracyTestClient and test/CcpTelemetry
This tests the vanilla behavior of the raw underlying TracyCLockXXX() functions.
Following tests removed: - RawTracyLockCAnnounceAndTerminate - RawTracyUncontendedLock
This is needed because the CcpMutex objects may have been created long before Tracy on-demand telemetry session started.
…tclient # Conflicts: # tests/TracyTestClient.cpp # tests/TracyTestClient.h
Make use of types from the tracy header files: - tracy::ServerQueryString - tracy::ServerQuerySourceLocation - tracy::QueueType::StringData - tracy::QueueType::SingleStringData - tracy::QueueType::LockAnnounce - tracy::QueueType::LockTerminate - tracy::QueueType::LockWait - tracy::QueueType::LockObtain - tracy::QueueType::LockRelease - tracy::QueueType::LockName - tracy::QueueType::SourceLocation
| LeaveCriticalSection( &m_mutex ); | ||
| #if CCP_TELEMETRY_ENABLED | ||
| if ( CcpTelemetryIsConnected() && m_tracyLockContext ) | ||
| EnsureTracyLockState(); |
There was a problem hiding this comment.
Why does this need to ensure the lock state?
There was a problem hiding this comment.
Will change this to a regular ctx + LockTracking + connectivity check
| { | ||
| // Telemetry disconnected (or lock tracking disabled); drop the stale | ||
| // context quickly so that the next connect produces a fresh announce/name. | ||
| m_tracyLockContext = nullptr; |
There was a problem hiding this comment.
Isn't this leaking the old context? Also, what about the scenario where someone temporarily stops the integration and then restarts without creation a new profiler session - won't that now show wrong information for the lock?
There was a problem hiding this comment.
Changed the way this (now renamed) function works.
No longer resetting the context if it was previously set but connection has been dropped.
| // so that a future reconnect will produce a fresh, valid context. | ||
| // After this returns, all other Tracy calls in Acquire/Release can rely on a | ||
| // single, fast null-check of m_tracyLockContext. | ||
| void EnsureTracyLockState() |
There was a problem hiding this comment.
This is a good opportunity for cleaning up the usage of Tracy as part of the name whenever possibly as opposed to adding it in more places. 🙂
There was a problem hiding this comment.
Changed to EnsureTelemetryLockAnnounced()
The file will now only reference Tracy as part of:
- m_tracyLockContext
- TracyCLockXXX() functions
| private: | ||
| #if CCP_TELEMETRY_ENABLED | ||
| // See the Windows variant above for documentation. | ||
| void EnsureTracyLockState() |
There was a problem hiding this comment.
Why does the helper function need to be duplicated per platform? Can't that be avoided?
There was a problem hiding this comment.
Will tackle in the CcpMutex.h -> .h + .cpp refactor
| EXPECT_EQ( 2, m_tracyClient.GetZoneEndCount() ); | ||
| } | ||
|
|
||
| TEST_F( CcpTelemetryTest, RawTracyLockCounters ) |
There was a problem hiding this comment.
This is a strange test to have. The TracyTestClient is implicitly tested through a test case that covers our actual lock usage. And Tracy's own functionality is nothing that we should be testing.
There was a problem hiding this comment.
Test removed
| } | ||
|
|
||
| // A locks, B waits, A unlocks, B locks, B unlocks. | ||
| TEST_F( CcpTelemetryTest, RawTracyLockOneWaitingThread ) |
There was a problem hiding this comment.
Same as above, there is no value in this test.
There was a problem hiding this comment.
Test removed
| } | ||
|
|
||
| // A locks, B waits, C waits, A unlocks, B and C lock/unlock in turn. | ||
| TEST_F( CcpTelemetryTest, RawTracyLockMultipleWaitingThreads ) |
There was a problem hiding this comment.
And another test that doesn't add value.
There was a problem hiding this comment.
Test removed
| #define CCPMUTEX_H | ||
|
|
||
| #include "CcpTelemetry.h" | ||
| #include <string> |
There was a problem hiding this comment.
This include can be avoided by moving the implementation into a .cpp file. Which then also resolves the other issue that we observed during initial testing, e.g. that some compilers inline this header completely, defeating the purpose of this code living in a shared library.
There was a problem hiding this comment.
This refactoring is in the pipeline...
There is currently no support for multiple Telemetry sessions at the same time.
- Renamed function to EnsureTelemetryLockAnnounced() - No longer resetting the context - Change conditional logic in Acquire/Release
- RawTracyLockCounters - RawTracyLockOneWaitingThread - RawTracyLockMultipleWaitingThreads
Change includes: