You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/04/25 23:05:21 UTC

mesos git commit: Fixed the 'perf' parsing logic.

Repository: mesos
Updated Branches:
  refs/heads/master d014d994b -> a5c81d407


Fixed the 'perf' parsing logic.

Previously the 'perf' parsing logic used the kernel version to
determine the token ordering. However, this approach breaks
when distributions backport perf parsing changes onto older
kernel versions. This updates the parsing logic to understand
all existing formats.

Co-authored with haosdent.

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


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

Branch: refs/heads/master
Commit: a5c81d4077400892cd3a5c306143f16903aac62c
Parents: d014d99
Author: fan du <fa...@intel.com>
Authored: Mon Apr 25 13:50:50 2016 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Mon Apr 25 14:04:55 2016 -0700

----------------------------------------------------------------------
 src/linux/perf.cpp | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a5c81d40/src/linux/perf.cpp
----------------------------------------------------------------------
diff --git a/src/linux/perf.cpp b/src/linux/perf.cpp
index 749e676..2364ab5 100644
--- a/src/linux/perf.cpp
+++ b/src/linux/perf.cpp
@@ -343,28 +343,24 @@ struct Sample
     // because the unit field can be empty.
     vector<string> tokens = strings::split(line, PERF_DELIMITER);
 
-    if (version >= Version(4, 0, 0)) {
-      // Optional running time and ratio were introduced in Linux v4.0,
-      // which make the format either:
-      //   value,unit,event,cgroup
-      //   value,unit,event,cgroup,running,ratio
-      if ((tokens.size() == 4) || (tokens.size() == 6)) {
-        return Sample({tokens[0], internal::normalize(tokens[2]), tokens[3]});
-      }
-    } else if (version >= Version(3, 13, 0)) {
-      // Unit was added in Linux v3.13, making the format:
-      //   value,unit,event,cgroup
-      if (tokens.size() == 4) {
-        return Sample({tokens[0], internal::normalize(tokens[2]), tokens[3]});
-      }
-    } else {
-      // Expected format for Linux kernel <= 3.12 is:
-      //   value,event,cgroup
-      if (tokens.size() == 3) {
-        return Sample({tokens[0], internal::normalize(tokens[1]), tokens[2]});
-      }
+    // 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]});
+    }
+
+    if (tokens.size() == 4 || tokens.size() == 6) {
+      return Sample({tokens[0], internal::normalize(tokens[2]), tokens[3]});
     }
 
+    // Bail out if the format is not recognized.
     return Error("Unexpected number of fields");
   }
 };