Add a TRANSACTION class to experiment with performance metrics in nightlies

This commit is contained in:
Marek Roszko 2025-06-07 11:43:11 -04:00
parent f6c305cea6
commit dea46f7780
4 changed files with 129 additions and 6 deletions

View File

@ -72,9 +72,9 @@ static std::string GetSentryBreadCrumbLevel( BREADCRUMB_LEVEL aLevel )
return ret;
}
void APP_MONITOR::AddBreadcrumb( BREADCRUMB_TYPE aType, const wxString& aMsg, const wxString& aCategory,
BREADCRUMB_LEVEL aLevel )
namespace APP_MONITOR
{
void AddBreadcrumb( BREADCRUMB_TYPE aType, const wxString& aMsg, const wxString& aCategory, BREADCRUMB_LEVEL aLevel )
{
#ifdef KICAD_USE_SENTRY
if( !Pgm().IsSentryOptedIn() )
@ -98,7 +98,7 @@ void APP_MONITOR::AddBreadcrumb( BREADCRUMB_TYPE aType, const wxString& aMsg, co
}
void APP_MONITOR::AddNavigationBreadcrumb( const wxString& aMsg, const wxString& aCategory )
void AddNavigationBreadcrumb( const wxString& aMsg, const wxString& aCategory )
{
#ifdef KICAD_USE_SENTRY
AddBreadcrumb( BREADCRUMB_TYPE::NAVIGATION, aMsg, aCategory, BREADCRUMB_LEVEL::INFO );
@ -106,9 +106,102 @@ void APP_MONITOR::AddNavigationBreadcrumb( const wxString& aMsg, const wxString&
}
void APP_MONITOR::AddTransactionBreadcrumb( const wxString& aMsg, const wxString& aCategory )
void AddTransactionBreadcrumb( const wxString& aMsg, const wxString& aCategory )
{
#ifdef KICAD_USE_SENTRY
AddBreadcrumb( BREADCRUMB_TYPE::TRANSACTION, aMsg, aCategory, BREADCRUMB_LEVEL::INFO );
#endif
}
class TRANSACTION_IMPL
{
public:
TRANSACTION_IMPL( const std::string& aName, const std::string& aOperation )
{
m_ctx = sentry_transaction_context_new( aName.c_str(), aOperation.c_str() );
}
~TRANSACTION_IMPL() {
Finish();
// note m_ctx is handled by sentry
}
void Start()
{
m_tx = sentry_transaction_start( m_ctx, sentry_value_new_null() );
}
void Finish()
{
FinishSpan();
if( m_tx )
{
sentry_transaction_finish( m_tx );
m_tx = nullptr;
}
}
void StartSpan( const std::string& aOperation, const std::string& aDescription )
{
if( m_span )
return;
if( !m_tx )
return;
m_span = sentry_transaction_start_child( m_tx, aOperation.c_str(), aDescription.c_str() );
}
void FinishSpan()
{
if( m_span )
{
sentry_span_finish( m_span );
m_span = nullptr;
}
}
private:
sentry_transaction_context_t* m_ctx;
sentry_transaction_t* m_tx = nullptr;
sentry_span_t* m_span = nullptr;
};
}
TRANSACTION::TRANSACTION( const std::string& aName, const std::string& aOperation )
{
m_impl = new TRANSACTION_IMPL( aName, aOperation );
}
TRANSACTION::~TRANSACTION()
{
delete m_impl;
}
void TRANSACTION::Start()
{
m_impl->Start();
}
void TRANSACTION::StartSpan( const std::string& aOperation, const std::string& aDescription )
{
m_impl->StartSpan( aOperation, aDescription );
}
void TRANSACTION::Finish()
{
m_impl->Finish();
}
void TRANSACTION::FinishSpan()
{
m_impl->FinishSpan();
}

View File

@ -337,7 +337,8 @@ void PGM_BASE::sentryInit()
#ifndef KICAD_SENTRY_DSN
# error "Project configuration error, missing KICAD_SENTRY_DSN"
#endif
// only capture 5% of transactions
sentry_options_set_traces_sample_rate( options, 0.05 );
sentry_options_set_dsn( options, KICAD_SENTRY_DSN );
wxFileName tmp;

View File

@ -24,6 +24,7 @@
#include <future>
#include <vector>
#include <unordered_map>
#include <app_monitor.h>
#include <core/profile.h>
#include <core/kicad_algo.h>
#include <common.h>
@ -739,11 +740,14 @@ void CONNECTION_GRAPH::Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnco
std::function<void( SCH_ITEM* )>* aChangedItemHandler,
PROGRESS_REPORTER* aProgressReporter )
{
APP_MONITOR::TRANSACTION monitorTrans( "CONNECTION_GRAPH::Recalculate", "Recalculate" );
PROF_TIMER recalc_time( "CONNECTION_GRAPH::Recalculate" );
monitorTrans.Start();
if( aUnconditional )
Reset();
monitorTrans.StartSpan( "updateItemConnectivity", "" );
PROF_TIMER update_items( "updateItemConnectivity" );
m_sheetList = aSheetList;
@ -858,20 +862,27 @@ void CONNECTION_GRAPH::Recalculate( const SCH_SHEET_LIST& aSheetList, bool aUnco
for( SCH_ITEM* item : dirty_items )
item->SetConnectivityDirty( false );
monitorTrans.FinishSpan();
if( wxLog::IsAllowedTraceMask( DanglingProfileMask ) )
update_items.Show();
PROF_TIMER build_graph( "buildConnectionGraph" );
monitorTrans.StartSpan( "BuildConnectionGraph", "" );
buildConnectionGraph( aChangedItemHandler, aUnconditional );
if( wxLog::IsAllowedTraceMask( DanglingProfileMask ) )
build_graph.Show();
monitorTrans.FinishSpan();
recalc_time.Stop();
if( wxLog::IsAllowedTraceMask( DanglingProfileMask ) )
recalc_time.Show();
monitorTrans.Finish();
}

View File

@ -51,6 +51,24 @@ namespace APP_MONITOR
DBG
};
class TRANSACTION_IMPL;
class KICOMMON_API TRANSACTION
{
public:
TRANSACTION( const std::string& aName, const std::string& aOperation );
~TRANSACTION();
void Start();
void StartSpan( const std::string& aOperation, const std::string& aDescription );
void FinishSpan();
void Finish();
private:
// We use a IMPL to avoid seeding sentry everywhere
TRANSACTION_IMPL* m_impl;
};
KICOMMON_API void AddBreadcrumb( BREADCRUMB_TYPE aType, const wxString& aMsg, const wxString& aCategory,
BREADCRUMB_LEVEL aLevel = BREADCRUMB_LEVEL::INFO );