← Back to team overview

kicad-developers team mailing list archive

Re: [Patch] Log traces for tool dispatch

 

Here is an updated patch. A recent commit made it not apply as cleanly as
it should (and this also adds a trace for the search minus the shift).

-Ian

On Wed, Jul 31, 2019 at 6:20 PM Wayne Stambaugh <stambaughw@xxxxxxxxx>
wrote:

> I think the tracing might be useful given some of the tool dispatch
> issues we've been having lately.  Is there any reason not to merge this
> patch?
>
> Cheers,
>
> Wayne
>
> On 7/27/19 12:33 PM, Ian McInerney wrote:
> > Whoops, ignore the patch in the last email since it appears a log
> > statement slipped out of an if null check. Here is an updated patch.
> >
> > -Ian
> >
> > On Sat, Jul 27, 2019 at 5:30 PM Ian McInerney <Ian.S.McInerney@xxxxxxxx
> > <mailto:Ian.S.McInerney@xxxxxxxx>> wrote:
> >
> >     As I was working on the cvpcb actions, I needed to trace the tool
> >     dispatch routes through the stack, so I went ahead and added a new
> >     debug trace for monitoring the dispatch events. It is contained in
> >     the attached patch. I don't guarantee that I found every location
> >     they pass through, but I got the major ones.
> >
> >     Hopefully this is useful enough to merge into master.
> >
> >     -Ian
> >
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~kicad-developers
> > Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> > Unsubscribe : https://launchpad.net/~kicad-developers
> > More help   : https://help.launchpad.net/ListHelp
> >
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
>
From 3383f0c2370f3c6ae664031c6d7df689ea3f7b87 Mon Sep 17 00:00:00 2001
From: Ian McInerney <Ian.S.McInerney@xxxxxxxx>
Date: Sat, 27 Jul 2019 16:11:41 +0200
Subject: [PATCH] Add log trace for tool handling

---
 common/eda_base_frame.cpp       |  2 +-
 common/tool/action_manager.cpp  | 22 ++++++++++++++++++++--
 common/tool/action_menu.cpp     | 14 +++++++++-----
 common/tool/tool_dispatcher.cpp |  6 ++++++
 common/tool/tool_manager.cpp    | 32 ++++++++++++++++++++++++++++++--
 common/trace_helpers.cpp        |  1 +
 include/trace_helpers.h         |  7 +++++++
 7 files changed, 74 insertions(+), 10 deletions(-)

diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp
index c39bfcf68..19ec945ef 100644
--- a/common/eda_base_frame.cpp
+++ b/common/eda_base_frame.cpp
@@ -307,7 +307,7 @@ bool EDA_BASE_FRAME::doAutoSave()
 
 void EDA_BASE_FRAME::OnCharHook( wxKeyEvent& event )
 {
-    wxLogTrace( kicadTraceKeyEvent, "EDA_DRAW_FRAME::OnCharHook %s", dump( event ) );
+    wxLogTrace( kicadTraceKeyEvent, "EDA_BASE_FRAME::OnCharHook %s", dump( event ) );
     // Key events can be filtered here.
     // Currently no filtering is made.
     event.Skip();
diff --git a/common/tool/action_manager.cpp b/common/tool/action_manager.cpp
index 1b681032d..9e26c49b4 100644
--- a/common/tool/action_manager.cpp
+++ b/common/tool/action_manager.cpp
@@ -23,10 +23,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
+#include <eda_draw_frame.h>
 #include <tool/action_manager.h>
-#include <tool/tool_manager.h>
 #include <tool/tool_action.h>
-#include <eda_draw_frame.h>
+#include <tool/tool_manager.h>
+#include <trace_helpers.h>
 
 #include <hotkeys_basic.h>
 #include <cctype>
@@ -92,6 +93,9 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey ) const
     if( key >= 'a' && key <= 'z' )
         key = std::toupper( key );
 
+    wxLogTrace( kicadTraceToolStack, "ACTION_MANAGER::RunHotKey Key: %s",
+            KeyNameFromKeyCode( aHotKey ) );
+
     HOTKEY_LIST::const_iterator it = m_actionHotKeys.find( key | mod );
 
     // If no luck, try without Shift, to handle keys that require it
