简体   繁体   English

Chrome开发者工具Profiler显示与console.log不同数量的方法调用

[英]Chrome Developer Tools Profiler showing different number of method calls vs console.log

I'm using the Profiles tab of the Dev Tools in Chrome. 我正在使用Chrome中Dev Tools的“个人档案”标签。 In the profile, I'm seeing an entry for function resizeDocument called 6+ times, with values 113ms, 17ms, 45ms, etc etc. Same line number, same file, same everything. 在配置文件中,我看到函数resizeDocument的条目被调用了6次以上,值为113ms,17ms,45ms等。相同的行号,相同的文件,相同的一切。

When I log from the console inside resizeDocument function, I only get one entry. 当我从resizeDocument函数内的控制台登录时,我只得到一个条目。 What is going on? 到底是怎么回事?

在此输入图像描述

在此输入图像描述

在此输入图像描述

在此输入图像描述

The reason of that is the nature of CPU profiler in chrome. 原因是chrome中的CPU分析器的性质。 It is a sampling profiler. 它是一个抽样分析器。 So it collects call stacks (samples) of the running program and uses them for reconstructing the bars in the chart view. 因此,它收集正在运行的程序的调用堆栈(示例),并使用它们来重建图表视图中的条形图。

For example if the profiler collected 1000 samples with one call frame for a function 'foo' in the each sample then you will see 1s long bar with 'foo' name in it. 例如,如果探查器在每个样本中收集了1000个样本,其中一个调用帧用于函数“foo”,那么您将看到1s长条,其中包含“foo”名称。

It might happen that the profiler can't collect the next stack trace. 可能会发生分析器无法收集下一个堆栈跟踪的情况。 For example it happens when the profiler tries to collect the call frames from the stack at a time when the function 'foo' called function 'bar' right before the sample. 例如,当函数'foo'在样本之前调用函数'bar'时,探测器尝试从堆栈中收集调用帧时会发生这种情况。 At this moment, right after call instruction, the function 'bar' constructs the call frame for 'foo' on the stack. 此时,在调用指令之后,函数'bar'在堆栈上构造'foo'的调用帧。 So the call frames on the stack are in invalid state at the moment. 因此,堆栈上的调用帧目前处于无效状态。 The profiler detects that and drops the sample. 探查器检测到并丢弃样本。 As a result a gap happens in the sequence of stack traces. 结果,在堆栈轨迹的序列中发生间隙。

In this case two different bars for 'foo' will be constructed. 在这种情况下,将构造两个不同的“foo”条。

Also there is a few other reasons when the profiler can't collect the call stack. 当探查器无法收集调用堆栈时,还有一些其他原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM