55

I have an xdebug profile on a php script that I parsed with kcachegrind. Here is a screenshot showing that the most time spent inside any given function was spent inside <cycle 1> and the top 'Callers' were made from 'include' and 'include_once' in index.php.

kcachegrind of xdebug profile showing cycle 1

This profile was run during a stress-test using apache 'ab' so there were many concurrent connections occurring.

What does <cycle 1> indicate on an xdebug profile?

2 Answers 2

42

It is heuristic cycle detection. You can turn it off from toolbar or from menu "View->Detect cycles" or "View->Do cycle detection".

Cycle is something like recursion, both direct ( f() -> f() -> f() where -> means call ) and indirect ( f()->g()->f()->g()->f())

Callgring format (used in kcachegrind) is not saving full call stack, it stores only pairs caller-callee and it may be hard to restore longer cycles from this information

1
  • Doesn't it mean having these cycles is redundant (just adding more noise) in case if f()->g()->f()->g()->f() happens inside a method x(), since we will get stats for x() anyway?
    – Nemoden
    Sep 13, 2021 at 0:34
30

Although @osgx mentions that you can turn off Cycle Detection, I just wanted to point out here that if you feel that <cycle 1> is hiding something of interest to you, that you probably should turn off cycle detection as he explains.

Disabling cycle detection in my case actually revealed some key pieces of information that were missing before.

3
  • It seems to me that turning it off only hides the info about the cycles. It doesn't reveal anything new. This solution seems to be sort of like saying, "if you don't like the story on page 9 then don't read page 9." Turning the feature off has not prevented the cycles from "hiding something of interest to [me]".
    – Octopus
    Dec 3, 2015 at 17:37
  • 1
    @Octopus It's been a couple years, but I remember that in my case cycle detection actually was hiding something of interest to me. The information I was looking for was either very difficult or impossible to find when I had cycle detection on.
    – Cory Klein
    Dec 3, 2015 at 17:39
  • 5
    @Octopus , what happens sometimes is "cycle detection" coalesces (and obscures) a bunch of details that might be relevant to see broken out; so in that case it is helpful to disable cycle detection and let those details come through. In my case, for instance, there were several __get methods calling each other repetitively and though the usage was perfectly valid, it was eating up tons of CPU. The repetitive in-calling was obscured by cycle detection, which IMO should really be thought of as "cycle detection/consolidation". May 10, 2016 at 5:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.