#!/usr/bin/env python
#This file is part of Tryton.  The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
import sys
import os
DIR = os.path.abspath(os.path.normpath(os.path.join(__file__,
    '..', '..', 'trytond')))
if os.path.isdir(DIR):
    sys.path.insert(0, os.path.dirname(DIR))
import trytond
if '--profile' in sys.argv:
    import profile
    import pstats
    import tempfile
    sys.argv.remove('--profile')

    statfile = tempfile.mkstemp(".stat","trytond-")[1]
    profile.run('trytond.server.TrytonServer().run()', statfile)
    s = pstats.Stats(statfile)
    s.sort_stats('cumulative').print_stats()
    s.sort_stats('call').print_stats()
    s.sort_stats('time').print_stats()
    s.sort_stats('time')
    s.print_callers()
    s.print_callees()

    os.remove(statfile)

else:
    trytond.server.TrytonServer().run()
