0

I'm new to cprofile but I'm running it on a python tool written for ArcGIS. It tells me that the most time consuming function is the lambda function in _base.py:

ncalls tottime percall cumtime percall filename:lineno(function)
17875 137.877 0.008 200.404 0.011 _base.py:510(<lambda>)
962732 67.568 0 67.568 0 {built-in method createobject}
7497 44.223 0.006 44.223 0.006 {built-in method distanceto}
8301909/8300996 35.652 0 35.659 0 {getattr}
713 35.235 0.049 35.235 0.049 {built-in method listfields}

_base.py is an arcpy file in this location:

C:\Program Files (x86)\ArcGIS\Desktop10.8\arcpy\arcpy\geoprocessing

How can I dig deeper and find out what's using this lambda function?

The tool is over 5000 lines of code so I can't post it but I'm importing cprofile at the start:

    import cProfile, pstats
    profiler = cProfile.Profile()
    profiler.enable()

then disabling it and dumping the stats just before the end:

    profiler.disable()
    stats.dump_stats(myStatsLocation)

1 Answers1

0

Usually when I need to debug slow code, I use line profiler. Using this you can use decorator on suspect slow functions. From there, you can find out, like with cProfiler, what's being called and how many times.

The cProfiler already pinpoints to line 510 in your _base.py. So probably that lambda calls another function which is slow. Adding the @profile on that function might shed some light on your performance issues.

The Pjot
  • 1,801
  • 1
  • 12
  • 20