#!/usr/bin/env python

"""
Profile with hotshot module.

Usage: profile [OPTIONS] [ARGUMENTS]
OPTIONS and ARGUMENTS are passed to Gaupol.
"""

import hotshot
import hotshot.stats
import os
import sys

TOOL_DIR = os.path.dirname(os.path.abspath(__file__))
LIB_DIR  = os.path.join(TOOL_DIR, '..', 'lib')
sys.path.insert(0, LIB_DIR)

from gaupol.gtk import main
profile = hotshot.Profile('gaupol.profile')
profile.runcall(main.main, sys.argv)
profile.close()
stats = hotshot.stats.load('gaupol.profile')
stats.sort_stats('time', 'calls')
stats.print_stats('gaupol', .2)
os.remove('gaupol.profile')
