Export to GitHub

yappi - apiyappi.wiki


Reference Manual


Latest version: 0.62

yappi.start(builtins=False)

Remarks:

Starts profiling all threads in the current interpreter instance. This function can be called from any thread at any time. Note that yappi is per-interpreter resource, you cannot run more than one instance per-interpreter. A relevant exception will be raised if you do so. Resumes previous profiling data if stop() is called previously.(Note: you can clear the profiling stats via clear_stats() between a successfull start()/stop() sequence.)

Params:

Function will take an optional parameter named builtins. As the name suggests, this means we also want to profile builtin functions used by standart Python modules. It is False by default.


yappi.stop()

Remarks:

Stops the currently running yappi instance. Same profiling session might be resumed later by calling start().(unless clear_stats() is called in that period.)


yappi.enum_func_stats(fenum)

Remarks:

Enumerates the profile stats one by one. The parameter fenum should be a callable Python function with one parameter, say stat_entry which will be invoked for every profiled function. The parameter is a Python tuple instance consisting all of the information related to function profiling: ('function_name', 'callcount', 'ttot', 'tsub')

Example:

```

def foo(): pass
import yappi yappi.start() foo() def estat(stat_entry): print stat_entry yappi.enum_stats(estat) ('tt.py.foo:4', 1, 0.40625, 0.28125) ```


yappi.enum_thread_stats()

Remarks:

Enumerates the profile stats one by one. The parameter fenum should be a callable Python function with one parameter, say stat_entry which will be invoked for every profiled function. The parameter is a Python tuple instance consisting all of the information related to thread profiling: ('thread_name', 'thread_id', 'last_func', 'ttot', 'sched_count')

Example:

```

def foo(): pass
import yappi yappi.start() foo() def estat(stat_entry): print stat_entry yappi.thread_stats(estat) ('_MainThread', 6232, 'tt.py.foo:4', 0.421875, 1) ```


yappi.get_func_stats(sorttype, sortorder, limit)

Remarks:

Returns a YStats object. YStats object will have two list attributes(func_stats, thread_stats). These attributes are a list of YStatDict instances. A YStatDict object for functions contains: ('name', 'ncall', 'ttot', 'tsub', 'tavg') and for thread profiling information, it contains: ('name', 'id', 'last_func', 'ttot', 'sched_count') See the example below for the usage.

Params:

  • sorttype: There are several columns in the statistics results. This parameter controls on which column you want the sort to be based on. The valid values for this parameter are:
    • yappi.SORTTYPE_NAME : Sorts the results according to function name.
    • yappi.SORTTYPE_NCALL : Sorts the results according to their call count.(default)
    • yappi.SORTTYPE_TTOTAL: Sorts the results according to their total time.
    • yappi.SORTTYPE_TSUB : Sorts the results according to their total subtime. Subtime means the total spent time in the function minus the total time spent in the other functions called from this function.
    • yappi.SORTTYPE_TAVG : Sorts the results according to their total average time.
  • sortorder: The order type of the column. Valid values for this parameter are:
    • yappi.SORTORDER_ASC : Sorts the values in ascending order.
    • yappi.SORTORDER_DESC : Sorts the values in descending order.(default)
  • limit: There may be too many functions profiled and user is not interested in many of them. So, limit gives the user the ability to limit the result set returned by the function. With this and above param, a user easily retrieves the top running functions that he/she is interested in.
  • yappi.SHOW_ALL : Returns all of the statistic results.(default)
  • thread_stats_on: If set to true, returns thread profiling information. True by default.

Example:

```

import yappi def foo(): pass yappi.start() foo() stats = yappi.get_stats() print "%s called %s times." % (stats.func_stats[0].name, stats.func_stats[0].ncall) print "thread %s(id=%d) scheduled %d times." % (stats.thread_stats[0].name, stats.thread_stats[0].id, stats.thread_stats[0].sched_count) yappi.py.init:50 called 4 times. thread _MainThread(id=7428) scheduled 1 times. ```


yappi.print_stats(out=sys.stdout, sorttype, sortorder, limit)

Params:

  • out: The fd which the output is redirected to. Default is sys.stdout.

Remarks: Remaining parameters are same as the get_stats() function.


yappi.clear_stats()

Remarks:

Clears the profiler results. Note that the only way to really delete the statistics is this function. The results stays with the application unless application(all threads including the main thread) exists or clear_stats() is called. yappi does not mess with the result set upon stop() or start(). It is user's responsibility to clear the statistics whenever appropiate. This also means without calling clear_stats(), you can resume previously stopped profile informations via start().


yappi.is_running()

Remarks:

Returns a boolean indicating whether yappi is running or not.


yappi.clock_type()

Remarks:

Returns the underlying clock type and its resolution yappi uses to retrieve per-thread CPU time.

``` ''' On windows: '''

import yappi print yappi.clock_type() {'clock_type': 'getthreadtimes', 'resolution': '100ns'} ```