cprofilingprofilergprof

gprof output shows a nonexistent call graph edge


I'm interested in profiling the function grep_source_is_binary()[1], whose code goes as following:

static int grep_source_is_binary(struct grep_source *gs,
                 struct index_state *istate)
{
    grep_source_load_driver(gs, istate);
    if (gs->driver->binary != -1)
        return gs->driver->binary;

    if (!grep_source_load(gs))
        return buffer_is_binary(gs->buf, gs->size);

    return 0;
}

gprof's call graph gives me this information:

                0.00    1.58  304254/304254      grep_source_1 [6]
[7]     72.9    0.00    1.58  304254         grep_source_is_binary [7]
                0.01    1.20  304254/304254      show_line_header [8]
                0.00    0.37  303314/607568      grep_source_load [15]

This seems weird to me, as show_line_header() is not called by grep_source_binary() nor any of its children. Am I misinterpreting gprof's output?

[1]: at https://github.com/git/git/blob/master/grep.c#L2183


Solution

  • Check if your code is being optimized by the compiler. If yes, then disable it by using -O0.