首页 > 编程语言 >scalene python cpu&gpu 性能分析工具

scalene python cpu&gpu 性能分析工具

时间:2024-03-07 14:57:39浏览次数:35  
标签:profile default python CPU -- scalene gpu cpu

scalene 使用一个python cpu&gpu 性能分析工具,同时也支持内存的分析,同时还提供了基于ai的智能优化推荐

包含的一些特性

  • cli 支持多种输出格式
  • 包含了一个web-gui
  • 基于ai 的智能提示

参考使用

  • 安装
pip install scalene
  • 包含的cli
usage: scalene [-h] [--version] [--column-width COLUMN_WIDTH] [--outfile OUTFILE] [--html] [--json] [--cli] [--stacks] [--web] [--no-browser] [--viewer] [--reduced-profile]
               [--profile-interval PROFILE_INTERVAL] [--cpu] [--cpu-only] [--gpu] [--memory] [--profile-all] [--profile-only PROFILE_ONLY] [--profile-exclude PROFILE_EXCLUDE]
               [--use-virtual-time] [--cpu-percent-threshold CPU_PERCENT_THRESHOLD] [--cpu-sampling-rate CPU_SAMPLING_RATE] [--allocation-sampling-window ALLOCATION_SAMPLING_WINDOW]
               [--malloc-threshold MALLOC_THRESHOLD] [--program-path PROGRAM_PATH] [--memory-leak-detector] [--on | --off]
 
Scalene: a high-precision CPU and memory profiler, version 1.5.36 (2024.03.04)
https://github.com/plasma-umass/scalene
 
command-line:
  % scalene [options] your_program.py [--- --your_program_args] 
or
  % python3 -m scalene [options] your_program.py [--- --your_program_args] 
 
in Jupyter, line mode:
  %scrun [options] statement
 
in Jupyter, cell mode:
  %%scalene [options]
   your code here
   
options:
  -h, --help            show this help message and exit
  --version             prints the version number for this release of Scalene and exits
  --column-width COLUMN_WIDTH
                        Column width for profile output (default: 132)
  --outfile OUTFILE     file to hold profiler output (default: stdout)
  --html                output as HTML (default: web)
  --json                output as JSON (default: web)
  --cli                 forces use of the command-line
  --stacks              collect stack traces
  --web                 opens a web tab to view the profile (saved as 'profile.html')
  --no-browser          doesn't open a web tab; just saves the profile ('profile.html')
  --viewer              opens the Scalene web UI.
  --reduced-profile     generate a reduced profile, with non-zero lines only (default: False)
  --profile-interval PROFILE_INTERVAL
                        output profiles every so many seconds (default: inf)
  --cpu                 profile CPU time (default:  True )
  --cpu-only            profile CPU time (deprecated: use --cpu )
  --gpu                 profile GPU time and memory (default: False )
  --memory              profile memory (default: True )
  --profile-all         profile all executed code, not just the target program (default: only the target program)
  --profile-only PROFILE_ONLY
                        profile only code in filenames that contain the given strings, separated by commas (default: no restrictions)
  --profile-exclude PROFILE_EXCLUDE
                        do not profile code in filenames that contain the given strings, separated by commas (default: no restrictions)
  --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)
  --allocation-sampling-window ALLOCATION_SAMPLING_WINDOW
                        Allocation sampling window size, in bytes (default: 10485767 bytes)
  --malloc-threshold MALLOC_THRESHOLD
                        only report profiles with at least this many allocations (default: 100)
  --program-path PROGRAM_PATH
                        The directory containing the code to profile (default: the path to the profiled program)
  --memory-leak-detector
                        EXPERIMENTAL: report likely memory leaks (default: True)
  --on                  start with profiling on (default)
  --off                 start with profiling off
 
When running Scalene in the background, you can suspend/resume profiling
for the process ID that Scalene reports. For example:
 
   % python3 -m scalene  yourprogram.py &
 Scalene now profiling process 12345
   to suspend profiling: python3 -m scalene.profile --off --pid 12345
   to resume profiling:  python3 -m scalene.profile --on  --pid 12345
 
