c++kcachegrind

Kcachegrind cycle estimation


After going to their github page and seeing some pdf manual form their kde docs site, I am still confused. Suppose there are these two lines in a test code:

double a1 {asinh(1 / ep)};                   // 5 instr.
double b1 {log((1 + sqrt(1 + ep*ep)) / ep)}; // 12 instr.

where ep is some value that can be predefined. The comments are mine and done, in Codeblocks, by running the debugger with the disassembler, then patiently hitting "next instruction" and counting. These correspond with what Kacachegrind says if I set it to show "Instruction fetch". I suppose it should make sense (I am a beginner in C++, btw). But if I switch to "Cycle estimation" I get some very strange readings. For the current example, it's 115 and 122, but other, seemingly similar expressions, like:

double Ap {1.0};
double ep {0.9};

show 222 and 2 (instr. fetch shows 2 for both)! What goes on here? Can someone please explain?


Solution

  • The current source code of kcachgrind suggest a slightly more complex calculation than in the other answer:

    QString GlobalConfig::knownFormula(const QString& name)
    {
        if (name == QLatin1String("L1m")) return QStringLiteral("I1mr + D1mr + D1mw");
        if (name == QLatin1String("L2m")) return QStringLiteral("I2mr + D2mr + D2mw");
        if (name == QLatin1String("LLm")) return QStringLiteral("ILmr + DLmr + DLmw");
        if (name == QLatin1String("Bm"))  return QStringLiteral("Bim + Bcm");
        if (name == QLatin1String("CEst"))
            return QStringLiteral("Ir + 10 Bm + 10 L1m + 20 Ge + 100 L2m + 100 LLm");
    
        return QString();
    }