Skip to content

Commit f2dca27

Browse files
author
Reza Safi
committed
Removing types from the definitions where ever possible
1 parent 8f3c938 commit f2dca27

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

core/src/main/scala/org/apache/spark/executor/ProcfsBasedSystems.scala

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,20 @@ private[spark] case class ProcfsBasedSystemsMetrics(
3939

4040
// Some of the ideas here are taken from the ProcfsBasedProcessTree class in hadoop
4141
// project.
42-
private[spark] class ProcfsBasedSystems(procfsDir: String = "/proc/") extends Logging {
42+
private[spark] class ProcfsBasedSystems(val procfsDir: String = "/proc/") extends Logging {
4343
val procfsStatFile = "stat"
4444
var pageSize = computePageSize()
4545
var isAvailable: Boolean = isProcfsAvailable
46-
private val pid: Int = computePid()
47-
private val ptree: scala.collection.mutable.Map[ Int, Set[Int]] =
48-
scala.collection.mutable.Map[ Int, Set[Int]]()
46+
private val pid = computePid()
47+
private val ptree = mutable.Map[ Int, Set[Int]]()
4948

5049
var allMetrics: ProcfsBasedSystemsMetrics = ProcfsBasedSystemsMetrics(0, 0, 0, 0, 0, 0)
51-
private var latestJVMVmemTotal: Long = 0
52-
private var latestJVMRSSTotal: Long = 0
53-
private var latestPythonVmemTotal: Long = 0
54-
private var latestPythonRSSTotal: Long = 0
55-
private var latestOtherVmemTotal: Long = 0
56-
private var latestOtherRSSTotal: Long = 0
50+
private var latestJVMVmemTotal = 0L
51+
private var latestJVMRSSTotal = 0L
52+
private var latestPythonVmemTotal = 0L
53+
private var latestPythonRSSTotal = 0L
54+
private var latestOtherVmemTotal = 0L
55+
private var latestOtherRSSTotal = 0L
5756

5857
computeProcessTree()
5958

@@ -86,7 +85,7 @@ private[spark] class ProcfsBasedSystems(procfsDir: String = "/proc/") extends Lo
8685
// https://docs.oracle.com/javase/9/docs/api/java/lang/ProcessHandle.html
8786
val cmd = Array("bash", "-c", "echo $PPID")
8887
val length = 10
89-
val out: Array[Byte] = Array.fill[Byte](length)(0)
88+
val out = Array.fill[Byte](length)(0)
9089
Runtime.getRuntime.exec(cmd).getInputStream.read(out)
9190
val pid = Integer.parseInt(new String(out, "UTF-8").trim)
9291
return pid;
@@ -105,7 +104,7 @@ private[spark] class ProcfsBasedSystems(procfsDir: String = "/proc/") extends Lo
105104
return 0;
106105
}
107106
val cmd = Array("getconf", "PAGESIZE")
108-
val out: Array[Byte] = Array.fill[Byte](10)(0)
107+
val out = Array.fill[Byte](10)(0)
109108
Runtime.getRuntime.exec(cmd).getInputStream.read(out)
110109
return Integer.parseInt(new String(out, "UTF-8").trim)
111110
}
@@ -114,7 +113,7 @@ private[spark] class ProcfsBasedSystems(procfsDir: String = "/proc/") extends Lo
114113
if (!isAvailable) {
115114
return
116115
}
117-
val queue: Queue[Int] = new Queue[Int]()
116+
val queue = mutable.Queue.empty[Int]
118117
queue += pid
119118
while( !queue.isEmpty ) {
120119
val p = queue.dequeue()
@@ -133,15 +132,15 @@ private[spark] class ProcfsBasedSystems(procfsDir: String = "/proc/") extends Lo
133132
try {
134133
val cmd = Array("pgrep", "-P", pid.toString)
135134
val input = Runtime.getRuntime.exec(cmd).getInputStream
136-
val childPidsInByte: mutable.ArrayBuffer[Byte] = new mutable.ArrayBuffer()
135+
val childPidsInByte = mutable.ArrayBuffer.empty[Byte]
137136
var d = input.read()
138137
while (d != -1) {
139138
childPidsInByte.append(d.asInstanceOf[Byte])
140139
d = input.read()
141140
}
142141
input.close()
143142
val childPids = new String(childPidsInByte.toArray, "UTF-8").split("\n")
144-
val childPidsInInt: ArrayBuffer[Int] = new ArrayBuffer[Int]()
143+
val childPidsInInt = mutable.ArrayBuffer.empty[Int]
145144
for (p <- childPids) {
146145
if (p != "") {
147146
childPidsInInt += Integer.parseInt(p)
@@ -152,7 +151,7 @@ private[spark] class ProcfsBasedSystems(procfsDir: String = "/proc/") extends Lo
152151
case e: IOException => logDebug("IO Exception when trying to compute process tree." +
153152
" As a result reporting of ProcessTree metrics is stopped", e)
154153
isAvailable = false
155-
return new mutable.ArrayBuffer()
154+
return mutable.ArrayBuffer.empty[Int]
156155
}
157156
}
158157

@@ -164,11 +163,11 @@ private[spark] class ProcfsBasedSystems(procfsDir: String = "/proc/") extends Lo
164163
* http://man7.org/linux/man-pages/man5/proc.5.html
165164
*/
166165
try {
167-
val pidDir: File = new File(procfsDir, pid.toString)
166+
val pidDir = new File(procfsDir, pid.toString)
168167
val fReader = new InputStreamReader(
169168
new FileInputStream(
170169
new File(pidDir, procfsStatFile)), Charset.forName("UTF-8"))
171-
val in: BufferedReader = new BufferedReader(fReader)
170+
val in = new BufferedReader(fReader)
172171
val procInfo = in.readLine
173172
in.close
174173
fReader.close

0 commit comments

Comments
 (0)