def callgrind(self, out, filename=None, commandline=None, relative_path=False):
        """
        Dump statistics in callgrind format.
        Contains:
        - per-line hit count, time and time-per-hit
        - call associations (call tree)
          Note: hit count is not inclusive, in that it is not the sum of all
          hits inside that call.
        Time unit: microsecond (1e-6 second).
        out (file-ish opened for writing)
            Destination of callgrind profiling data.
        filename (str, list of str)
            If provided, dump stats for given source file(s) only.
            By default, list for all known files.
        commandline (anything with __str__)
            If provided, will be output as the command line used to generate
            this profiling data.
        relative_path (bool)
            When True, absolute elements are stripped from path. Useful when
            maintaining several copies of source trees with their own
            profiling result, so kcachegrind does not look in system-wide
            files which may not match with profiled code.
        """
        print >> out, 'version: 1'
        if commandline is not None:
            print >> out, 'cmd:', commandline
        print >> out, 'creator: pprofile'
        print >> out, 'event: usphit :us/hit'
        print >> out, 'events: hits us usphit'
        file_dict = self.file_dict
        if relative_path:
            convertPath = _relpath
        else:
            convertPath = lambda x: x
        for name in self._getFileNameList(filename):
            printable_name = convertPath(name)
            print >> out, 'fl=%s' % printable_name
            funcname = False
            call_list_by_line = file_dict[name].getCallListByLine()
            for lineno, func, firstlineno, hits, duration, _ in self._iterFile(
                    name, call_list_by_line):
                call_list = call_list_by_line.get(lineno, ())
                if not hits and not call_list:
                    continue
                if func is None:
                    func, firstlineno = call_list[0][:2]
                if funcname != func:
                    funcname = func
                    print >> out, 'fn=%s' % _getFuncOrFile(func,
                        printable_name, firstlineno)
                ticks = int(duration * 1000000)
                if hits == 0:
                    ticksperhit = 0
                else:
                    ticksperhit = ticks / hits
                print >> out, lineno, hits, ticks, int(ticksperhit)
                for _, _, hits, duration, callee_file, callee_line, \
                        callee_name in sorted(call_list, key=lambda x: x[2:4]):
                    callee_file = convertPath(callee_file)
                    print >> out, 'cfl=%s' % callee_file
                    print >> out, 'cfn=%s' % _getFuncOrFile(callee_name,
                        callee_file, callee_line)
                    print >> out, 'calls=%s' % hits, callee_line
                    duration *= 1000000
                    print >> out, lineno, hits, int(duration), int(duration / hits)
Dump statistics in callgrind format.
        Contains:
        - per-line hit count, time and time-per-hit
        - call associations (call tree)
          Note: hit count is not inclusive, in that it is not the sum of all
          hits inside that call.
        Time unit: microsecond (1e-6 second).
        out (file-ish opened for writing)
            Destination of callgrind profiling data.
        filename (str, list of str)
            If provided, dump stats for given source file(s) only.
            By default, list for all known files.
        commandline (anything with __str__)
            If provided, will be output as the command line used to generate
            this profiling data.
        relative_path (bool)
            When True, absolute elements are stripped from path. Useful when
            maintaining several copies of source trees with their own
            profiling result, so kcachegrind does not look in system-wide
            files which may not match with profiled code.