You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by al...@apache.org on 2018/04/18 04:21:55 UTC

[02/12] mesos git commit: Simplified download pipeline in MemoryProfiler.

Simplified download pipeline in MemoryProfiler.


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

Branch: refs/heads/master
Commit: 915bf398a930e2b7f0ec571fa5a5712d7bb3ca82
Parents: 963a289
Author: Alexander Rukletsov <al...@apache.org>
Authored: Wed Apr 18 03:07:32 2018 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Wed Apr 18 06:20:29 2018 +0200

----------------------------------------------------------------------
 3rdparty/libprocess/src/memory_profiler.cpp | 61 +++++++++++-------------
 1 file changed, 28 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/915bf398/3rdparty/libprocess/src/memory_profiler.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/memory_profiler.cpp b/3rdparty/libprocess/src/memory_profiler.cpp
index 1991bbe..db3045e 100644
--- a/3rdparty/libprocess/src/memory_profiler.cpp
+++ b/3rdparty/libprocess/src/memory_profiler.cpp
@@ -818,6 +818,7 @@ Future<http::Response> MemoryProfiler::downloadRaw(
         "No heap profile exists: " + jemallocRawProfile.id().error() + ".\n");
   }
 
+  // Only requests for the latest available version are allowed.
   if (requestedId.isSome() &&
       (requestedId.get() != jemallocRawProfile.id().get())) {
     return http::BadRequest(
@@ -851,31 +852,27 @@ Future<http::Response> MemoryProfiler::downloadTextProfile(
         "No source profile exists: " + jemallocRawProfile.id().error() + ".\n");
   }
 
+  // Only requests for the latest available version are allowed.
+  if (requestedId.isSome() &&
+      (requestedId.get() != jemallocRawProfile.id().get())) {
+    return http::BadRequest(
+        "Cannot serve requested id #" + stringify(requestedId.get()) + ".\n");
+  }
+
   if (currentRun.isSome() && !requestedId.isSome()) {
     return http::BadRequest(
         "A profiling run is currently in progress. To download results of the"
         " previous run, please pass an 'id' explicitly.\n");
   }
 
-  time_t rawId = jemallocRawProfile.id().get();
-
-  // Use the latest version as default.
-  if (requestedId.isNone()) {
-    requestedId = rawId;
-  }
-
-  // Generate the profile with the given timestamp, or return the cached file
-  // on disk.
+  // Generate the profile for the latest available version,
+  // or return the cached file on disk.
+  Try<string> rawProfilePath = jemallocRawProfile.path();
   Try<Nothing> result = jeprofSymbolizedProfile.generate(
-      requestedId.get(),
-      [&](const string& outputPath) -> Try<Nothing>
-      {
-        if (!(requestedId.get() == jemallocRawProfile.id().get())) {
-          return Error("Requested version cannot be served");
-        }
-
+      jemallocRawProfile.id().get(),
+      [rawProfilePath](const string& outputPath) -> Try<Nothing> {
         return generateJeprofFile(
-            jemallocRawProfile.path(),
+            rawProfilePath,
             "--text",
             outputPath);
       });
@@ -906,29 +903,27 @@ Future<http::Response> MemoryProfiler::downloadGraph(
         "No source profile exists: " + jemallocRawProfile.id().error() + ".\n");
   }
 
+  // Only requests for the latest available version are allowed.
+  if (requestedId.isSome() &&
+      (requestedId.get() != jemallocRawProfile.id().get())) {
+    return http::BadRequest(
+        "Cannot serve requested id #" + stringify(requestedId.get()) + ".\n");
+  }
+
   if (currentRun.isSome() && !requestedId.isSome()) {
     return http::BadRequest(
         "A profiling run is currently in progress. To download results of the"
         " previous run, please pass an 'id' explicitly.\n");
   }
 
-  time_t rawId = jemallocRawProfile.id().get();
-
-  // Use the latest version as default.
-  if (requestedId.isNone()) {
-    requestedId = rawId;
-  }
-
-  // Generate the graph with the given id, or return the cached file on disk.
+  // Generate the profile for the latest available version,
+  // or return the cached file on disk.
+  Try<string> rawProfilePath = jemallocRawProfile.path();
   Try<Nothing> result = jeprofGraph.generate(
-      rawId,
-      [&](const string& outputPath) -> Try<Nothing> {
-        if (!(requestedId.get() == jemallocRawProfile.id().get())) {
-          return Error("Requested version cannot be served");
-        }
-
+      jemallocRawProfile.id().get(),
+      [rawProfilePath](const string& outputPath) -> Try<Nothing> {
         return generateJeprofFile(
-            jemallocRawProfile.path(),
+            rawProfilePath,
             "--svg",
             outputPath);
       });
@@ -1111,7 +1106,7 @@ void MemoryProfiler::stopAndGenerateRawProfile()
 
   Try<Nothing> generated = jemallocRawProfile.generate(
       runId,
-      [this](const string& outputPath) -> Try<Nothing> {
+      [](const string& outputPath) -> Try<Nothing> {
         // Make sure we actually have permissions to write to the file and that
         // there is at least a little bit space left on the device.
         const string data(DUMMY_FILE_SIZE, '\0');