Last active
August 29, 2015 14:06
-
-
Save boris-42/e5ffbe1077e4f8f3da09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #To add new points in code you have 4 ways: | |
| from osprofiler import profiler | |
| def some_func(): | |
| profiler.start("point_name", {"any_key": "with_any_value"}) | |
| # your code | |
| profiler.stop({"any_info_about_point": "in_this_dict"}) | |
| @profiler.trace("point_name", | |
| info={"any_info_about_point": "in_this_dict"}, | |
| hide_args=False) | |
| def some_func2(*args, **kwargs): | |
| # If you need to hide args in profile info, put hide_args=True | |
| pass | |
| def some_func3(): | |
| with profiler.Trace("point_name", | |
| info={"any_key": "with_any_value"}): | |
| # some code here | |
| @profiler.trace_cls("point_name", info={}, hide_args=False, | |
| trace_private=False) | |
| class TracedClass(object): | |
| def traced_method(self): | |
| pass | |
| def _traced_only_if_trace_private_true(self): | |
| pass | |
| #If OSprofiler will be optional, you will be able to use only first option: start()/stop(). | |
| #Which will produce huge mess in code. Take a look at next sample | |
| #SAMPlE 1 | |
| def some_func(*args, **kwargs): | |
| #code | |
| def some_func(*args, **kwargs): | |
| try: | |
| if profiler: | |
| profiler.start("point_name", {"function": {"name": "some_func", args ....}}) | |
| #code | |
| finally: | |
| if profiler: | |
| profiler.stop() | |
| #instead of | |
| @profile.trace("point_name") | |
| def some_func(): | |
| #code | |
| # SAMPLE 2: | |
| #as well you won't be able to use with.Profiler() | |
| with Profiler("point", info): | |
| # some code | |
| # with profiler optional | |
| try: | |
| if profiler: | |
| profiler.start() | |
| # your code | |
| finally: | |
| if profiler: | |
| profiler.stop() | |
| # SAMPLE 3 (profiling all methods from class) | |
| @profiler.trace_cls("point_name") | |
| class A: | |
| pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment