KCachegrind 解释混乱
我试图理解左侧面板中 Kcachegrind 中显示的值,
我包括在内。 (我在手册中读到的内容是包容性的),自我,称为函数
现在我正在分析这个cachegrind文件,我已经
Incl. ---- Self ---- Called ---- Function
100.05 ---- 0.04 ---- (0) ---- {main}
83.38 ---- 0.07 ---- 250 --- item->close
78.85 ---- 78.85 ---- 10 067 ---- php::mysql_query
并且列表还在继续..
但这是我的问题。
我认为 item->close 是我的瓶颈,但我不明白的是它如何具有 83.38 的 Inclusive 和 0.07 的 Self 以及 mysql_query 命令在两者中具有相同的值。
这里的“自我”意味着什么?
另外,这些百分比之间有何关系? 我不明白 item->close 如何占用 83% 而 mysql_query 占用 78%
谢谢
I am trying to understand the values shown in Kcachegrind in the left panel
I have Incl. (which I read in the manual is inclusive), Self, Called an Function
Now I am analyzing this cachegrind file and I have
Incl. ---- Self ---- Called ---- Function
100.05 ---- 0.04 ---- (0) ---- {main}
83.38 ---- 0.07 ---- 250 --- item->close
78.85 ---- 78.85 ---- 10 067 ---- php::mysql_query
and the list continues..
But here is my problem.
I think that the item->close is my bottleneck but what I don't understand is how it has 83.38 of Inclusive and then 0.07 of Self and the mysql_query command has the same in both.
What does the 'self' signify here?
Also how do these percentages relate to one another? I don't get it how the item->close takes 83% and the mysql_query takes 78%
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
“self”是指该函数所花费的时间,但不是它调用的任何函数所花费的时间。 如果“自我”低而“包含”。 高,那么优化的最佳位置可能是子级之一(例如,称为函数)。 在这种情况下,看起来 mysql 查询占用了大部分时间,因此您可能需要优化查询(如果可能)。
mysql_qeury
之所以有“self”==“incl”。 是探查器无法查看该函数,因为它是在 php 运行时之外(例如在 mysql 客户端库中)进行工作,我可能会补充说,对 mysql_query 的 10067 次调用确实看起来像非常可疑。 数据库查询是一项非常昂贵的操作。 您确定不能以某种方式减少查询数量吗?
编辑:
数字不需要相加。 您所看到的是这些函数所花费的整体时间的排序列表。 它不是一个调用图(尽管它经常会以某种方式模仿)。
假设有以下代码:
可能会生成以下输出:
当您按“包含”对列表进行排序时,您正在查看聚合时速度较慢的函数。 换句话说,那些在这里得分高的函数不一定很慢,但它们调用其他函数却很慢。 如果某个函数在“包含”方面得分较高。 和有很多调用,您应该考虑尝试减少对此函数的调用次数,或者让该函数缓存其结果(仅当它是查询而不是操作时才有效)。
当您按“自我”排序时,您将看到实际占用时间最多的呼叫。 这些是您想要微调的功能。 在大多数 PHP 脚本中,您会发现
mysql_query
在该领域占据主导地位。 如果您有很多调用,请再次尝试减少调用或缓存。 如果您的调用很少,那么您可能需要优化 sql 查询。 PHP 调试器无法帮助您解决此问题。 相反,找到实际的查询并在 mysql 控制台中对其运行解释
。 这本身就是一整章。"self" means the time taken by that function, but not from any functions that it calls. If "self" is low and "incl." is high, then the best place to optimise is probably in one of the children (eg. called functions). In this case, it looks like the mysql-query takes most of the time, so you'd probably want to optimise the query (If possible). The reason why
mysql_qeury
has "self" == "incl." is that the profiler can't see into the function, since it is doing its work outside of the php-runtime (eg. in the mysql client library)I might add that 10067 calls to
mysql_query
does look mighty suspicious. A database query is a very expensive operation. Are you sure you can't reduce the number of queries somehow?Edit:
The numbers don't need to add up. What you're looking at, is a sorted list of the time of the whole, that these functions take. It's not a call graph (Although it will often happen to mimic that somehow).
Assume the following code:
Which might generate the following output:
When you sort the list by "incl.", you are looking at the functions that are slow in aggregate. In other words, those that score high here, are not necessarily slow, but they call other functions which are. If a function scores high on "incl." and has many calls, you should be looking into trying to reduce the number of calls to this function, or let the function cache its result (Only works if it's a query, rather than an action).
When you sort by "self", you will see the actual calls that take up most time. These are the functions that you'd want to fine-tune on. In most PHP scripts, you'll find that
mysql_query
dominates this field. If you have many calls, again try to reduce them or cache. If you have few calls, then you probably need to optimise the sql-query. The PHP-debugger can't help you with this. Instead, find the actual query and run anexplain
on it in the mysql-console. That's a whole chapter in itself.Self 是指函数花费的时间,不包括它调用的任何函数。
例如:
这会给你:
Self means the time spent in the function excluding any functions it calls.
For example:
This would give you: