{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/226524183","pull_request_review_id":166367573,"id":226524183,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNjUyNDE4Mw==","diff_hunk":"@@ -0,0 +1,226 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * the License.  You may obtain a copy of the License at\n+ *\n+ *    http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.apache.spark.executor\n+\n+import java.io._\n+import java.nio.charset.Charset\n+import java.nio.file.{Files, Paths}\n+import java.util.Locale\n+\n+import scala.collection.mutable\n+import scala.collection.mutable.ArrayBuffer\n+\n+import org.apache.spark.{SparkEnv, SparkException}\n+import org.apache.spark.internal.{config, Logging}\n+import org.apache.spark.util.Utils\n+\n+private[spark] case class ProcfsBasedSystemsMetrics(\n+    jvmVmemTotal: Long,\n+    jvmRSSTotal: Long,\n+    pythonVmemTotal: Long,\n+    pythonRSSTotal: Long,\n+    otherVmemTotal: Long,\n+    otherRSSTotal: Long)\n+\n+// Some of the ideas here are taken from the ProcfsBasedProcessTree class in hadoop\n+// project.\n+private[spark] class ProcfsBasedSystems(val procfsDir: String = \"/proc/\") extends Logging {\n+  val procfsStatFile = \"stat\"\n+  val testing = sys.env.contains(\"SPARK_TESTING\") || sys.props.contains(\"spark.testing\")\n+  var pageSize = computePageSize()\n+  var isAvailable: Boolean = isProcfsAvailable\n+  private val pid = computePid()\n+  private val ptree = mutable.Map[ Int, Set[Int]]()\n+\n+  var allMetrics: ProcfsBasedSystemsMetrics = ProcfsBasedSystemsMetrics(0, 0, 0, 0, 0, 0)\n+\n+  computeProcessTree()\n+\n+  private def isProcfsAvailable: Boolean = {\n+    if (testing) {\n+      return true\n+    }\n+    try {\n+      if (!Files.exists(Paths.get(procfsDir))) {\n+        return false\n+      }\n+    }\n+    catch {\n+      case f: FileNotFoundException => return false\n+    }\n+    val shouldLogStageExecutorMetrics =\n+      SparkEnv.get.conf.get(config.EVENT_LOG_STAGE_EXECUTOR_METRICS)\n+    val shouldLogStageExecutorProcessTreeMetrics =\n+      SparkEnv.get.conf.get(config.EVENT_LOG_PROCESS_TREE_METRICS)\n+    shouldLogStageExecutorProcessTreeMetrics && shouldLogStageExecutorMetrics\n+  }\n+\n+  private def computePid(): Int = {\n+    if (!isAvailable || testing) {\n+      return -1;\n+    }\n+    try {\n+      // This can be simplified in java9:\n+      // https://docs.oracle.com/javase/9/docs/api/java/lang/ProcessHandle.html\n+      val cmd = Array(\"bash\", \"-c\", \"echo $PPID\")\n+      val length = 10\n+      val out2 = Utils.executeAndGetOutput(cmd)\n+      val pid = Integer.parseInt(out2.split(\"\\n\")(0))\n+      return pid;\n+    }\n+    catch {\n+      case e: SparkException => logDebug(\"IO Exception when trying to compute process tree.\" +\n+        \" As a result reporting of ProcessTree metrics is stopped\", e)\n+        isAvailable = false\n+        return -1\n+    }\n+  }\n+\n+  private def computePageSize(): Long = {\n+    if (testing) {\n+      return 0;\n+    }\n+    val cmd = Array(\"getconf\", \"PAGESIZE\")\n+    val out2 = Utils.executeAndGetOutput(cmd)\n+    return Integer.parseInt(out2.split(\"\\n\")(0))","path":"core/src/main/scala/org/apache/spark/executor/ProcfsBasedSystems.scala","position":100,"original_position":100,"commit_id":"18ee4ad3829c3ee637d45f73c4e182b78c7661fb","original_commit_id":"18ee4ad3829c3ee637d45f73c4e182b78c7661fb","user":{"login":"rezasafi","id":20547172,"node_id":"MDQ6VXNlcjIwNTQ3MTcy","avatar_url":"https://avatars2.githubusercontent.com/u/20547172?v=4","gravatar_id":"","url":"https://api.github.com/users/rezasafi","html_url":"https://github.com/rezasafi","followers_url":"https://api.github.com/users/rezasafi/followers","following_url":"https://api.github.com/users/rezasafi/following{/other_user}","gists_url":"https://api.github.com/users/rezasafi/gists{/gist_id}","starred_url":"https://api.github.com/users/rezasafi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rezasafi/subscriptions","organizations_url":"https://api.github.com/users/rezasafi/orgs","repos_url":"https://api.github.com/users/rezasafi/repos","events_url":"https://api.github.com/users/rezasafi/events{/privacy}","received_events_url":"https://api.github.com/users/rezasafi/received_events","type":"User","site_admin":false},"body":"yes, will fix it.","created_at":"2018-10-19T03:10:26Z","updated_at":"2018-10-19T03:10:26Z","html_url":"https://github.com/apache/spark/pull/22612#discussion_r226524183","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/22612","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/226524183"},"html":{"href":"https://github.com/apache/spark/pull/22612#discussion_r226524183"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/22612"}},"in_reply_to_id":226519607},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/22612","id":219745354,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE5NzQ1MzU0","html_url":"https://github.com/apache/spark/pull/22612","diff_url":"https://github.com/apache/spark/pull/22612.diff","patch_url":"https://github.com/apache/spark/pull/22612.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/22612","number":22612,"state":"open","locked":false,"title":"[SPARK-24958] Add executors' process tree total memory information to heartbeat signals.","user":{"login":"rezasafi","id":20547172,"node_id":"MDQ6VXNlcjIwNTQ3MTcy","avatar_url":"https://avatars2.githubusercontent.com/u/20547172?v=4","gravatar_id":"","url":"https://api.github.com/users/rezasafi","html_url":"https://github.com/rezasafi","followers_url":"https://api.github.com/users/rezasafi/followers","following_url":"https://api.github.com/users/rezasafi/following{/other_user}","gists_url":"https://api.github.com/users/rezasafi/gists{/gist_id}","starred_url":"https://api.github.com/users/rezasafi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rezasafi/subscriptions","organizations_url":"https://api.github.com/users/rezasafi/orgs","repos_url":"https://api.github.com/users/rezasafi/repos","events_url":"https://api.github.com/users/rezasafi/events{/privacy}","received_events_url":"https://api.github.com/users/rezasafi/received_events","type":"User","site_admin":false},"body":"Spark executors' process tree total memory information can be really useful. Currently such information are not available. The goal of this PR is to compute such information for each executor, add these information to the heartbeat signals, and compute the peaks at the driver.\r\nThis PR is tested by running the current unit tests and also some added ones. I have also tested this on our internal cluster and have verified the results.","created_at":"2018-10-02T15:23:41Z","updated_at":"2018-10-19T03:10:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8b93e90d41063d29ec31f135e0616397a4cabf80","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/22612/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/22612/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/22612/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/18ee4ad3829c3ee637d45f73c4e182b78c7661fb","head":{"label":"rezasafi:ptreememory2","ref":"ptreememory2","sha":"18ee4ad3829c3ee637d45f73c4e182b78c7661fb","user":{"login":"rezasafi","id":20547172,"node_id":"MDQ6VXNlcjIwNTQ3MTcy","avatar_url":"https://avatars2.githubusercontent.com/u/20547172?v=4","gravatar_id":"","url":"https://api.github.com/users/rezasafi","html_url":"https://github.com/rezasafi","followers_url":"https://api.github.com/users/rezasafi/followers","following_url":"https://api.github.com/users/rezasafi/following{/other_user}","gists_url":"https://api.github.com/users/rezasafi/gists{/gist_id}","starred_url":"https://api.github.com/users/rezasafi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rezasafi/subscriptions","organizations_url":"https://api.github.com/users/rezasafi/orgs","repos_url":"https://api.github.com/users/rezasafi/repos","events_url":"https://api.github.com/users/rezasafi/events{/privacy}","received_events_url":"https://api.github.com/users/rezasafi/received_events","type":"User","site_admin":false},"repo":{"id":64172231,"node_id":"MDEwOlJlcG9zaXRvcnk2NDE3MjIzMQ==","name":"spark","full_name":"rezasafi/spark","private":false,"owner":{"login":"rezasafi","id":20547172,"node_id":"MDQ6VXNlcjIwNTQ3MTcy","avatar_url":"https://avatars2.githubusercontent.com/u/20547172?v=4","gravatar_id":"","url":"https://api.github.com/users/rezasafi","html_url":"https://github.com/rezasafi","followers_url":"https://api.github.com/users/rezasafi/followers","following_url":"https://api.github.com/users/rezasafi/following{/other_user}","gists_url":"https://api.github.com/users/rezasafi/gists{/gist_id}","starred_url":"https://api.github.com/users/rezasafi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rezasafi/subscriptions","organizations_url":"https://api.github.com/users/rezasafi/orgs","repos_url":"https://api.github.com/users/rezasafi/repos","events_url":"https://api.github.com/users/rezasafi/events{/privacy}","received_events_url":"https://api.github.com/users/rezasafi/received_events","type":"User","site_admin":false},"html_url":"https://github.com/rezasafi/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/rezasafi/spark","forks_url":"https://api.github.com/repos/rezasafi/spark/forks","keys_url":"https://api.github.com/repos/rezasafi/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rezasafi/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rezasafi/spark/teams","hooks_url":"https://api.github.com/repos/rezasafi/spark/hooks","issue_events_url":"https://api.github.com/repos/rezasafi/spark/issues/events{/number}","events_url":"https://api.github.com/repos/rezasafi/spark/events","assignees_url":"https://api.github.com/repos/rezasafi/spark/assignees{/user}","branches_url":"https://api.github.com/repos/rezasafi/spark/branches{/branch}","tags_url":"https://api.github.com/repos/rezasafi/spark/tags","blobs_url":"https://api.github.com/repos/rezasafi/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rezasafi/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rezasafi/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/rezasafi/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rezasafi/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/rezasafi/spark/languages","stargazers_url":"https://api.github.com/repos/rezasafi/spark/stargazers","contributors_url":"https://api.github.com/repos/rezasafi/spark/contributors","subscribers_url":"https://api.github.com/repos/rezasafi/spark/subscribers","subscription_url":"https://api.github.com/repos/rezasafi/spark/subscription","commits_url":"https://api.github.com/repos/rezasafi/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/rezasafi/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/rezasafi/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/rezasafi/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/rezasafi/spark/contents/{+path}","compare_url":"https://api.github.com/repos/rezasafi/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rezasafi/spark/merges","archive_url":"https://api.github.com/repos/rezasafi/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rezasafi/spark/downloads","issues_url":"https://api.github.com/repos/rezasafi/spark/issues{/number}","pulls_url":"https://api.github.com/repos/rezasafi/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/rezasafi/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/rezasafi/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rezasafi/spark/labels{/name}","releases_url":"https://api.github.com/repos/rezasafi/spark/releases{/id}","deployments_url":"https://api.github.com/repos/rezasafi/spark/deployments","created_at":"2016-07-25T22:32:56Z","updated_at":"2018-09-25T04:44:02Z","pushed_at":"2018-10-17T20:24:26Z","git_url":"git://github.com/rezasafi/spark.git","ssh_url":"git@github.com:rezasafi/spark.git","clone_url":"https://github.com/rezasafi/spark.git","svn_url":"https://github.com/rezasafi/spark","homepage":null,"size":275739,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"7d425b190a91f49193eeb58c398e497ff92c6169","user":{"login":"apache","id":47359,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ3MzU5","avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"node_id":"MDEwOlJlcG9zaXRvcnkxNzE2NTY1OA==","name":"spark","full_name":"apache/spark","private":false,"owner":{"login":"apache","id":47359,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ3MzU5","avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","deployments_url":"https://api.github.com/repos/apache/spark/deployments","created_at":"2014-02-25T08:00:08Z","updated_at":"2018-10-19T01:38:17Z","pushed_at":"2018-10-19T02:59:49Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":284941,"stargazers_count":19141,"watchers_count":19141,"language":"Scala","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":17188,"mirror_url":null,"archived":false,"open_issues_count":520,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":17188,"open_issues":520,"watchers":19141,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/22612"},"html":{"href":"https://github.com/apache/spark/pull/22612"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/22612"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/22612/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/22612/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/22612/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/18ee4ad3829c3ee637d45f73c4e182b78c7661fb"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"rezasafi"}}