Skip to content

Add Lock support for Tracy#24

Draft
ccp-chargeback wants to merge 16 commits into
carbonengine:mainfrom
ccp-chargeback:tracy_locks_testclient
Draft

Add Lock support for Tracy#24
ccp-chargeback wants to merge 16 commits into
carbonengine:mainfrom
ccp-chargeback:tracy_locks_testclient

Conversation

@ccp-chargeback

Copy link
Copy Markdown
Contributor

Change includes:

  • Adding support for Locks in the TracyTestClient (with help from Claude)
  • Gate access to Locks in Tracy based on telemetry config flag
  • Changing CcpMutex to inform Tracy of Locks
  • Add support of "lazy announce" of locks in Tracy, once telemetry is connected.

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
Comment thread include/CcpMutex.h Outdated
LeaveCriticalSection( &m_mutex );
#if CCP_TELEMETRY_ENABLED
if ( CcpTelemetryIsConnected() && m_tracyLockContext )
EnsureTracyLockState();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this need to ensure the lock state?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change this to a regular ctx + LockTracking + connectivity check

Comment thread include/CcpMutex.h Outdated
{
// Telemetry disconnected (or lock tracking disabled); drop the stale
// context quickly so that the next connect produces a fresh announce/name.
m_tracyLockContext = nullptr;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the way this (now renamed) function works.
No longer resetting the context if it was previously set but connection has been dropped.

Comment thread include/CcpMutex.h Outdated
// 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()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to EnsureTelemetryLockAnnounced()
The file will now only reference Tracy as part of:

  • m_tracyLockContext
  • TracyCLockXXX() functions

Comment thread include/CcpMutex.h Outdated
private:
#if CCP_TELEMETRY_ENABLED
// See the Windows variant above for documentation.
void EnsureTracyLockState()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the helper function need to be duplicated per platform? Can't that be avoided?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will tackle in the CcpMutex.h -> .h + .cpp refactor

Comment thread tests/CcpTelemetry.cpp Outdated
EXPECT_EQ( 2, m_tracyClient.GetZoneEndCount() );
}

TEST_F( CcpTelemetryTest, RawTracyLockCounters )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test removed

Comment thread tests/CcpTelemetry.cpp Outdated
}

// A locks, B waits, A unlocks, B locks, B unlocks.
TEST_F( CcpTelemetryTest, RawTracyLockOneWaitingThread )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, there is no value in this test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test removed

Comment thread tests/CcpTelemetry.cpp Outdated
}

// A locks, B waits, C waits, A unlocks, B and C lock/unlock in turn.
TEST_F( CcpTelemetryTest, RawTracyLockMultipleWaitingThreads )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And another test that doesn't add value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test removed

Comment thread include/CcpMutex.h Outdated
#define CCPMUTEX_H

#include "CcpTelemetry.h"
#include <string>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants