長時間実行される python スクリプトのプロファイルを作成しようとしています。このスクリプトは、 gdal モジュールを使用して、ラスター GIS データ セットに対していくつかの空間分析を行います。スクリプトは現在 3 つのファイルを使用します。メイン スクリプトは と呼ばれるラスター ピクセルをループ処理しfind_pixel_pairs.py
、単純なキャッシュは にlrucache.py
あり、いくつかのその他のクラスは にありutils.py
ます。中程度のサイズのデータセットでコードをプロファイリングしました。 pstats
戻り値:
p.sort_stats('cumulative').print_stats(20)
Thu May 6 19:16:50 2010 phes.profile
355483738 function calls in 11644.421 CPU seconds
Ordered by: cumulative time
List reduced from 86 to 20 due to restriction <20>
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.008 0.008 11644.421 11644.421 <string>:1(<module>)
1 11064.926 11064.926 11644.413 11644.413 find_pixel_pairs.py:49(phes)
340135349 544.143 0.000 572.481 0.000 utils.py:173(extent_iterator)
8831020 18.492 0.000 18.492 0.000 {range}
231922 3.414 0.000 8.128 0.000 utils.py:152(get_block_in_bands)
142739 1.303 0.000 4.173 0.000 utils.py:97(search_extent_rect)
745181 1.936 0.000 2.500 0.000 find_pixel_pairs.py:40(is_no_data)
285478 1.801 0.000 2.271 0.000 utils.py:98(intify)
231922 1.198 0.000 2.013 0.000 utils.py:116(block_to_pixel_extent)
695766 1.990 0.000 1.990 0.000 lrucache.py:42(get)
1213166 1.265 0.000 1.265 0.000 {min}
1031737 1.034 0.000 1.034 0.000 {isinstance}
142740 0.563 0.000 0.909 0.000 utils.py:122(find_block_extent)
463844 0.611 0.000 0.611 0.000 utils.py:112(block_to_pixel_coord)
745274 0.565 0.000 0.565 0.000 {method 'append' of 'list' objects}
285478 0.346 0.000 0.346 0.000 {max}
285480 0.346 0.000 0.346 0.000 utils.py:109(pixel_coord_to_block_coord)
324 0.002 0.000 0.188 0.001 utils.py:27(__init__)
324 0.016 0.000 0.186 0.001 gdal.py:848(ReadAsArray)
1 0.000 0.000 0.160 0.160 utils.py:50(__init__)
上位 2 つの呼び出しには、メイン ループ (分析全体) が含まれています。残りの呼び出しの合計は、11644 秒のうち 625 未満です。残りの 11,000 秒はどこで費やされますか? それはすべてのメインループ内にありfind_pixel_pairs.py
ますか? もしそうなら、コードのどの行が最も多くの時間を費やしているかを調べることはできますか?