You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ya...@apache.org on 2017/04/28 22:29:43 UTC

mesos git commit: Fix perf-stat parsing for recent perf releases.

Repository: mesos
Updated Branches:
  refs/heads/master b28e4a92d -> 6f6a5868b


Fix perf-stat parsing for recent perf releases.

perf-stat(1) emits additional metric aggregation and value fields since
Linux 4.6 (see kernel tree commit 92a61f6). Since these fields are not
needed for the Sample interface, it is ok to ignore them.

Review: https://reviews.apache.org/r/56731/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6f6a5868
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6f6a5868
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6f6a5868

Branch: refs/heads/master
Commit: 6f6a5868b0710d416207fcae62a8a2f27f73ed64
Parents: b28e4a9
Author: James Peach <jp...@apache.org>
Authored: Fri Apr 28 15:22:30 2017 -0700
Committer: Jiang Yan Xu <xu...@apple.com>
Committed: Fri Apr 28 15:29:11 2017 -0700

----------------------------------------------------------------------
 src/linux/perf.cpp                     | 40 +++++++++++++++++------------
 src/tests/containerizer/perf_tests.cpp | 15 ++++++-----
 2 files changed, 32 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6f6a5868/src/linux/perf.cpp
----------------------------------------------------------------------
diff --git a/src/linux/perf.cpp b/src/linux/perf.cpp
index 5f4f50a..b333496 100644
--- a/src/linux/perf.cpp
+++ b/src/linux/perf.cpp
@@ -368,25 +368,31 @@ struct Sample
     // because the unit field can be empty.
     vector<string> tokens = strings::split(line, PERF_DELIMITER);
 
-    // The following formats are possible:
-    //   (1) value,event,cgroup (since Linux v2.6.39)
-    //   (2) value,unit,event,cgroup (since Linux v3.14)
-    //   (3) value,unit,event,cgroup,running,ratio (since Linux v4.1)
-    //
-    // Note that we do not use the kernel version when parsing
-    // because OS vendors often backport perf tool functionality
-    // into older kernel versions.
-
-    if (tokens.size() == 3) {
-      return Sample({tokens[0], internal::normalize(tokens[1]), tokens[2]});
-    }
+    // A number of CSV formats are possible.  Note that we do not
+    // use the kernel version when parsing because OS vendors often
+    // backport perf tool functionality into older kernel versions.
 
-    if (tokens.size() == 4 || tokens.size() == 6) {
-      return Sample({tokens[0], internal::normalize(tokens[2]), tokens[3]});
-    }
+    switch (tokens.size()) {
+      // value,event,cgroup (since Linux v2.6.39)
+      case 3:
+        return Sample({tokens[0], internal::normalize(tokens[1]), tokens[2]});
+
+      // value,unit,event,cgroup (since Linux v3.14)
+      case 4:
+
+      // value,unit,event,cgroup,running,measurement-ratio (since Linux v4.1)
+      case 6:
 
-    // Bail out if the format is not recognized.
-    return Error("Unexpected number of fields");
+      // value,unit,event,cgroup,running,measurement-ratio,
+      // aggregate-value,aggregate-unit (since Linux v4.6)
+      case 8:
+        return Sample({tokens[0], internal::normalize(tokens[2]), tokens[3]});
+
+      // Bail out if the format is not recognized.
+      default:
+        return Error(
+            "Unexpected number of fields (" + stringify(tokens.size()) + ")");
+    }
   }
 };
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/6f6a5868/src/tests/containerizer/perf_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/perf_tests.cpp b/src/tests/containerizer/perf_tests.cpp
index e2d7860..b33b928 100644
--- a/src/tests/containerizer/perf_tests.cpp
+++ b/src/tests/containerizer/perf_tests.cpp
@@ -71,14 +71,17 @@ TEST_F(PerfTest, Parse)
 {
   // Parse multiple cgroups with uint64 and floats.
   Try<hashmap<string, mesos::PerfStatistics>> parse =
-    perf::parse("123,cycles,cgroup1\n"
-                "456,cycles,cgroup2\n"
-                "0.456,task-clock,cgroup2\n"
-                "0.123,task-clock,cgroup1",
-                Version(3, 12, 0));
+    perf::parse(
+        "123,cycles,cgroup1\n"
+        "456,cycles,cgroup2\n"
+        "0.456,task-clock,cgroup2\n"
+        "0.123,task-clock,cgroup1\n"
+        "5812843447,,cycles,cgroup3,3560494814,100.00,0.097,GHz\n"
+        "60011.034108,,task-clock,cgroup3,60011034108,100.00,11.999,CPUs utilized", // NOLINT(whitespace/line_length)
+        Version(3, 12, 0));
 
   ASSERT_SOME(parse);
-  EXPECT_EQ(2u, parse->size());
+  EXPECT_EQ(3u, parse->size());
 
   ASSERT_TRUE(parse->contains("cgroup1"));
   mesos::PerfStatistics statistics = parse->get("cgroup1").get();