简体   繁体   English

在分析Cython代码时,`stringsource`是什么?

[英]When profiling Cython Code, what is `stringsource`?

I have a heavy Cython function that I'm trying to optimize. 我正在尝试优化一个沉重的Cython函数。 I am profiling per this following tutorial http://docs.cython.org/src/tutorial/profiling_tutorial.html . 我正在按照以下教程http://docs.cython.org/src/tutorial/profiling_tutorial.html进行配置 My profile output looks like this: 我的个人资料输出如下所示:

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    7.521    7.521   18.945   18.945 routing_cython_core.pyx:674(resolve_flat_regions_for_drainage)
  6189250    4.964    0.000    4.964    0.000 stringsource:323(__cinit__)
  6189250    2.978    0.000    7.942    0.000 stringsource:618(memoryview_cwrapper)
  6009849    0.868    0.000    0.868    0.000 routing_cython_core.pyx:630(_is_flat)
  6189250    0.838    0.000    0.838    0.000 stringsource:345(__dealloc__)
  6189250    0.527    0.000    0.527    0.000 stringsource:624(memoryview_check)
  1804189    0.507    0.000    0.683    0.000 routing_cython_core.pyx:646(_is_sink)
    15141    0.378    0.000    0.378    0.000 {_gdal_array.BandRasterIONumPy}
        3    0.066    0.022    0.086    0.029 /home/rpsharp/local/workspace/invest-natcap.invest-3/invest_natcap/raster_utils.py:235(new_raster_from_base_uri)
    11763    0.048    0.000    0.395    0.000 /usr/lib/python2.7/dist-packages/osgeo/gdal_array.py:189(BandReadAsArray)

Specifically I'm interested in lines 2 and 3 that call stringsource:323(__cinit__) and stringsource:618(memoryview_cwrapper) many times. 具体来说,我对第2行和第3行感兴趣,这些行stringsource:323(__cinit__)调用stringsource:323(__cinit__)stringsource:618(memoryview_cwrapper) A Google turned up references to memory views which I'm not using in that function, although I am statically typing numpy arrays. Google出现了对我在该函数中未使用的内存视图的引用,尽管我是静态键入numpy数组。 Any idea what these calls are and if I can avoid/optimize them? 您知道这些调用是什么,是否可以避免/优化它们?

Okay, turns out I did have a memory view. 好的,原来我确实有一个内存视图。 I was calling an inline function that passed a statically typed numpy array to a memory view, thus invoking all those extra calls to stringsource. 我正在调用一个内联函数,该函数将静态类型的numpy数组传递给内存视图,从而调用了所有额外的对stringsource的调用。 Replacing the memoryview type in the function call with a numpy type fixed this. 将函数调用中的memoryview类型替换为numpy类型可解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM