score-p / scorep_binding_python

Allows tracing of python code using Score-P

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Import C extension directly

Flamefire opened this issue · comments

TLDR: I would like to replace scorep_bindings = importlib.import_module("scorep.scorep_bindings") by from scorep import scorep_bindings in the instrumenters directly

Currently there is a line scorep_bindings = importlib.import_module("scorep.scorep_bindings") which is the same as import scorep.scorep_bindings as scorep_bindings or from scorep import scorep_bindings. This is then passed to the ctor of the instrumenters and stored in the instance.

I propose to simplify this to a from scorep import scorep_bindings statement at the top of the instrumenter files that need this.

Reasoning:

  • it makes the code easier to read when you can see where this is coming from
  • it may be faster as the instance variable doesn't need to be read on access
  • it solves discussions like #71 (comment) as the module can be used directly
  • for the cTracing I'm creating a class and want to inherit from or instantiate it. With the current approach this is very difficult if possible at all. Just importing it would be very easy

The problem why this currently won't work is due to those lines: https://github.com/Flamefire/scorep_binding_python/blob/f9fbd7d932f945cac2b679fcd24cc8771b40f211/scorep/instrumenter.py#L1-L3 They import the modules unconditionally even when they are not used. In the new approach this would try to load the bindings module even when Score-P is not available.
Solution: Import the instrumenter on demand: https://github.com/Flamefire/scorep_binding_python/blob/15c01ff629f063c2ea17abadc80aa3a53072a0dd/scorep/instrumenter.py#L34-L35. I think this is very clean, reduces overhead and solves the problem

Interesting Idea, but I am not sure if I get all the side effects of this proposal. However, I'd like to try it. Plase open a PR.

Best,

Andreas

Done in #82. Please have a look 👍

Cool. Looks good. What I like most, ist that it is now obvious that the bindings are a global module and not object-related.

But you should fix the Flake8 test 😄 .

Ups, sure. Done