Github user ankuriitg commented on a diff in the pull request:
https://github.com/apache/spark/pull/21916#discussion_r206264100
--- Diff:
core/src/main/scala/org/apache/spark/executor/ProcfsBasedSystems.scala ---
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.executor
+
+import java.io.{BufferedReader, File, FileInputStream, InputStreamReader}
+import java.io.FileNotFoundException
+import java.nio.charset.Charset
+import java.nio.file.{Files, Paths}
+
+import scala.collection.mutable
+import scala.collection.mutable.ArrayBuffer
+import scala.collection.mutable.Queue
+
+// Some of the ideas here are taken from the ProcfsBasedProcessTree class
in hadoop
+// project.
+class ProcfsBasedSystems extends ProcessTreeMetrics {
+ val procfsDir = "/proc/"
+ var isAvailable: Boolean = isItProcfsBased
+ val pid: Int = computePid()
+ val ptree: scala.collection.mutable.Map[ Int, Set[Int]] =
+ scala.collection.mutable.Map[ Int, Set[Int]]()
+ val PROCFS_STAT_FILE = "stat"
+
+
+ def isItProcfsBased: Boolean = {
+ val testing = sys.env.contains("SPARK_TESTING") ||
sys.props.contains("spark.testing")
+ if (testing) {
+ return true
+ }
+ try {
+ if (!Files.exists(Paths.get(procfsDir))) {
+ return false
+ }
+ }
+ catch {
+ case f: FileNotFoundException => return false
+ }
+ true
+ }
+
+
+ def computePid(): Int = {
+ if (!isAvailable) {
+ return -1;
+ }
+ val cmd = Array("bash", "-c", "echo $PPID")
+ val length = 10
+ var out: Array[Byte] = Array.fill[Byte](length)(0)
+ Runtime.getRuntime.exec(cmd).getInputStream.read(out)
+ val pid = Integer.parseInt(new String(out, "UTF-8").trim)
+ return pid;
+ }
+
+
+ def createProcessTree(): Unit = {
+ if (!isAvailable) {
+ return
+ }
+ val queue: Queue[Int] = new Queue[Int]()
+ queue += pid
+ while( !queue.isEmpty ) {
+ val p = queue.dequeue()
+ val c = getChildPIds(p)
+ if(!c.isEmpty) {
+ queue ++= c
+ ptree += (p -> c.toSet)
+ }
+ else {
+ ptree += (p -> Set[Int]())
+ }
+ }
+ }
+
+
+ def updateProcessTree(): Unit = {
--- End diff --
Why not just create a new Process tree instead of updating the existing
tree?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]