问题标签 [line-profiler]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
536 浏览

python - line_profiler 仅显示少量行

按照 line_profiler 上的文档,我可以很好地分析我的代码,但是当我查看输出时python -m line_profiler script_to_profile.py.lprof,我只看到 27 行代码。我希望看到大约 250,因为这是我添加@profile装饰器的函数的长度。我的输出如下所示:

它在 for 循环的中间被切断。

0 投票
2 回答
1486 浏览

python - 如何在 Python 中对单元测试进行时间分析?

我有一个测试套件和它正在测试的代码。如果我放在from memory_profiler import profile适当文件的顶部,用 装饰我想要配置的函数@profile,并用 以标准方式运行python TestThing.py,我会得到很好的逐行结果。

但是 line_profiler 并没有以这种方式出现在一个包中,我能够用它来分析任何东西的唯一方法是使用kernprof -l -v thing.py. 如果我在单元测试中使用它,则不会运行任何测试(真的不足为奇),也不会生成任何结果。如何以类似于 memory_profiler 的方式对我的测试和它们使用的代码进行时间分析?

0 投票
0 回答
207 浏览

python - 使用 kernprof 进行类似 %lprun 的模块分析

我想在不插入@profile装饰器的情况下使用 kernprof 来分析某些模块。IPython shell 内部%lprun有一个很棒的功能-m module,它允许分析指定模块中的所有行。但是如果我需要从我使用的命令运行一些脚本kernprof。不幸的是,后者似乎没有允许仅使用装饰器进行概要分析的功能。如何将此模块分析功能引入命令行kernprof调用?

0 投票
0 回答
176 浏览

python - line_profiler 跟踪内置函数

我知道使用配置文件或 cprofile 库可以分析给定代码段的详细 CPU 时间,但它不能指定给定函数。而且我知道 line_profiler 可以跟踪某个函数,但它无法深入跟踪到第三方库或调用了内置函数。有没有什么方法可以结合库的结果来跟踪给定的函数和其中的所有子函数?

0 投票
2 回答
568 浏览

python-2.7 - 不能在 jupyter/python2.7.5 中使用 line_profiler

我正在尝试在运行 python 2.7.5 内核的 jupyter notebook 中使用 line magic %lprun。

我试图运行的代码如下:

bal.run 代码有点复杂,但是使用这些参数执行代码将输出以下元组:

但是,如果我尝试使用 %lprun 魔法,我会收到以下错误:

不知道那里发生了什么,但作为一个测试,我尝试运行一个简单的 python 函数,比如 print 和 line_profiler,并且有效。

任何人都知道问题可能是什么?

0 投票
1 回答
6344 浏览

python - Boto3 put_object() is very slow

TL;DR: Trying to put .json files into S3 bucket using Boto3, process is very slow. Looking for ways to speed it up.

This is my first question on SO, so I apologize if I leave out any important details. Essentially I am trying to pull data from Elasticsearch and store it in an S3 bucket using Boto3. I referred to this post to pull multiple pages of ES data using the scroll function of the ES Python client. As I am scrolling, I am processing the data and putting it in the bucket as a [timestamp].json format, using this:

While running this on my machine, I noticed that this process is very slow. Using line profiler, I discovered that this line is consuming over 96% of the time in my entire program:

What modification(s) can I make in order to speed up this process? Keep in mind, I am creating the .json files in my program (each one is ~240 bytes) and streaming them directly to S3 rather than saving them locally and uploading the files. Thanks in advance.

0 投票
1 回答
5348 浏览

python-3.x - 我们如何在运行时为烧瓶 API 分析内存、CPU 负载?

我将 python 3 用于在端口 5000 中运行的烧瓶应用程序。它有一个示例 API。我需要在从 REST 或浏览器访问此 API 时分析内存、CPU 使用情况。

请帮助我寻求更好的解决方案。

0 投票
1 回答
92 浏览

python - Python - 手动包装一个方法(具体来说,我问的是 robert kern 的 line-profiler )

包装函数没问题:如何使用 line_profiler(来自 Robert Kern)?

但是,我似乎无法弄清楚它将相同的技术应用于方法。

假设我尝试在方法上使用相同的技术:

解决此错误的最佳方法是什么?谢谢。

0 投票
2 回答
756 浏览

python - 将线轮廓仪与多处理一起使用

如何分析使用多处理 (multiprocessing.Pool.map) 的 python 模块,以便每个生成的进程也将逐行分析。

