有没有办法以编程方式启动/停止仪器分析?我只需要以可靠的方式分析我的 OS X 代码的特定部分,但我似乎无法找到任何有关 Instruments 的文档,这些文档可能会告诉我如何做到这一点。对于 CHUD/Shark,有一个编程 API 和一个命令行工具来支持这一点,但我在任何地方都看不到 Instruments 的等效项?FWIW 我发现 2009 年左右的一些旧论坛帖子哀叹该领域缺乏 Instruments 功能,但最近没有。
我想使用statprof.py来分析 PyPy 中的代码。不幸的是,它似乎不起作用,它指向的行号已关闭。有谁知道如何使其工作或知道替代方案?
我有两种算法来完成相同的任务。要检查它们的性能,我应该检查什么:cpu time 或 wall time?我认为是 CPU 时间,对吧?
我正在对我的代码进行并行处理。要检查我的并行性能,我应该检查什么:cpu time 或 wall time?我认为是墙壁时间,对吧?
假设我已经使用多线程完成了理想的并行性。我认为 1 个线程的 cpu 时间将与 8 个线程相同,而 1 个线程的壁挂时间将比 8 个线程长 8 倍。这样对吗?
还有任何简单的方法来检查这些时间吗?
我正在尝试使用 nvprof 在我的 CUDA 程序中获得一些基准时间,但不幸的是它似乎没有分析任何 API 调用或内核。我寻找了一个简单的初学者示例以确保我做对了,并在 Nvidia 开发者博客上找到了一个:
https://devblogs.nvidia.com/parallelforall/how-optimize-data-transfers-cuda-cc/
代码:
int main()
{
const unsigned int N = 1048576;
const unsigned int bytes = N * sizeof(int);
int *h_a = (int*)malloc(bytes);
int *d_a;
cudaMalloc((int**)&d_a, bytes);
memset(h_a, 0, bytes);
cudaMemcpy(d_a, h_a, bytes, cudaMemcpyHostToDevice);
cudaMemcpy(h_a, d_a, bytes, cudaMemcpyDeviceToHost);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
命令行:
-bash-4.2$ nvcc profile.cu -o profile_test
-bash-4.2$ nvprof ./profile_test
Run Code Online (Sandbox Code Playgroud)
所以我逐字逐行复制它,并运行相同的命令行参数。不幸的是,我的结果是一样的:
-bash-4.2$ nvprof ./profile_test
==85454== NVPROF is profiling process 85454, command: ./profile_test
==85454== Profiling application: ./profile_test
==85454== Profiling result:
No kernels …Run Code Online (Sandbox Code Playgroud) import time
import logging
from functools import reduce
logging.basicConfig(filename='debug.log', level=logging.DEBUG)
def read_large_file(file_object):
"""Uses a generator to read a large file lazily"""
while True:
data = file_object.readline()
if not data:
break
yield data
def process_file_1(file_path):
"""Opens a large file and reads it in"""
try:
with open(file_path) as fp:
for line in read_large_file(fp):
logging.debug(line)
pass
except(IOError, OSError):
print('Error Opening or Processing file')
def process_file_2(file_path):
"""Opens a large file and reads it in"""
try:
with open(path) as file_handler:
while True:
logging.debug(next(file_handler))
except (IOError, …Run Code Online (Sandbox Code Playgroud) 我在运行我的游戏时查看了分析器,我可以在那里看到一大堆东西 - 但不是我的脚本的内存使用情况。问题是,我的游戏的总内存分配是 223 MB,但纹理只有这个的 112 个和我看到的一两个 MB,除此之外。我不知道我的其他 100 MB 内存去了哪里,我想稍微优化一下我的脚本。旁注:我使用 Visual Studio 进行编码。也许我应该去那里看看?
我正在尝试了解 Cython,并且我正在关注官方文档。最近,我尝试做“ http://docs.cython.org/en/latest/src/tutorial/profiling_tutorial.html ”中提供的教程。这里的目标是分析 Cython 文档。这就是我遇到麻烦的地方。
要配置文件的函数是(文件“calc_pi.py”):
def recip_square(i):
return 1./i**2
def approx_pi(n=10000000):
val = 0.
for k in range(1,n+1):
val += recip_square(k)
return (6 * val)**.5Run Code Online (Sandbox Code Playgroud)
分析函数的脚本(如文档中所述)是:
import pstats, cProfile
import calc_pi
cProfile.runctx("calc_pi.approx_pi()", globals(), locals(), "Profile.prof")
s = pstats.Stats("Profile.prof")
s.strip_dirs().sort_stats("time").print_stats()Run Code Online (Sandbox Code Playgroud)
我不确定要运行哪个命令,以及这是否会引发错误。但是,在他们的页面中,没有提到 thisi。所以我只是运行“python3 profile.py”,这会产生以下错误:
AttributeError: 模块“cProfile”没有属性“runctx”
我知道我的错误可能是愚蠢和最小的,但是在谷歌搜索并检查 stackoverflow 一段时间后,我找不到答案。
感谢您的帮助。
当执行遇到某个方法时,有没有办法暂停 Java 进程的所有业务逻辑执行线程?
如果无法通过外部配置,是否有任何方法调用嵌入到应用程序中以达到预期的结果?
当我kill -SIGINT pid使用 Golang 服务时,我会正常关闭调用profile.Stop,但在调用它之前,我收到了以下消息:profile: caught interrupt, stopping profiles
我什至无法调用 profile.Stop 因为它触发得更快,但是 grpc 侦听和 couchbase 连接关闭正常工作。
无论如何我可以覆盖这个故障的配置文件停止吗?
有没有办法查看当我启动一个新 shell 时每件事花费了多少时间(例如一些正在运行的函数等)。
是否可以?
我唯一能想到的帮助就是做这样的事情:
~
? time fish -i -c exit
________________________________________________________
Executed in 142.29 millis fish external
usr time 76.19 millis 68.00 micros 76.12 millis
sys time 61.52 millis 469.00 micros 61.05 millis
Run Code Online (Sandbox Code Playgroud)
然后试图取出东西并再次测量......虽然并不理想。