分析与日志记录有何不同?
分析与日志记录有何不同?
难道只是使用分析来进行性能测量,以了解每个函数需要多长时间吗? 还是我下班了?
通常,如何使用分析库?
通过分析获得哪些类型的统计数据?
How is profiling different from logging?
Is it just that profiling is used for performance measurements to see how long each function takes? Or am I off?
Typically, how are profiling libraries used?
What types of stats are obtained by profiling?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
日志记录会告诉您发生了什么。 它非常适合取证和调试。
分析量化了这一点:它告诉您代码在每个区域花费了多少时间,或者代码主体被执行了多少次。 它可以帮助您提高代码的性能。
分析通常在一行代码、一个函数调用、有时甚至是一个文件级别进行操作。 对于每个级别,它通常可以告诉您:
单元被执行了多少次。 通常,优化很少使用的代码不如优化执行数百万次的代码重要。 一个例外是让用户(或另一个进程)等待其完成的代码。
一个分支被采用了多少次,例如在
if
或switch
语句中。 同样,您通常最关心的是优化常用代码。在特定功能上花费了多少时间。 警告:即使是经验丰富的开发人员也常常会对这些结果感到惊讶。 很难预测您的“时间消耗”在哪里。
一个函数以及该函数内调用的所有函数花费了多少时间。 也许需要优化的不是函数本身,而是它的子函数。
调用该单元的次数。 您可能会发现某个特定函数主要是从意外位置调用的。
有了来自优秀分析器的数据,您通常可以花费相对较少的精力来显着提高性能。
Logging tells you what happened. It's great for forensics and debugging.
Profiling quantifies that: it tells you how much time your code spent in each area, or how many times a body of code was executed. It helps you improve your code's performance.
Profiling typically operates at the level of a line of code, a function call, or sometimes a file. For each level, it can typically tell you:
How many times the unit was executed. It's generally less important to optimize rarely-used code than code that executes millions of times. One exception is code that makes a user (or another process) wait for it to complete.
How many times a branch was taken, say in an
if
orswitch
statement. Again, you typically care most about optimizing often-used code.How much time was spent in a particular function. Warning: even experienced developers are often surprised by these results. It's very difficult to predict where your "time sinks" are.
How much time was spent in a function and all functions called within that function. Maybe it's not the function itself, but its children, that need optimizing.
How many times the unit was called by each caller. You may find that a particular function is called primarily from an unexpected place.
Armed with the data from a good profiler, you can often gain significant improvements in performance with relatively little effort.
分析是关于确定函数/方法调用方面的性能,例如
的次数 分析的整个想法是对系统的良好概述以确定可以在何处进行优化。 如果您知道某个特定函数的调用次数比调用次数第二高的函数多 20 次,您就知道何时应该集中优化工作。
它还会告诉您不该把时间花在哪些地方。 您不想花一天的时间来优化每小时仅调用一次的函数。 您希望将时间集中在优化那些每秒调用多次的函数。
根据我的理解,日志记录只是跟踪所调用的内容(但没有与每个调用相关的详细元数据)。
Rational Quantify 等分析库通过检测代码来收集运行时的统计数据。 这将对性能产生隐性影响,但在整个系统中都是相对的。
Profiling is about determining performance with respect to function/method calls, e.g.
The whole idea of profiling is getting a good overview of a system to determine where optimisations can be made. If you know a particular function is called 20 more times than the 2nd most highly called function, you know when to focus your optimisation efforts.
It also shows you where not to spend your time. You don't want to spend a day optimising a function that is only called once per hour. You want to focus your time on optimising those functions that are called multiple times per second.
Logging, in my understanding, is just keeping track of what has been called (but without the detailed metadata associated with each call).
Profiling libraries such as Rational Quantify work by instrumenting the code to gather statistics as it is running. This will have an implicit performance impact, but it will be relative across the system.
分析用于确定程序的运行时效率。 它可用于测量内存使用情况或 CPU 使用情况。 您可以使用它来优化您的代码。
另一方面,日志记录是一种审计功能。 您想查看程序运行时做了什么。 它更多地用于调试而不是性能。
Profiling is used to determine the run time efficiency of a program. It may be used to measure memory usage or CPU usage. You can use it to optimize your code.
Logging on the other hand is an auditing function. You want to see what the program did while it was running. It is more used for debugging than performance.
我将分析视为性能衡量,您不必分析正在运行的每一段代码,有时最好针对特定区域。
日志记录是存储信息以供以后使用,这些信息可能与分析相关,但不一定相关。 可能只是记录发生的事情。
我曾经使用过的所有分析工具基本上都允许您存储“事务”的开始时间和结束时间,然后操作数据以查看什么花费了最多的时间。
I see profiling as performance measurement, and you don't have to profile every piece of code running, it's sometimes better to target specific areas.
Logging is storing information for later use, information which may relate to profiling but not necessarily. It may just be to log what happened.
All the profiling stuff I've ever used basically allows you to store a start time and end time for a 'transaction' and later manipulate the data to see what's taking the most time.
日志记录是为了审计或故障排除而记录所做的事情。 我想说,分析是衡量性能的技术。 分析可以通过记录性能指标来完成,也可以通过使用专门的工具或实用程序来检查系统运行时的状态来完成。
Logging is recording what's done for the purpose of auditing or troubleshooting. Profiling, I'd say, is the technique of gauging performance. Profiling can be done by logging performance metrics, or it can be done by using specialized tools or utilities to examine the state of a system as it is running.
日志语句通常写在源代码本身中,而使用分析,您可以修改代码< em>在编译之后,并且仅针对分析会话进行检测(即,构建本身的任何版本中都不存在分析代码。)并实时评估性能,或者可以采样,这样它就可以以不太精细但侵入性较小的方式跟踪性能。
Log statements are usually written in the source code itself, whereas with profiling you can modify the code after it's compiled and is instrumented then and only for a profiling session (i.e., there's no profiling code present in any verison of the build itself.) and gauge performance in real-time or it can be sampled so it can track performance at a less granular but less intrusive way.
日志记录会告诉您您向 stackoverflow 发布了多少个问题。
分析告诉您发布每个问题需要多长时间,以及您在此处花费的工作日多少。
Logging tells you how many questions you've posted to stackoverflow.
Profiling tells you how long it takes to post each question, and how much of your workday you spend here.
前面的答案都是对的。
然而,恕我直言,分析器比枪更烟雾,我敢打赌这会导致一些箭头被点击。
如果你想知道一个函数负责多少时间,你需要知道它被调用了多少次以及调用时需要多长时间。 其中之一若缺一则毫无用处。
即使它告诉您这两点,它也不会告诉您函数内的哪些语句负责时间。 它们告诉你很多东西,比如带注释的调用图等等,但它仍然以大量线索的形式出现,你必须费尽心思,让你的猜测听起来更“有根据”。
然后他们谈论这些数字有多“准确”。
做了一个很好的演示,但没有解决问题。
他们可以做(但他们没有)的是指出特定的陈述或指示并说
并按 X 排序。
如果您确实需要解决性能问题,那么这就是您所需要的,并且您可以轻松地自己获得。 看这里:
如何优化程序的性能
The previous answers are right.
However, IMHO, profilers are more smoke than guns, and I bet this causes some arrows to get clicked.
If you want to know how much time a function is responsible for, you need to know both how many times it is called and how long it takes when it is called. One of these without the other is useless.
Even if it tells you both of these, it doesn't tell you what statements inside the function are responsible for the time. They tell you lots of stuff, like annotated call graphs and whatnot, but it's still in the form of lots of clues that you have to puzzle over, making your guesses sound more "informed".
Then they talk about how "accurate" the figures are.
Makes a nice presentation, but doesn't nail the problem.
What they could do (and they don't) is point at particular statements or instructions and say
and sort those by X.
If you really need to fix a performance problem, that is what you need, and you can easily get it yourself. Look here:
How to Optimize your Program's Performance