目前我使用 line_profiler 进行分析,但它不支持多处理。有没有办法手动完成?或者也许使用其他工具?

0 投票
1 回答
5827 浏览

python - 没有名为“line_profiler”的模块

我正在尝试在 python 中进行线路配置文件和内存配置文件。我在运行代码时通过 from line_profiler import LineProfiler 导入了 line_profiler,我收到错误消息:ModuleNotFoundError: No module named 'line_profiler'

当我尝试使用 pip install 安装它时:

一切都很好,但最后它给出了红色的东西:

C:\Users\asmobari>py -m pip install line_profiler 收集 line_profiler 使用缓存的 https://files.pythonhosted.org/packages/14/fc/ecf4e238bb601ff829068e5a72cd1bd67b0ee0ae379db172eb6a0779c6b6/line_profiler-2.1.2.tar.gz line_profiler) (4.3.0) 要求已经满足:c:\users\asmobari\appdata\local\programs\python\python37\lib\site-packages 中的pickleshare(来自 IPython>=0.13->line_profiler)(0.7.5)已满足要求:c:\users\asmobari\appdata\local\programs\python\python37\lib\site-packages 中的 jedi>=0.10(来自 IPython>=0.13->line_profiler)(0.13.1) 已满足要求: c:\users\asmobari\appdata\local\programs\python\python37\lib\site-packages 中的 pygments(来自 IPython>=0.13->line_profiler)(2.2.0)要求已经满足:colorama;c:\users\asmobari\appdata\local\programs\python\python37\lib\site-packages 中的 sys_platform == "win32" (来自 IPython>=0.13->line_profiler) (0.4.0) 已满足要求:提示-工具包<2.1.0,>=2.0.0 in c:file ='C:\Users\asmobari\AppData\Local\Temp\pip-install-2w13a4ux\line-profiler\setup.py';f=getattr(tokenize, 'open', open)( file );code=f .read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record C:\Users\asmobari\AppData\Local\Temp\pip-record-h8dq1h7x\install-record.txt --single-version-externally-managed --compile: 运行安装运行 build 运行 build_py 创建 build 创建 build\lib.win-amd64-3.7 复制 line_profiler.py -> build\lib.win-amd64-3.7 复制 kernprof.py -> build\lib.win-amd64-3.7 复制 line_profiler_py35.py -> build\lib.win-amd64-3.7 运行 build_ext 跳过“_line_profiler.c”Cython 扩展(最新)构建“_line_profiler”扩展创建 build\temp.win-amd64-3.7 创建 build\temp.win- amd64-3.7\Release C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64\cl。exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\asmobari\AppData\Local\Programs\Python\Python37\include -IC:\Users\asmobari\AppData\Local\Programs\Python\ Python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.15.26726\include" "-IC:\Program Files (x86)\Windows Kits\10\包括\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\ 10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0. 17134.0\cppwinrt" /Tc_line_profiler.c /Fobuild\temp.win-amd64-3.7\Release_line_profiler.obj _line_profiler.c _line_profiler.c(7890): 错误 C2039: 'exc_type': 不是 '_ts' 的成员 c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209): 注意:见 '_ts' 的声明 _line_profiler.c(7891 ): error C2039: 'exc_value': is not a member of '_ts' c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209): 注意:见 '_ts 的声明' _line_profiler.c(7892): error C2039: 'exc_traceback': is not a member of '_ts' c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209): note :请参阅“_ts”声明 _line_profiler.c(7899):错误 C2039:“exc_type”:不是“_ts”c:\users\asmobari\appdata\local\programs\python\python37\include\pystate 的成员。 h(209):注意:参见“_ts”的声明_line_profiler.c(7900): error C2039: 'exc_value': is not a member of '_ts' c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209): 注意:请参阅“_ts”的声明 _line_profiler.c(7901):错误 C2039:“exc_traceback”:不是“_ts”的成员 c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h (209):注意:请参阅“_ts”声明 _line_profiler.c(7902):错误 C2039:“exc_type”:不是“_ts”c:\users\asmobari\appdata\local\programs\python\python37 的成员\include\pystate.h(209): 注意: 见 '_ts' 声明 _line_profiler.c(7903): error C2039: 'exc_value': is not a member of '_ts' c:\users\asmobari\appdata\local \programs\python\python37\include\pystate.h(209):注意:请参阅“_ts”声明 _line_profiler.c(7904):错误 C2039:“exc_traceback”:不是“_ts”的成员 c:\users\asmobari\appdata\local\programs\python\ python37\include\pystate.h(209): 注意: 见 '_ts' 声明 _line_profiler.c(7959): error C2039: 'exc_type': is not a member of '_ts' c:\users\asmobari\appdata\ local\programs\python\python37\include\pystate.h(209):注意:请参阅 '_ts' _line_profiler.c(7960) 的声明:错误 C2039:'exc_value':不是 '_ts' c:\ 的成员users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209):注意:请参阅 '_ts' _line_profiler.c(7961) 的声明:错误 C2039:'exc_traceback':不是'_ts' c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209):注意:请参阅“_ts”声明 _line_profiler.c(7962):错误 C2039:“exc_type”:不是成员'_ts' 的 c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209):注意:请参阅 '_ts' _line_profiler.c(7963) 的声明:错误 C2039:'exc_value ': 不是 '_ts' c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209) 的成员:注意:参见 '_ts' 的声明 _line_profiler.c(7964) : 错误 C2039: 'exc_traceback': 不是 '_ts' c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209) 的成员:注意:见 '_ts' 的声明请参阅“_ts”的声明 _line_profiler.c(7962):错误 C2039:“exc_type”:不是“_ts”的成员 c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h (209):注意:请参阅“_ts”声明 _line_profiler.c(7963):错误 C2039:“exc_value”:不是“_ts”c:\users\asmobari\appdata\local\programs\python\python37 的成员\include\pystate.h(209): 注意: 见 '_ts' 声明 _line_profiler.c(7964): error C2039: 'exc_traceback': is not a member of '_ts' c:\users\asmobari\appdata\local \programs\python\python37\include\pystate.h(209): 注意: 见 '_ts' 的声明请参阅“_ts”的声明 _line_profiler.c(7962):错误 C2039:“exc_type”:不是“_ts”的成员 c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h (209):注意:请参阅“_ts”声明 _line_profiler.c(7963):错误 C2039:“exc_value”:不是“_ts”c:\users\asmobari\appdata\local\programs\python\python37 的成员\include\pystate.h(209): 注意: 见 '_ts' 声明 _line_profiler.c(7964): error C2039: 'exc_traceback': is not a member of '_ts' c:\users\asmobari\appdata\local \programs\python\python37\include\pystate.h(209): 注意: 见 '_ts' 的声明\users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209):注意:请参阅 '_ts' _line_profiler.c(7963) 的声明:错误 C2039:'exc_value':不是成员'_ts' 的 c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209):注意:请参阅 '_ts' _line_profiler.c(7964) 的声明:错误 C2039:'exc_traceback ': 不是 '_ts' 的成员 c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209): 注意:见 '_ts' 的声明\users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209):注意:请参阅 '_ts' _line_profiler.c(7963) 的声明:错误 C2039:'exc_value':不是成员'_ts' 的 c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209):注意:请参阅 '_ts' _line_profiler.c(7964) 的声明:错误 C2039:'exc_traceback ': 不是 '_ts' 的成员 c:\users\asmobari\appdata\local\programs\python\python37\include\pystate.h(209): 注意:见 '_ts' 的声明h(209):注意:请参阅“_ts”声明 _line_profiler.c(7964):错误 C2039:“exc_traceback”:不是“_ts”的成员 c:\users\asmobari\appdata\local\programs\python\ python37\include\pystate.h(209): 注意: 见 '_ts' 的声明h(209):注意:请参阅“_ts”声明 _line_profiler.c(7964):错误 C2039:“exc_traceback”:不是“_ts”的成员 c:\users\asmobari\appdata\local\programs\python\ python37\include\pystate.h(209): 注意: 见 '_ts' 的声明

退出状态为 2 失败

-u -c "导入设置工具,标记化;文件='C:\Users\asmobari\AppData\Local\Temp\pip-install-2w13a4ux\line-profiler\setup.py';f=getattr(tokenize, 'open' , open)( file );code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file , 'exec'))" install --record C:\Users\asmobari\AppData\Local\Temp\pip-record-h8dq1h7x\install-record.txt --single-version-externally-managed --compile" 失败,错误代码 1 在 C:\用户\asmobari\AppData\Local\Temp\pip-install-2w13a4ux\line-profiler\

我想知道是否有人可以帮我解决这个问题,或者是否有人知道除了 from line_profiler import LineProfiler 和 import line_profiler to import line_profiler 之外的其他方法