@@ -0,0 +1,2264 @@
+# Copyright 2012 James McCauley%0A#%0A# This file is part of POX.%0A#%0A# POX is free software: you can redistribute it and/or modify%0A# it under the terms of the GNU General Public License as published by%0A# the Free Software Foundation, either version 3 of the License, or%0A# (at your option) any later version.%0A#%0A# POX is distributed in the hope that it will be useful,%0A# but WITHOUT ANY WARRANTY; without even the implied warranty of%0A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A# GNU General Public License for more details.%0A#%0A# You should have received a copy of the GNU General Public License%0A# along with POX.  If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A%0A%22%22%22%0AThis is an extremely primitive start at some debugging.%0AAt the moment, it is really just for recoco (maybe it belongs in there?).%0A%22%22%22%0A%0Afrom pox.core import core%0Alog = core.getLogger()%0Aimport time%0Aimport traceback%0A%0A_frames = %5B%5D%0A%0Adef _tf (frame, event, arg):%0A  if _frames is None: return _tf%0A  #print %22 %22 * len(_frames) + event%0A  if event == 'call':%0A    _frames.append(frame)%0A    return _tf%0A  elif event == 'line':%0A    return _tf%0A  elif event == 'exception':%0A    #_frames.pop()%0A    return _tf%0A  elif event == 'return':%0A    _frames.pop()%0A  elif event == 'c_call':%0A    print %22c_call%22%0A    _frames.append((frame,arg))%0A  elif event == 'c_exception':%0A    _frames.pop()%0A  elif event == 'c_return':%0A    _frames.pop()%0A%0A%0Adef _trace_thread_proc ():%0A  last = None%0A  last_time = None%0A  warned = None%0A  while True:%0A    try:%0A      time.sleep(1)%0A      c = len(_frames)%0A      if c == 0: continue%0A      f = _frames%5B-1%5D%0A      f = %22 / %22.join(%5Bs.strip() for s in%0A                      traceback.format_stack(f,1)%5B0%5D.strip().split(%22%5Cn%22)%5D)%0A      if f != last:%0A        if warned != last:%0A          log.warning(%22recoco running again%22)%0A        warned = None%0A        last = f%0A        last_time = time.time()%0A      elif f != warned:%0A        if time.time() - last_time %3E 3:%0A          warned = f%0A          log.warning(f)%0A%0A      #from pox.core import core%0A      #core.f = f%0A%0A    except:%0A      pass%0A%0A%0A%0Adef launch ():%0A  def f ():%0A    import sys%0A    sys.settrace(_tf)%0A  core.callLater(f)%0A%0A  import threading%0A  _trace_thread = threading.Thread(target=_trace_thread_proc)%0A  _trace_thread.daemon = True%0A  _trace_thread.start()%0A

Add recoco_spy