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?

Matt Wallis
  • 873
  • 5
  • 25
Derek Downey
  • 1,512
  • 2
  • 10
  • 16

2 Answers2

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

osgx
  • 90,338
  • 53
  • 357
  • 513
  • 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 '21 at 00: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.

Cory Klein
  • 51,188
  • 43
  • 183
  • 243
  • 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 03 '15 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 03 '15 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". – Ezekiel Victor May 10 '16 at 05:53