[vtk-developers] new widget to spy on your vtk objects

pat marion pat.marion at kitware.com
Tue Feb 15 12:59:11 EST 2011


I'd definitely be in favor of adding this widget to VTK master, but I'll
leave that decision to the VTK community and ARB.

The code is mostly self contained in a pair of qt model/view classes, but
also requires modifications to vtkObjectBase.cxx and vtkDebugLeaks{cxx,h}
here:


https://github.com/patmarion/VTK/commit/8b3b7203323859efb493cd76d1d2ca68e22eff62

The main change is that I added hooks to vtkObjectBase.cxx:

diff --git a/Common/vtkObjectBase.cxx b/Common/vtkObjectBase.cxx
index 9ea53ec..c75687b 100644
--- a/Common/vtkObjectBase.cxx
+++ b/Common/vtkObjectBase.cxx
@@ -75,10 +75,17 @@ vtkObjectBase::vtkObjectBase()
 {
   this->ReferenceCount = 1;
   this->WeakPointers = 0;
+#ifdef VTK_DEBUG_LEAKS
+  vtkDebugLeaks::ObjectConstructed(this);
+#endif
 }

 vtkObjectBase::~vtkObjectBase()
 {
+#ifdef VTK_DEBUG_LEAKS
+  vtkDebugLeaks::ObjectDestroyed(this);
+#endif
+
   // warn user if reference counting is on and the object is being
referenced
   // by another object
   if ( this->ReferenceCount > 0)


The vtkDebugLeaks::ObjectConstructed/ObjectDestroyed function calls are
essentially no-ops unless the widget is activate.  And of course when
VTK_DEBUG_LEAKS is OFF then the whole thing is skipped.  So I think it is
pretty unobtrusive the way I have it, but perhaps someone will suggest an
alternate implementation.

Note- class counts and reference counts are not updated instantaneously,
they are updated when the application event loop cycles.  For people
interested in pinpointing instantaneous changes, gdb or other debugger is
still the best option.

Pat


On Tue, Feb 15, 2011 at 11:28 AM, Aashish Chaudhary <
aashish.chaudhary at kitware.com> wrote:

> This is fantastic. Really helpful visual debug tool.
>
> Any plans to move it into VTK master?
>
> Thanks Pat.
>
> On Sat, Feb 12, 2011 at 11:04 AM, David Cole <david.cole at kitware.com>wrote:
>
>> Absolutely brilliant. Nice work, Pat!
>>
>>
>> On Sat, Feb 12, 2011 at 10:57 AM, Utkarsh Ayachit <
>> utkarsh.ayachit at kitware.com> wrote:
>>
>>> That;s fantastic. Can't wait to try it out next time I am trying to
>>> debug a leak-hell.
>>>
>>> Utkarsh
>>>
>>> On Fri, Feb 11, 2011 at 5:49 PM, pat marion <pat.marion at kitware.com>
>>> wrote:
>>> > Hello vtk and qt heads,
>>> >
>>> > I've got a new widget to share with you.  Actually it's not new.  I
>>> wrote
>>> > the code several months ago when I was stuck in an airport.  I finally
>>> got
>>> > around to rebasing it and pushing to github.  I added a wiki page with
>>> > screenshots:
>>> >
>>> >     http://vtk.org/Wiki/DebugLeaksView
>>> >
>>> > Motivation: VTK_DEBUG_LEAKS is a great help, any developer worth his or
>>> her
>>> > salt has it enabled... (right?)  But it only reports leaky objects at
>>> > program shutdown.  I wanted to spy on my vtk objects at runtime.  So I
>>> > created this debug leaks widget.  Please see the wiki page for a
>>> > demonstration!
>>> >
>>> > Pat
>>> >
>>> > _______________________________________________
>>> > Powered by www.kitware.com
>>> >
>>> > Visit other Kitware open-source projects at
>>> > http://www.kitware.com/opensource/opensource.html
>>> >
>>> > Follow this link to subscribe/unsubscribe:
>>> > http://www.vtk.org/mailman/listinfo/vtk-developers
>>> >
>>> >
>>> >
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtk-developers
>>>
>>>
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtk-developers
>>
>>
>>
>
>
> --
> | Aashish Chaudhary
> | R&D Engineer
> | Kitware Inc.
> | www.kitware.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20110215/4ffccda9/attachment.html>


More information about the vtk-developers mailing list