Commit 2a117338 authored by Josef Weidendorfer's avatar Josef Weidendorfer

Fix detection of callgrind files for very long commands

Backport fix from master

A file created by a callgrind run of "ls /usr/bin/*" was not detected
as callgrind file due to the previous heuristics that the first 2k
characters should contain "events:".
Also checking for "creator: callgrind" fixes this issue.

This assumes that other creators of callgrind files never have such long
command lines, are put the "event:" line before the "cmd:" line.

The real fix would be a mandatory first magic line, which unfortunately is
not part of the format specification, and now we need to be compatible.
parent 3c9da249
......@@ -149,24 +149,31 @@ CachegrindLoader::CachegrindLoader()
bool CachegrindLoader::canLoad(QIODevice* file)
{
if (!file) return false;
if (!file) return false;
Q_ASSERT(file->isOpen());
Q_ASSERT(file->isOpen());
/*
* We recognize this as cachegrind/callgrind format if in the first
* 2047 bytes we see the string "\nevents:"
*/
char buf[2048];
int read = file->read(buf,2047);
if (read < 0)
return false;
buf[read] = 0;
QByteArray s = QByteArray::fromRawData(buf, read+1);
int pos = s.indexOf("events:");
if (pos>0 && buf[pos-1] != '\n') pos = -1;
return (pos>=0);
/*
* We recognize this as cachegrind/callgrind format if in the first
* 2047 bytes we see the string "\nevents:" or "\ncreator: callgrind"
*/
char buf[2048];
int read = file->read(buf,2047);
if (read < 0)
return false;
buf[read] = 0;
QByteArray s = QByteArray::fromRawData(buf, read+1);
int pos = s.indexOf("events:");
if (pos>0 && buf[pos-1] != '\n') pos = -1;
if (pos>=0) return true;
// callgrind puts a "cmd:" line before "events:", and with big command
// lines, we need another way to detect such callgrind files...
pos = s.indexOf("creator: callgrind");
if (pos>0 && buf[pos-1] != '\n') pos = -1;
return (pos>=0);
}
int CachegrindLoader::load(TraceData* d,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment