import sys
from narval.Engine import *
from tools import Cyclops

def trace(frame,event,arg):
    if event == 'call' and frame.f_lineno == 49 and frame.f_code.co_name == '__init__' :
        i = 0
        f = frame
        while f and i<20:
            i = i+1
            co = f.f_code
            print co.co_filename,co.co_name,co.co_firstlineno
            f = f.f_back
    return trace


#sys.settrace(trace)

z=Cyclops.CycleFinder()
n = Narval()
n.scheduleEvent(('quit',),when=90)

z.register(n)
z.run(start,(n,1))
if z.find_cycles(purge_dead_roots=1):
    print 'Cycles found'
    z.show_stats()
    z.show_sccs()
    z.show_arcs()
else:
    print 'No cycles!!!'