@@ -100,6 +104,9 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey ) const
     // different combination
     if( it == m_actionHotKeys.end() )
     {
+        wxLogTrace( kicadTraceToolStack,
+                "ACTION_MANAGER::RunHotKey No actions found, searching with key: %s",
+                KeyNameFromKeyCode( key | ( mod & ~MD_SHIFT ) ) );
         it = m_actionHotKeys.find( key | ( mod & ~MD_SHIFT ) );
 
         if( it == m_actionHotKeys.end() )
@@ -141,15 +148,26 @@ bool ACTION_MANAGER::RunHotKey( int aHotKey ) const
 
     if( context )
     {
+        wxLogTrace( kicadTraceToolStack,
+                "ACTION_MANAGER::RunHotKey Running action %s for hotkey %s", context->GetName(),
+                KeyNameFromKeyCode( aHotKey ) );
+
         m_toolMgr->RunAction( *context, true );
         return true;
     }
     else if( global )
     {
+        wxLogTrace( kicadTraceToolStack,
+                "ACTION_MANAGER::RunHotKey Running action: %s for hotkey %s", global->GetName(),
+                KeyNameFromKeyCode( aHotKey ) );
+
         m_toolMgr->RunAction( *global, true );
         return true;
     }
 
+    wxLogTrace( kicadTraceToolStack, "ACTION_MANAGER::RunHotKey No action found for key %s",
+            KeyNameFromKeyCode( aHotKey ) );
+
     return false;
 }
 
diff --git a/common/tool/action_menu.cpp b/common/tool/action_menu.cpp
index c707fb176..6293898ea 100644
--- a/common/tool/action_menu.cpp
+++ b/common/tool/action_menu.cpp
@@ -24,16 +24,17 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
+#include <eda_base_frame.h>
 #include <functional>
+#include <id.h>
+#include <menus_helpers.h>
+#include <tool/action_menu.h>
 #include <tool/actions.h>
 #include <tool/tool_event.h>
-#include <tool/tool_manager.h>
 #include <tool/tool_interactive.h>
-#include <tool/action_menu.h>
+#include <tool/tool_manager.h>
+#include <trace_helpers.h>
 #include <wx/log.h>
-#include <menus_helpers.h>
-#include <eda_base_frame.h>
-#include <id.h>
 
 
 using namespace std::placeholders;
@@ -436,6 +437,9 @@ void ACTION_MENU::OnMenuEvent( wxMenuEvent& aEvent )
     // clients that don't supply a tool will have to check GetSelected() themselves
     if( evt && m_tool )
     {
+
+        wxLogTrace( kicadTraceToolStack, "ACTION_MENU::OnMenuEvent %s", evt->Format() );
+
         TOOL_MANAGER* toolMgr = m_tool->GetManager();
 
         if( g_last_menu_highlighted_id == aEvent.GetId() && !m_isContextMenu )
diff --git a/common/tool/tool_dispatcher.cpp b/common/tool/tool_dispatcher.cpp
index 5e9711ff9..8b4259944 100644
--- a/common/tool/tool_dispatcher.cpp
+++ b/common/tool/tool_dispatcher.cpp
@@ -463,6 +463,8 @@ void TOOL_DISPATCHER::DispatchWxEvent( wxEvent& aEvent )
 
     if( evt )
     {
+        wxLogTrace( kicadTraceToolStack, "TOOL_DISPATCHER::DispatchWxEvent %s", evt->Format() );
+
         handled = m_toolMgr->ProcessEvent( *evt );
 
         // ESC is the special key for canceling tools, and is therefore seen as handled
@@ -499,7 +501,11 @@ void TOOL_DISPATCHER::DispatchWxCommand( wxCommandEvent& aEvent )
     OPT<TOOL_EVENT> evt = m_actions->TranslateLegacyId( aEvent.GetId() );
 
     if( evt )
+    {
+        wxLogTrace( kicadTraceToolStack, "TOOL_DISPATCHER::DispatchWxCommand %s", evt->Format() );
+
         m_toolMgr->ProcessEvent( *evt );
+    }
     else
         aEvent.Skip();
 }
diff --git a/common/tool/tool_manager.cpp b/common/tool/tool_manager.cpp
index 250985c75..71870b267 100644
--- a/common/tool/tool_manager.cpp
+++ b/common/tool/tool_manager.cpp
@@ -24,10 +24,11 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  */
 
-#include <map>
-#include <stack>
 #include <algorithm>
 #include <core/optional.h>
+#include <map>
+#include <stack>
+#include <trace_helpers.h>
 
 #include <wx/event.h>
 #include <wx/clipbrd.h>
@@ -528,6 +529,8 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent )
 {
     bool handled = false;
 
+    wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::dispatchInternal %s", aEvent.Format() );
+
     // iterate over active tool stack
     for( auto it = m_activeTools.begin(); it != m_activeTools.end(); ++it )
     {
@@ -555,6 +558,10 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent )
 
                 if( st->cofunc )
                 {
+                    wxLogTrace( kicadTraceToolStack,
+                            "TOOL_MANAGER::dispatchInternal Waking tool %s for event: %s",
+                            st->theTool->GetName(), aEvent.Format() );
+
                     setActiveState( st );
                     bool end = !st->cofunc->Resume();
 
@@ -565,6 +572,10 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent )
                 // If the tool did not request the event be passed to other tools, we're done
                 if( !st->wakeupEvent.PassEvent() )
                 {
+                    wxLogTrace( kicadTraceToolStack,
+                            "TOOL_MANAGER::dispatchInternal %s stopped passing event: %s",
+                            st->theTool->GetName(), aEvent.Format() );
+
                     handled = true;
                     break;
                 }
@@ -604,6 +615,10 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent )
                     // as the state changes, the transition table has to be set up again
                     st->transitions.clear();
 
