Allow optional CR before LF when probing collapsed stacks files (#154)

This fixes #152, in that it allows "collapsed stacks" files generated with
tools using Windows line endings to be imported into the tool verbatim.
This commit is contained in:
januszn 2018-09-04 23:12:27 -04:00 committed by Jamie Wong
parent 44a1f520fe
commit 281d9f9033
4 changed files with 64 additions and 1 deletions

View File

@ -0,0 +1,5 @@
a;b;c 1
a;b;c 1
a;b;d 4
a;b;c 3
a;b 5

View File

@ -50,6 +50,60 @@ Object {
} }
`; `;
exports[`importFromBGFlameGraph with CRLF 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-crlf.txt",
"stacks": Array [
"a;b;c 2",
"a;b;d 4",
"a;b;c 3",
"a;b 5",
],
}
`;
exports[`importFromBGFlameGraph with CRLF: indexToView 1`] = `0`;
exports[`importFromBGFlameGraph with CRLF: profileGroup.name 1`] = `"simple-crlf.txt"`;
exports[`importFromBGFlameGraph: indexToView 1`] = `0`; exports[`importFromBGFlameGraph: indexToView 1`] = `0`;
exports[`importFromBGFlameGraph: profileGroup.name 1`] = `"simple.txt"`; exports[`importFromBGFlameGraph: profileGroup.name 1`] = `"simple.txt"`;

View File

@ -3,3 +3,7 @@ import {checkProfileSnapshot} from '../lib/test-utils'
test('importFromBGFlameGraph', async () => { test('importFromBGFlameGraph', async () => {
await checkProfileSnapshot('./sample/profiles/stackcollapse/simple.txt') await checkProfileSnapshot('./sample/profiles/stackcollapse/simple.txt')
}) })
test('importFromBGFlameGraph with CRLF', async () => {
await checkProfileSnapshot('./sample/profiles/stackcollapse/simple-crlf.txt')
})

View File

@ -103,7 +103,7 @@ async function _importProfileGroup(
// If every line ends with a space followed by a number, it's probably // If every line ends with a space followed by a number, it's probably
// the collapsed stack format. // the collapsed stack format.
const lineCount = contents.split(/\n/).length const lineCount = contents.split(/\n/).length
if (lineCount >= 1 && lineCount === contents.split(/ \d+\n/).length) { if (lineCount >= 1 && lineCount === contents.split(/ \d+\r?\n/).length) {
console.log('Importing as collapsed stack format') console.log('Importing as collapsed stack format')
return toGroup(importFromBGFlameGraph(contents)) return toGroup(importFromBGFlameGraph(contents))
} }