(venv) (venv) (base) ➜  dremio-sqlalchemy scalene app.py 
297511 E8:CB:ED:5A:52:41
(venv) (venv) (base) ➜  dremio-sqlalchemy scalene --help
usage: scalene [-h] [--version] [--column-width COLUMN_WIDTH] [--outfile OUTFILE] [--html] [--json] [--cli] [--stacks] [--web] [--no-browser] [--viewer] [--reduced-profile]
               [--profile-interval PROFILE_INTERVAL] [--cpu] [--cpu-only] [--gpu] [--memory] [--profile-all] [--profile-only PROFILE_ONLY] [--profile-exclude PROFILE_EXCLUDE]
               [--use-virtual-time] [--cpu-percent-threshold CPU_PERCENT_THRESHOLD] [--cpu-sampling-rate CPU_SAMPLING_RATE] [--allocation-sampling-window ALLOCATION_SAMPLING_WINDOW]
               [--malloc-threshold MALLOC_THRESHOLD] [--program-path PROGRAM_PATH] [--memory-leak-detector] [--on | --off]
 
Scalene: a high-precision CPU and memory profiler, version 1.5.36 (2024.03.04)
https://github.com/plasma-umass/scalene
 
command-line:
  % scalene [options] your_program.py [--- --your_program_args] 
or
  % python3 -m scalene [options] your_program.py [--- --your_program_args] 
 
in Jupyter, line mode:
  %scrun [options] statement
 
in Jupyter, cell mode:
  %%scalene [options]
   your code here
   
options:
  -h, --help            show this help message and exit
  --version             prints the version number for this release of Scalene and exits
  --column-width COLUMN_WIDTH
                        Column width for profile output (default: 132)
  --outfile OUTFILE     file to hold profiler output (default: stdout)
  --html                output as HTML (default: web)
  --json                output as JSON (default: web)
  --cli                 forces use of the command-line
  --stacks              collect stack traces
  --web                 opens a web tab to view the profile (saved as 'profile.html')
  --no-browser          doesn't open a web tab; just saves the profile ('profile.html')
  --viewer              opens the Scalene web UI.
  --reduced-profile     generate a reduced profile, with non-zero lines only (default: False)
  --profile-interval PROFILE_INTERVAL
                        output profiles every so many seconds (default: inf)
  --cpu                 profile CPU time (default:  True )
  --cpu-only            profile CPU time (deprecated: use --cpu )
  --gpu                 profile GPU time and memory (default: False )
  --memory              profile memory (default: True )
  --profile-all         profile all executed code, not just the target program (default: only the target program)
  --profile-only PROFILE_ONLY
                        profile only code in filenames that contain the given strings, separated by commas (default: no restrictions)
  --profile-exclude PROFILE_EXCLUDE
                        do not profile code in filenames that contain the given strings, separated by commas (default: no restrictions)
  --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)
  --allocation-sampling-window ALLOCATION_SAMPLING_WINDOW
                        Allocation sampling window size, in bytes (default: 10485767 bytes)
  --malloc-threshold MALLOC_THRESHOLD
                        only report profiles with at least this many allocations (default: 100)
  --program-path PROGRAM_PATH
                        The directory containing the code to profile (default: the path to the profiled program)
  --memory-leak-detector
                        EXPERIMENTAL: report likely memory leaks (default: True)
  --on                  start with profiling on (default)
  --off                 start with profiling off
 
When running Scalene in the background, you can suspend/resume profiling
for the process ID that Scalene reports. For example:
 
   % python3 -m scalene  yourprogram.py &
 Scalene now profiling process 12345
   to suspend profiling: python3 -m scalene.profile --off --pid 12345
   to resume profiling:  python3 -m scalene.profile --on  --pid 12345
  • 使用
scalene app.py
  • 效果

说明

scalene 同时还有一个与比较工具的比较,scalene 支持的功能还是很多的,很值得试用下,尤其是ai 开发的场景

参考资料

https://github.com/plasma-umass/scalene

