Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDawid Pakuła2019-04-09 15:30:58 -0400
committerDawid Pakuła2019-04-09 15:30:58 -0400
commit7737c6d87d7ac84062bb86320ba292cf3285a08a (patch)
tree48144c59dc693a6a622728ef0576323708fa4783
parent2dbcc035c6d12b63dc47e3acca29ab49f9704eaf (diff)
downloadorg.eclipse.pdt-7737c6d87d7ac84062bb86320ba292cf3285a08a.tar.gz
org.eclipse.pdt-7737c6d87d7ac84062bb86320ba292cf3285a08a.tar.xz
org.eclipse.pdt-7737c6d87d7ac84062bb86320ba292cf3285a08a.zip
Bug 545444 - support \r as new-line sign in cachegrind parser
Change-Id: Ifc85a923c381dc83abf94f4537ba305ec5f0f843 Signed-off-by: Dawid Pakuła <zulus@w3des.net>
-rw-r--r--plugins/org.eclipse.php.profile.core/src/org/eclipse/php/profile/core/engine/cachegrind/CacheGrindParser.java2
-rw-r--r--tests/org.eclipse.php.profile.core.tests/resources/cachegrind/profile_header.021
-rw-r--r--tests/org.eclipse.php.profile.core.tests/src/org/eclipse/php/profile/core/test/cachegrind/CacheGrindParserTest.java56
3 files changed, 58 insertions, 1 deletions
diff --git a/plugins/org.eclipse.php.profile.core/src/org/eclipse/php/profile/core/engine/cachegrind/CacheGrindParser.java b/plugins/org.eclipse.php.profile.core/src/org/eclipse/php/profile/core/engine/cachegrind/CacheGrindParser.java
index d43e9be63..28cc59f6b 100644
--- a/plugins/org.eclipse.php.profile.core/src/org/eclipse/php/profile/core/engine/cachegrind/CacheGrindParser.java
+++ b/plugins/org.eclipse.php.profile.core/src/org/eclipse/php/profile/core/engine/cachegrind/CacheGrindParser.java
@@ -683,7 +683,7 @@ public class CacheGrindParser {
StringBuilder buff = new StringBuilder();
List<State> states = CacheGrindParser.mainStates;
while (letter != -1) {
- if (letter == '\n') {
+ if (letter == '\n' || letter == '\r') {
if (states.size() != 1) {
if (buff.length() > 0) {
listener.unknown(buff.toString());
diff --git a/tests/org.eclipse.php.profile.core.tests/resources/cachegrind/profile_header.02 b/tests/org.eclipse.php.profile.core.tests/resources/cachegrind/profile_header.02
new file mode 100644
index 000000000..571af8f10
--- /dev/null
+++ b/tests/org.eclipse.php.profile.core.tests/resources/cachegrind/profile_header.02
@@ -0,0 +1 @@
+# callgrind format events: Cycles Instructions Flops creator: xdebug 2.6.0 (PHP 7.1.13) version: something cmd: /src/web/app_dev.php part: 1 positions: instr line pid: 10 totals: 10 11 summary: 10 12 desc: unsupported version: 1 fl=file1.c fi=file2.c fe=file3.c fn=main calls=23 -3 4 23 0 0 3 fl=(1) file1.c fl=(1) fn=(1) main cfl=cfile1.c cfi=cfile2.c cfn=main cfl=(2) \ No newline at end of file
diff --git a/tests/org.eclipse.php.profile.core.tests/src/org/eclipse/php/profile/core/test/cachegrind/CacheGrindParserTest.java b/tests/org.eclipse.php.profile.core.tests/src/org/eclipse/php/profile/core/test/cachegrind/CacheGrindParserTest.java
index 3c664e400..356dd0dea 100644
--- a/tests/org.eclipse.php.profile.core.tests/src/org/eclipse/php/profile/core/test/cachegrind/CacheGrindParserTest.java
+++ b/tests/org.eclipse.php.profile.core.tests/src/org/eclipse/php/profile/core/test/cachegrind/CacheGrindParserTest.java
@@ -273,4 +273,60 @@ public class CacheGrindParserTest {
file.close();
}
+
+ @Test
+ public void test2() throws IOException {
+ InputStream file = getFile("/resources/cachegrind/profile_header.02");
+
+ CacheGrindParser parser = new CacheGrindParser(file);
+ Listener listener = new Listener();
+ parser.parse(listener);
+
+ assertEquals("xdebug 2.6.0 (PHP 7.1.13)", listener.creator);
+ assertEquals("1", listener.version);
+ assertEquals("/src/web/app_dev.php", listener.cmd);
+ assertEquals(10, listener.pid);
+ assertEquals(1, listener.part);
+
+ assertArrayEquals(new String[] { "instr", "line" }, listener.positions);
+ assertArrayEquals(new String[] { "Cycles", "Instructions", "Flops" }, listener.events);
+
+ assertArrayEquals(new int[] { 10, 11 }, listener.totals);
+ assertArrayEquals(new int[] { 10, 12 }, listener.summary);
+ assertArrayEquals(new String[] { "desc: unsupported" }, listener.unknown.toArray(new String[0]));
+
+ // files
+ assertEquals(5, listener.files.size());
+ assertEquals(new Name(-1, "file1.c"), listener.files.get(0));
+ assertEquals(new Name(-1, "file2.c"), listener.files.get(1));
+ assertEquals(new Name(-1, "file3.c"), listener.files.get(2));
+ assertEquals(new Name(1, "file1.c"), listener.files.get(3));
+ assertEquals(new Name(1, null), listener.files.get(4));
+
+ // functions
+ assertEquals(2, listener.functions.size());
+ assertEquals(new Name(-1, "main"), listener.functions.get(0));
+ assertEquals(new Name(1, "main"), listener.functions.get(1));
+
+ // next files
+ assertEquals(3, listener.nextFiles.size());
+ assertEquals(new Name(-1, "cfile1.c"), listener.nextFiles.get(0));
+ assertEquals(new Name(-1, "cfile2.c"), listener.nextFiles.get(1));
+ assertEquals(new Name(2, null), listener.nextFiles.get(2));
+
+ // next functions
+ assertEquals(1, listener.nextFunctions.size());
+ assertEquals(new Name(-1, "main"), listener.nextFunctions.get(0));
+
+ // calls
+ assertEquals(1, listener.calls.size());
+ assertEquals(new Nums(23, new int[] { -3, 4 }), listener.calls.get(0));
+
+ // cost
+ assertEquals(1, listener.costs.size());
+ assertEquals(new Nums(23, new int[] { 0, 0, 3 }), listener.costs.get(0));
+
+ file.close();
+
+ }
}

Back to the top