python工具——Scalene


Scalene 是一個 Python 的高性能 CPU內存分析器

用於Python腳本的CPU和內存分析器,能夠正確處理多線程代碼,還能區分Python代碼和本機代碼的運行時間

在linux或Mac OS X上運行

特點:

  快速、開銷少、精確

  還能對高耗能的代碼行進行標注

安裝

pip install scalene

eg:

  test.py

import time
def test():
    i=3;
    while i>0:
        print("test")
        time.sleep(10)
        i=i-1
test()

會生成一個文本形式的報告,顯示出每一行代碼的CPU和內存的使用情況

 

查看全部配置

python -m scalene --help

usage: scalene [-h] [--outfile OUTFILE] [--html] [--reduced-profile]
[--profile-interval PROFILE_INTERVAL] [--cpu-only]
[--profile-all] [--use-virtual-time]
[--cpu-percent-threshold CPU_PERCENT_THRESHOLD]
[--cpu-sampling-rate CPU_SAMPLING_RATE]
[--malloc-threshold MALLOC_THRESHOLD]

Scalene: a high-precision CPU and memory profiler.
https://github.com/emeryberger/scalene
% scalene yourprogram.py

optional arguments:
-h, --help show this help message and exit
--outfile OUTFILE file to hold profiler output (default: stdout)
--html output as HTML (default: text)
--reduced-profile generate a reduced profile, with non-zero lines only (default: False).
--profile-interval PROFILE_INTERVAL
output profiles every so many seconds.
--cpu-only only profile CPU time (default: profile CPU, memory, and copying)
--profile-all profile all executed code, not just the target program (default: only the target program)
--use-virtual-time measure only CPU time, not time spent in I/O or blocking (default: False)
--cpu-percent-threshold CPU_PERCENT_THRESHOLD
only report profiles with at least this percent of CPU time (default: 1%)
--cpu-sampling-rate CPU_SAMPLING_RATE
CPU sampling rate (default: every 0.01s)
--malloc-threshold MALLOC_THRESHOLD
only report profiles with at least this many allocations (default: 100)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM