Allow collapsed stacks with invalid lines (#336)
Ingest files containing collapsed stacks and tolerate invalid lines, like FlameGraph does. Some files might contain lines starting with a # to add comments to the collected samples. Speedscope should still attempt to parse these files as collapsed stacks and only keep the samples that it can find. Only fail if there are no samples reported.
This commit is contained in:
committed by
GitHub
parent
246fc3dd5d
commit
36aebfbda6
8
sample/profiles/stackcollapse/simple-with-invalids.txt
Normal file
8
sample/profiles/stackcollapse/simple-with-invalids.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
# comment that gives extra info about the samples
|
||||
// some other comment
|
||||
a;b;c 1
|
||||
a;b;c 1
|
||||
a;b;d 4
|
||||
a;b;c 3
|
||||
a;b 5
|
||||
invalid line
|
||||
@@ -212,6 +212,60 @@ exports[`importFromBGFlameGraph with UTF-16, Little Endian: indexToView 1`] = `0
|
||||
|
||||
exports[`importFromBGFlameGraph with UTF-16, Little Endian: profileGroup.name 1`] = `"simple-utf16-le.txt"`;
|
||||
|
||||
exports[`importFromBGFlameGraph with invalid lines 1`] = `
|
||||
Object {
|
||||
"frames": Array [
|
||||
Frame {
|
||||
"col": undefined,
|
||||
"file": undefined,
|
||||
"key": "a",
|
||||
"line": undefined,
|
||||
"name": "a",
|
||||
"selfWeight": 0,
|
||||
"totalWeight": 14,
|
||||
},
|
||||
Frame {
|
||||
"col": undefined,
|
||||
"file": undefined,
|
||||
"key": "b",
|
||||
"line": undefined,
|
||||
"name": "b",
|
||||
"selfWeight": 5,
|
||||
"totalWeight": 14,
|
||||
},
|
||||
Frame {
|
||||
"col": undefined,
|
||||
"file": undefined,
|
||||
"key": "c",
|
||||
"line": undefined,
|
||||
"name": "c",
|
||||
"selfWeight": 5,
|
||||
"totalWeight": 5,
|
||||
},
|
||||
Frame {
|
||||
"col": undefined,
|
||||
"file": undefined,
|
||||
"key": "d",
|
||||
"line": undefined,
|
||||
"name": "d",
|
||||
"selfWeight": 4,
|
||||
"totalWeight": 4,
|
||||
},
|
||||
],
|
||||
"name": "simple-with-invalids.txt",
|
||||
"stacks": Array [
|
||||
"a;b;c 2",
|
||||
"a;b;d 4",
|
||||
"a;b;c 3",
|
||||
"a;b 5",
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`importFromBGFlameGraph with invalid lines: indexToView 1`] = `0`;
|
||||
|
||||
exports[`importFromBGFlameGraph with invalid lines: profileGroup.name 1`] = `"simple-with-invalids.txt"`;
|
||||
|
||||
exports[`importFromBGFlameGraph: indexToView 1`] = `0`;
|
||||
|
||||
exports[`importFromBGFlameGraph: profileGroup.name 1`] = `"simple.txt"`;
|
||||
|
||||
@@ -15,3 +15,7 @@ test('importFromBGFlameGraph with UTF-16, Little Endian', async () => {
|
||||
test('importFromBGFlameGraph with UTF-16, Big Endian', async () => {
|
||||
await checkProfileSnapshot('./sample/profiles/stackcollapse/simple-utf16-be.txt')
|
||||
})
|
||||
|
||||
test('importFromBGFlameGraph with invalid lines', async () => {
|
||||
await checkProfileSnapshot('./sample/profiles/stackcollapse/simple-with-invalids.txt')
|
||||
})
|
||||
|
||||
@@ -201,19 +201,17 @@ async function _importProfileGroup(dataSource: ProfileDataSource): Promise<Profi
|
||||
return toGroup(importFromInstrumentsDeepCopy(contents))
|
||||
}
|
||||
|
||||
// If every line ends with a space followed by a number, it's probably
|
||||
// the collapsed stack format.
|
||||
const lineCount = contents.split(/\n/).length
|
||||
if (lineCount >= 1 && lineCount === contents.split(/ \d+\r?\n/).length) {
|
||||
console.log('Importing as collapsed stack format')
|
||||
return toGroup(importFromBGFlameGraph(contents))
|
||||
}
|
||||
|
||||
const fromLinuxPerf = importFromLinuxPerf(contents)
|
||||
if (fromLinuxPerf) {
|
||||
console.log('Importing from linux perf script output')
|
||||
return fromLinuxPerf
|
||||
}
|
||||
|
||||
const fromBGFlameGraph = importFromBGFlameGraph(contents)
|
||||
if (fromBGFlameGraph) {
|
||||
console.log('Importing as collapsed stack format')
|
||||
return toGroup(fromBGFlameGraph)
|
||||
}
|
||||
}
|
||||
|
||||
// Unrecognized format
|
||||
|
||||
Reference in New Issue
Block a user