标签:profile,default,python,CPU,--,scalene,gpu,cpu
From: https://www.cnblogs.com/rongfengliang/p/18058513

相关文章

  • memray python 内存profiler 工具简单试用
    memraypython内存profiler工具,功能还是很强大的,以下是一个简单使用参考使用安装pipinstallmemray支持的cliusage:memray[-h][-v][-V]{run,flamegraph,table,live,tree,parse,summary,stats,transform,attach,detach}... Memo......
  • Python中怎么使用Spark的spark.read.format()函数读取MySQL数据库中的数据
    1.准备工作:安装pyspark库(pipinstallpyspark)2.代码:#导入模块frompyspark.sqlimportSparkSession#创建Spark会话对象spark=SparkSession.builder\.appName("ReadMySQL")\.getOrCreate()#或者写成一行spark=SparkSession.builder.appName("ReadMySQL&qu......
  • CentOS7安装python3详细教程
    1.检查CentOS7自带python环境centos一般自带Python2,先使用python-V来查看python版本建议大家在保留python2的基础上安装一个python3,因为python2和python3还是有一些区别的,同时安装python2和python3的环境,以便不时之需或者对比学习。如果想要删除原有的python环境,可以通过下面......
  • 详解Python魔法函数,__init__,__str__,__del__
    1、简介Python作为一门灵活而强大的编程语言,提供了许多特殊的方法,被称为魔法函数(Magicmethods)。这些魔法函数以双下划线开头和结尾,能够让我们自定义类的行为,使得Python更加灵活和易用。本文将详细介绍Python中的魔法函数,帮助读者理解其作用和用法。1.1、什么是魔法函数?魔法函......
  • Python根据坐标半径生成测试点数据
    一、代码#-*-coding:UTF-8-*-importcsvimportrandomimportmathimportdatetimefromfakerimportFaker#定义语言faker_data=Faker(locale='zh_CN')#获取当前时间current_time=datetime.datetime.now()#格式化时间formatted_time=current_time.strft......
  • Python爬虫学习记录1—Python基础知识
    1.type()函数:用于查看变量的数据类型print(type(a),a)2.input()函数:输入内容用户的交互程序如果没有结束,则需要输入内容注意:input接受的所有数据都是字符串,字符串如果想变成其他数据类型则需要转化3.ifPython用缩进代替判断括号缩进:捆绑同一层级别的代码,简称代码块if单分......
  • Python 实现 AES 加密/解密
    AES,高级加密标准(AdvancedEncryptionStandard)。是用来替代DES,目前比较流行的对称加密算法。与上一篇博文提到过的RSA非对称算法不同,对称加密算法也就是加密和解密用相同的密钥#-*-coding:utf-8-*-#!/usr/bin/envpythonimportosimportsyssys.path.append(os.pa......
  • Java开发者的Python快速进修指南:掌握T检验
    前言T检验是一种用于比较两个独立样本均值差异的统计方法。它通过计算T值和P值来判断样本之间是否存在显著性差异。通常情况下,我们会有两组数据,例如一组实验组和一组对照组。T检验的原假设是两组样本的均值相等,备假设是两组样本的均值不相等。T检验会计算一个T值,表示两组样本均......
  • Python开启线程和线程池的方法
    一.最佳线程数的获取:1、通过用户慢慢递增来进行性能压测,观察QPS(即每秒的响应请求数,也即是最大吞吐能力。),响应时间2、根据公式计算:服务器端最佳线程数量=((线程等待时间+线程cpu时间)/线程cpu时间)*cpu数量3、单用户压测,查看CPU的消耗,然后直接乘以百分比,再进行压测,一般这个值......
  • Python中判定列表是否包含某个元素的方法
    大家好,我是彭涛,今天为大家分享Python中判定列表是否包含某个元素的方法,全文4000字,阅读大约10分钟。在Python编程中,判定一个列表是否包含特定元素是一项常见任务。本文将深入研究各种方法,从基本的成员运算符到更高级的函数和库的应用,为大家提供全方位的指南和实用示例。1.成......