Home

Awesome

Python Instrumentation

An extensible framework that instruments (modifies the bytecode at loading time) python programs at runtime, with the purpose of capturing method invocation events (start, finish, errors ...) and notifying custom listeners.

Hence this framework uses dynamic instrumentation of python achieved by monkey patching.

This framework runs as a wrapper for any python script/program.

Key Features:

Run :

$ python ${ABSOLUTE_PATH_FOR_FRAMEWORK}/driver.py YOUR_ACTUALL_SCRIPT.py CMD_ARGS_TO_YOUR_SCRIPT

Note: The above run command expects both the framework & your script being in the PYTHONPATH of your env. This can be set like any other env variable as $ export PYTHONPATH=$PYTHONPATH:{PATHS_TO_BE_ADDED}

Details

Adding hooks to functions/methods:

For adding hook to any method/function, please add the module & function/Class.Method to constants/hooks.py under relevant sections. The methods/functions present in sys, io, os etc internal & by default loaded modules shall go in BUILTIN_CALLABLES_TO_HOOK & all the rest shall go into USER_CALLABLES_TO_HOOK.

Custom Callbacks:

The framework calls the default callbacks defined in utils/callbacks.py . You can update/extend the functionality of these callbacks. The name of callbacks are self explanatory:

Current Support:

Test & Demo:

Latency:

Latency introduced by this framework per API hook is ~ 0.53 ms. <br> This means for each hooked method/function, the above latency is introduced to the execution of the said method/function. <br> This can be calculated from the above outputs by subtracting the time taken by each API with & without the framework. <br>

References: