相关疑难解决方法(0)

如何分析在Linux上运行的C++代码?

我有一个在Linux上运行的C++应用程序,我正在优化它.如何确定代码的哪些区域运行缓慢?

c++ unix profiling

1732
推荐指数
12
解决办法
49万
查看次数

在KCacheGrind中使用cProfile结果

我正在使用cProfile来配置我的Python程序.根据这个说法,我的印象是KCacheGrind可以解析并显示cProfile的输出.

但是,当我去导入文件时,KCacheGrind只会在状态栏中显示"未知文件格式"错误,并且不显示任何内容.

在我的性能分析统计数据与KCacheGrind兼容之前,我需要做些什么特别的事情吗?

...
if profile:
    import cProfile

    profileFileName = 'Profiles/pythonray_' + time.strftime('%Y%m%d_%H%M%S') + '.profile'

    profile = cProfile.Profile()
    profile.run('pilImage = camera.render(scene, samplePattern)')

    profile.dump_stats(profileFileName)
    profile.print_stats()
else:            
    pilImage = camera.render(scene, samplePattern)
...
Run Code Online (Sandbox Code Playgroud)

包版本

  • KCacheGrind 4.3.1
  • Python 2.6.2

python profiling kcachegrind cprofile

53
推荐指数
5
解决办法
2万
查看次数

一个装饰器,用于分析方法调用并记录分析结果

我想创建一个装饰器,用于描述方法并记录结果.如何才能做到这一点?

python profiling decorator

20
推荐指数
3
解决办法
1万
查看次数

如何查找python中代码的统计信息和执行时间

我正在研究 python,并遇到了一些查找代码的统计信息和执行时间的概念

假设我有以下代码

from time import gmtime, strftime
import timeit


def calculation():
     a = 2
     b = 3
     res = a + b
     return  res

if 'name' == 'main' :
    exec_time = timeit.timeit(calculation)
    print exec_time
Run Code Online (Sandbox Code Playgroud)

结果:

0.2561519145965576
Run Code Online (Sandbox Code Playgroud)

所以从上面的代码我可以找到代码的执行时间,但是如何在python中找到代码的统计信息呢?

最后我的意图如下

  1. 如何在python中查找代码的统计信息
  2. 如何在python中找到整个代码的执行时间
  3. 代码统计实际上意味着什么?

编辑后的代码:

例如我的文件中有上面的代码test.py

现在我已经使用下面的命令运行了上面的文件

python -m cProfile test.py
Run Code Online (Sandbox Code Playgroud)

结果 :

sh-4.2$ python -m cProfile test.py
         4 function calls in 0.001 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.001    0.001    0.001    0.001 test.py:1(<module>)
        1 …
Run Code Online (Sandbox Code Playgroud)

python statistics execution-time

6
推荐指数
1
解决办法
4191
查看次数

VisualVM等效于Python

我想知道是否有类似Java的VisualVM的Python.我需要的功能是对正在运行的Python解释器进行实时分析.

一点背景:我最近对代码库的更改大大减慢了它的速度.我想知道我的代码在做什么而不必重新开始计算.另一种方法是停止解释器并重新启动它-m cProfile,从而减少一天的CPU时间.

任何建议都非常感谢.

python profiling visualvm

5
推荐指数
1
解决办法
1218
查看次数