linesman.middleware

class linesman.middleware.ProfilingMiddleware(app, profiler_path='/__profiler__', backend='linesman.backends.sqlite:SqliteBackend', chart_packages='', **kwargs)[source]

This wraps calls to the WSGI application with cProfile, storing the output and providing useful graphs for the user to view.

app:
WSGI application
profiler_path:
Path relative to the root to look up. For example, if your script is mounted at the context /someapp and this variable is set to /__profiler__, /someapp/__profiler__ will match.
backend:
This should be a full module path, with the function or class name specified after the trailing :. This function or class should return an implementation of Backend.
chart_packages:
Space separated list of packages to be charted in the pie graph.
delete_profile(req)[source]

If the current path info refers to a specific session_uuid, this session will be removed. Otherwise, if it refers to all, then all tracked session info will be removed.

req:
webob.Request containing the environment information from the request itself.

Returns a WSGI application.

get_template(template)[source]

Uses mako templating lookups to retrieve the template file. If the file is ever changed underneath, this function will automatically retrieve and recompile the new version.

template:
Filename of the template, relative to the linesman/templates directory.
list_profiles(req)[source]

Displays all available profiles in list format.

req:
webob.Request containing the environment information from the request itself.

Returns a WSGI application.

media(req)[source]

Serves up static files relative to MEDIA_DIR.

req:
webob.Request containing the environment information from the request itself.

Returns a WSGI application.

render_graph(req)[source]

Used to display rendered graphs; if the graph that the user is trying to access does not exist–and the session_uuid exists in our history–it will be rendered.

This also creates a thumbnail image, since some of these graphs can grow to be extremely large.

req:
webob.Request containing the environment information from the request itself.

Returns a WSGI application.

show_profile(req)[source]

Displays specific profile information for the session_uuid specified in the path.

req:
webob.Request containing the environment information from the request itself.

Returns a WSGI application.

linesman.middleware.make_linesman_middleware(app, **kwargs)[source]

Helper function for wrapping an application with linesman. This can be used when manually wrapping middleware, although its also possible to simply call ProfilingMiddleware directly.

linesman.middleware.prepare_graph(source_graph, cutoff_time, break_cycles=False)[source]

Prepares a graph for display. This includes:

  • removing subgraphs based on a cutoff time
  • breaking cycles

Returns a tuple of (new_graph, removed_edges)

linesman.middleware.profiler_filter_app_factory(app, conf, **kwargs)[source]

Creates a single paste filter. Full documentation can be found in the paste docs.

linesman.middleware.profiler_filter_factory(conf, **kwargs)[source]

Factory for creating paste filters. Full documentation can be found in the paste docs.

linesman.middleware.time_per_field(full_graph, root_nodes, fields)[source]

This function generates the fields used by the pie graph jQuery code on the session profile page. This process is clever about calculating total time, so that packages and subpackages don’t overlap.

Additionally, if I were to track linesman.middleware, and in that package an external package is called, say re, the time spent in re would be added to the total time in package linesman.middleware, unless re is one of the fields that are being tracked.

full_graph:
For best results, this should be an untouched copy of the original graph. The reasoning is because, if certain packages are pruned, the graph result could be completely varied and inaccurate.
root_nodes:
The list of starting point for this graph.
fields:
The list of packages to be tracked.

Returns a dictionary where the keys are the same as the fields, plus an extra field called Other that contains packages that were not tracked. The values for each field is the total time spent in that package.

Warning

This will run into issues where separate packages rely on the same core set of functions. I.e., of PackageA and PackageB both rely on re, there’s no defined outcome. Whichever one is parsed first will include the time spent in re.

Previous topic

linesman.backends

Next topic

0.3.1 (2013-05-02)

This Page