+                    wxLogTrace( kicadTraceToolStack,
+                            "TOOL_MANAGER::dispatchInternal Running tool %s for event: %s",
+                            st->theTool->GetName(), aEvent.Format() );
+
                     // got match? Run the handler.
                     setActiveState( st );
                     st->idle = false;
@@ -626,6 +641,9 @@ bool TOOL_MANAGER::dispatchInternal( const TOOL_EVENT& aEvent )
             break;      // only the first tool gets the event
     }
 
+    wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::dispatchInternal handled: %s  %s",
+            ( handled ? "true" : "false" ), aEvent.Format() );
+
     return handled;
 }
 
@@ -641,6 +659,7 @@ bool TOOL_MANAGER::dispatchHotKey( const TOOL_EVENT& aEvent )
 
 bool TOOL_MANAGER::dispatchActivation( const TOOL_EVENT& aEvent )
 {
+    wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::dispatchActivation %s", aEvent.Format() );
     if( aEvent.IsActivate() )
     {
         wxString cmdStr( *aEvent.GetCommandStr() );
@@ -649,6 +668,10 @@ bool TOOL_MANAGER::dispatchActivation( const TOOL_EVENT& aEvent )
 
         if( tool != m_toolNameIndex.end() )
         {
+            wxLogTrace( kicadTraceToolStack,
+                    "TOOL_MANAGER::dispatchActivation Running tool %s for event: %s",
+                    tool->second->theTool->GetName(), aEvent.Format() );
+
             runTool( tool->second->theTool );
             return true;
         }
@@ -931,6 +954,8 @@ void TOOL_MANAGER::applyViewControls( TOOL_STATE* aState )
 
 bool TOOL_MANAGER::processEvent( const TOOL_EVENT& aEvent )
 {
+    wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::processEvent %s", aEvent.Format() );
+
     if( dispatchHotKey( aEvent ) )
         return true;
 
@@ -949,6 +974,9 @@ bool TOOL_MANAGER::processEvent( const TOOL_EVENT& aEvent )
         processEvent( event );
     }
 
+    wxLogTrace( kicadTraceToolStack, "TOOL_MANAGER::processEvent handled: %s  %s",
+            ( handled ? "true" : "false" ), aEvent.Format() );
+
     return handled;
 }
 
diff --git a/common/trace_helpers.cpp b/common/trace_helpers.cpp
index c7b4c662c..b4cda831b 100644
--- a/common/trace_helpers.cpp
+++ b/common/trace_helpers.cpp
@@ -33,6 +33,7 @@
 const wxChar* const traceFindReplace = wxT( "KICAD_FIND_REPLACE" );
 const wxChar* const kicadTraceCoords = wxT( "KICAD_COORDS" );
 const wxChar* const kicadTraceKeyEvent = wxT( "KICAD_KEY_EVENTS" );
+const wxChar* const kicadTraceToolStack = wxT( "KICAD_TOOL_STACK" );
 const wxChar* const traceSchLibMem = wxT( "KICAD_SCH_LIB_MEM" );
 const wxChar* const traceFindItem = wxT( "KICAD_FIND_ITEM" );
 const wxChar* const traceSchLegacyPlugin = wxT( "KICAD_SCH_LEGACY_PLUGIN" );
diff --git a/include/trace_helpers.h b/include/trace_helpers.h
index d310bf5ee..55caa48a1 100644
--- a/include/trace_helpers.h
+++ b/include/trace_helpers.h
@@ -75,6 +75,13 @@ extern const wxChar* const kicadTraceCoords;
  */
 extern const wxChar* const kicadTraceKeyEvent;
 
+/**
+ * Flag to enable tracing of the tool handling stack.
+ *
+ * Use "KICAD_TOOL_STACK" to enable.
+ */
+extern const wxChar* const kicadTraceToolStack;
+
 /**
  * Flag to enable auto save feature debug tracing.
  *
-- 
2.21.0


Follow ups

References