diff --git a/common/advanced_config.cpp b/common/advanced_config.cpp index e1a6cca774..fca3fbda82 100644 --- a/common/advanced_config.cpp +++ b/common/advanced_config.cpp @@ -179,6 +179,8 @@ static const wxChar TraceMasks[] = wxT( "TraceMasks" ); static const wxChar ShowRepairSchematic[] = wxT( "ShowRepairSchematic" ); +static const wxChar ShowEventCounters[] = wxT( "ShowEventCounters" ); + } // namespace KEYS @@ -285,6 +287,7 @@ ADVANCED_CFG::ADVANCED_CFG() m_Skip3DModelFileCache = false; m_Skip3DModelMemoryCache = false; m_HideVersionFromTitle = false; + m_ShowEventCounters = false; loadFromConfigFile(); } @@ -400,6 +403,9 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg ) configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ShowRepairSchematic, &m_ShowRepairSchematic, false ) ); + configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::ShowEventCounters, + &m_ShowEventCounters, false ) ); + // Special case for trace mask setting...we just grab them and set them immediately // Because we even use wxLogTrace inside of advanced config wxString traceMasks = ""; diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index a3495b517c..e7943950a9 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -71,6 +71,8 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin m_parent = aParentWindow; m_MouseCapturedLost = false; + m_PaintEventCounter = std::make_unique( "Draw panel paint events" ); + SetLayoutDirection( wxLayout_LeftToRight ); m_edaFrame = dynamic_cast( m_parent ); @@ -190,6 +192,8 @@ void EDA_DRAW_PANEL_GAL::DoRePaint() if( m_drawing ) return; + ( *m_PaintEventCounter )++; + wxASSERT( m_painter ); m_drawing = true; diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 516a03b2ff..64beed2084 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -27,6 +27,7 @@ */ #include +#include #include #include #include @@ -83,6 +84,8 @@ WX_VIEW_CONTROLS::WX_VIEW_CONTROLS( VIEW* aView, EDA_DRAW_PANEL_GAL* aParentPane { LoadSettings(); + m_MotionEventCounter = std::make_unique( "Mouse motion events" ); + m_parentPanel->Connect( wxEVT_MOTION, wxMouseEventHandler( WX_VIEW_CONTROLS::onMotion ), nullptr, this ); #if wxCHECK_VERSION( 3, 1, 0 ) || defined( USE_OSX_MAGNIFY_EVENT ) @@ -192,6 +195,8 @@ void WX_VIEW_CONTROLS::LoadSettings() void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent ) { + ( *m_MotionEventCounter )++; + bool isAutoPanning = false; int x = aEvent.GetX(); int y = aEvent.GetY(); diff --git a/include/advanced_config.h b/include/advanced_config.h index cd8343ab78..ba8e500a18 100644 --- a/include/advanced_config.h +++ b/include/advanced_config.h @@ -197,6 +197,11 @@ public: bool m_ShowRepairSchematic; + /** + * Shows debugging event counters in various places. + */ + bool m_ShowEventCounters; + private: ADVANCED_CFG(); diff --git a/include/class_draw_panel_gal.h b/include/class_draw_panel_gal.h index ed4c9e9459..b0d30d9e6d 100644 --- a/include/class_draw_panel_gal.h +++ b/include/class_draw_panel_gal.h @@ -41,6 +41,7 @@ class BOARD; class EDA_DRAW_FRAME; class TOOL_DISPATCHER; +class PROF_COUNTER; namespace KIGFX { @@ -233,6 +234,8 @@ public: */ bool m_MouseCapturedLost; + std::unique_ptr m_PaintEventCounter; + protected: virtual void onPaint( wxPaintEvent& WXUNUSED( aEvent ) ); void onSize( wxSizeEvent& aEvent ); diff --git a/include/profile.h b/include/profile.h index 378fb69080..bf6f28c8b4 100644 --- a/include/profile.h +++ b/include/profile.h @@ -31,6 +31,7 @@ #ifndef TPROFILE_H #define TPROFILE_H +#include #include #include #include @@ -217,4 +218,46 @@ private: */ unsigned GetRunningMicroSecs(); + +/** + * A thread-safe event counter + */ +class PROF_COUNTER +{ +public: + PROF_COUNTER( const std::string& aName ) : + m_name( aName ), + m_count( 0 ) + { + } + + unsigned long long Count() const + { + return m_count.load(); + } + + void Reset() + { + m_count.store( 0 ); + } + + unsigned long long operator++( int ) + { + return m_count++; + } + + void Show( std::ostream& aStream = std::cerr ) + { + if( m_name.size() ) + aStream << m_name << ": "; + + aStream << m_count.load(); + aStream << std::endl; + } + +private: + std::string m_name; + std::atomic_ullong m_count; +}; + #endif // TPROFILE_H diff --git a/include/view/wx_view_controls.h b/include/view/wx_view_controls.h index d4c0760762..773258c425 100644 --- a/include/view/wx_view_controls.h +++ b/include/view/wx_view_controls.h @@ -38,6 +38,7 @@ #include class EDA_DRAW_PANEL_GAL; +class PROF_COUNTER; namespace KIGFX { @@ -115,6 +116,8 @@ public: ///< mouse cursor does not move in screen coordinates, but does in world coordinates) static const wxEventType EVT_REFRESH_MOUSE; + std::unique_ptr m_MotionEventCounter; + private: ///< Possible states for WX_VIEW_CONTROLS. enum STATE diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index e983864cd3..dd64ff3b7a 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -102,6 +102,8 @@ #include #include #include +#include +#include #include #include "../scripting/python_scripting.h" @@ -363,6 +365,27 @@ PCB_EDIT_FRAME::PCB_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : // Ensure the controls on the toolbars all are correctly sized UpdateToolbarControlSizes(); } ); + + if( ADVANCED_CFG::GetCfg().m_ShowEventCounters ) + { + m_eventCounterTimer = new wxTimer( this ); + + Bind( wxEVT_TIMER, + [&]( wxTimerEvent& aEvent ) + { + GetCanvas()->m_PaintEventCounter->Show(); + GetCanvas()->m_PaintEventCounter->Reset(); + + KIGFX::WX_VIEW_CONTROLS* vc = + static_cast( GetCanvas()->GetViewControls() ); + vc->m_MotionEventCounter->Show(); + vc->m_MotionEventCounter->Reset(); + + }, + m_eventCounterTimer->GetId() ); + + m_eventCounterTimer->Start( 1000 ); + } } diff --git a/pcbnew/pcb_edit_frame.h b/pcbnew/pcb_edit_frame.h index 96f4bf4d47..d05525ec64 100644 --- a/pcbnew/pcb_edit_frame.h +++ b/pcbnew/pcb_edit_frame.h @@ -785,6 +785,8 @@ private: TOOL_ACTION* m_exportNetlistAction; DIALOG_FIND* m_findDialog; + + wxTimer* m_eventCounterTimer; }; #endif // __PCB_EDIT_FRAME_H__