Creates a profile wrapper around a method to time out 
    all the  operations that it runs through.  For more 
    information, look into the hotshot Profile documentation 
    online for the built-in Python package.
    
    :param      sorting     <tuple> ( <key>, .. )
    :param      stripDirs   <bool>
    :param      limit       <int>
    :param      path        <str>
    :param      autoclean   <bool>
    
    :usage      |from projex.decorators import profiler
                |
                |class A:
                |   @profiler() # must be called as a method
                |   def increment(amount, count = 1):
                |       return amount + count
                |
                |a = A()
                |a.increment(10)
                |

def profiler(sorting=('tottime',), stripDirs=True,
             limit=20, path='', autoclean=True):
    """
    Creates a profile wrapper around a method to time out 
    all the  operations that it runs through.  For more 
    information, look into the hotshot Profile documentation 
    online for the built-in Python package.
    
    :param      sorting     <tuple> ( <key>, .. )
    :param      stripDirs   <bool>
    :param      limit       <int>
    :param      path        <str>
    :param      autoclean   <bool>
    
    :usage      |from projex.decorators import profiler
                |
                |class A:
                |   @profiler() # must be called as a method
                |   def increment(amount, count = 1):
                |       return amount + count
                |
                |a = A()
                |a.increment(10)
                |
    """

    def decorated(func):
        """ Wrapper function to handle the profiling options. """
        # create a call to the wrapping
        @wraps(func)
        def wrapped(*args, **kwds):
            """ Inner method for calling the profiler method. """
            # define the profile name
            filename = os.path.join(path, '%s.prof' % func.__name__)

            # create a profiler for the method to run through
            prof = hotshot.Profile(filename)
            results = prof.runcall(func, *args, **kwds)
            prof.close()

            # log the information about it
            stats = hotshot.stats.load(filename)

            if stripDirs:
                stats.strip_dirs()

            # we don't want to know about the arguments for this method
            stats.sort_stats(*sorting)
            stats.print_stats(limit)

            # remove the file if desired
            if autoclean:
                os.remove(filename)

            return results

        return wrapped

    return decorated