ducky.profiler module¶
This module provides support for profiling the virtual machine (machine profilers) and running programs (code profilers). Wrappers for python’s deterministic profilers, and simple statistical profiler of running code are available for usage thoughout the ducky sources.
cProfile
is the prefered choice of machine profiling backend, with
profile
is used as a backup option.
Beware, each thread needs its own profiler instance. These instances can be acquired from ProfilerStore class which handles saving their data when virtual machine exits.
To simplify the usage of profilers in ducky sources in case when user does not
need profiling, I chose to provide classes with the same API but these classes
does not capture any data. These are called dummy profilers, as opposed to
the real ones. Both kinds mimic API of profile.Profile
- the
real machine profiler is profile.Profile
object.
-
class
ducky.profiler.
DummyCPUCoreProfiler
(core, frequency=17)[source]¶ Bases:
object
Dummy code profiler class. Base class for all code profilers.
Parameters: - core (ducky.cpu.CPUCore) – core this profiler captures data from.
- frequency (int) – sampling frequency, given as an instruction count.
-
class
ducky.profiler.
DummyMachineProfiler
(*args, **kwargs)[source]¶ Bases:
object
Dummy machine profiler. Does absolutely nothing.
-
class
ducky.profiler.
ProfilerStore
[source]¶ Bases:
object
This class manages profiler instances. When in need of a profiler (e.g. in a new thread) get one by calling proper method of ProfilerStore object.
-
get_core_profiler
(core)[source]¶ Create new code profiler.
Return type: DummyCPUCoreProfiler
-
get_machine_profiler
()[source]¶ Create and return new machine profiler.
Returns: new machine profiler.
-
-
class
ducky.profiler.
RealCPUCoreProfiler
(core)[source]¶ Bases:
ducky.profiler.DummyCPUCoreProfiler
Real code profiler. This class actually does collect data.
-
ducky.profiler.
STORE
= <ducky.profiler.ProfilerStore object>¶ Main profiler store