sawsen11 / jrfonseca

Automatically exported from code.google.com/p/jrfonseca
0 stars 0 forks source link

[gprof2dot] [PATCH] ability to preserve module path #75

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
for example:
----------------------
    22 [label="__init__:15:<module>\n1.57%\n(0.06%)\n1×"];
    27 [label="__init__:2:<module>\n1.20%\n(0.24%)\n1×"];
    27 -> 36 [label="0.51%\n1×"];
    36 [label="__init__:6:<module>\n0.51%\n(0.02%)\n1×"];
    50 [label="__init__:106:<module>\n4.61%\n(0.09%)\n1×"];
    50 -> 301 [label="2.42%\n1×"];
    50 -> 22 [label="1.57%\n1×"];
    98 [label="__init__:1:<module>\n1.93%\n(0.08%)\n1×"];
----------------------
__init__ is where? who?

Of course, generally, to avoid huge graph is good, but we sometimes needs to 
know the path of module, like this:
------------------------------------------------------------------
*** gprof2dot.py~   2012-08-11 08:12:22.188108815 +0900
--- gprof2dot.py    2012-10-12 06:07:14.261211787 +0900
***************
*** 2359,2365 ****

      def get_function_name(self, (filename, line, name)):
          module = os.path.splitext(filename)[0]
!         module = os.path.basename(module)
          return "%s:%d:%s" % (module, line, name)

      def get_function(self, key):
--- 2359,2378 ----

      def get_function_name(self, (filename, line, name)):
          module = os.path.splitext(filename)[0]
!         rdpaths = list(set(map(lambda x: os.path.dirname(x),
!                                filter(lambda x: x is not None,
!                                       [getattr(m, '__file__', None)
!                                        for m in sys.modules.values()]))))
!         for rd in rdpaths:
!             rds = os.path.join(rd, "site-packages")
!             found = False
!             for r in [rds, rd]:
!                 if module.startswith(r):
!                     module = module[len(r)+1:]
!                     found = True
!                     break
!             if found:
!                 break
          return "%s:%d:%s" % (module, line, name)

      def get_function(self, key):
------------------------------------------------------------------

Original issue reported on code.google.com by xwhhspri...@gmail.com on 11 Oct 2012 at 9:09

GoogleCodeExporter commented 9 years ago

Original comment by Jose.R.F...@gmail.com on 8 Apr 2013 at 5:36

GoogleCodeExporter commented 9 years ago

Original comment by Jose.R.F...@gmail.com on 8 Apr 2013 at 5:40

GoogleCodeExporter commented 9 years ago
Yes, this would indeed be very useful.

But I'd prefer a different implementation -- we should not rely on the 
sys.modules (given the data can be seen on a different system), but instead 
simply add enough path elements as to make each path entry unique.

I wonder if you could provide me some sample profile where this issue is 
obvious.

Original comment by Jose.R.F...@gmail.com on 16 May 2013 at 6:21

GoogleCodeExporter commented 9 years ago
Is this enough?
Like Numpy, SciPy, etc., when the modules have heavy tasks within `import',
__init__ will be especially noticeable...

Original comment by xwhhspri...@gmail.com on 17 May 2013 at 5:11

Attachments: