Skip to content

Commit 805741c

Browse files
author
Reza Safi
committed
Applying review comments, mostly style related
1 parent ef4be38 commit 805741c

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class ExecutorMetrics private[spark] extends Serializable {
5353
*/
5454
private[spark] def this(executorMetrics: Map[String, Long]) {
5555
this()
56-
ExecutorMetricType.metricToOffset.map { m =>
57-
metrics(m._2) = executorMetrics.getOrElse(m._1, 0L)
56+
ExecutorMetricType.metricToOffset.foreach { case(name, idx) =>
57+
metrics(idx) = executorMetrics.getOrElse(name, 0L)
5858
}
5959
}
6060

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ private[spark] case class ProcfsMetrics(
4141

4242
// Some of the ideas here are taken from the ProcfsBasedProcessTree class in hadoop
4343
// project.
44-
private[spark] class ProcfsMetricsGetter(
45-
val procfsDir: String = "/proc/",
46-
val pSizeForTest: Long = 0) extends Logging {
44+
private[spark] class ProcfsMetricsGetter(val procfsDir: String = "/proc/") extends Logging {
4745
val procfsStatFile = "stat"
4846
val testing = sys.env.contains("SPARK_TESTING") || sys.props.contains("spark.testing")
4947
val pageSize = computePageSize()
@@ -91,7 +89,7 @@ private[spark] class ProcfsMetricsGetter(
9189

9290
private def computePageSize(): Long = {
9391
if (testing) {
94-
return pSizeForTest;
92+
return 4096;
9593
}
9694
try {
9795
val cmd = Array("getconf", "PAGESIZE")
@@ -114,10 +112,10 @@ private[spark] class ProcfsMetricsGetter(
114112
ptree += pid
115113
val queue = mutable.Queue.empty[Int]
116114
queue += pid
117-
while( !queue.isEmpty ) {
115+
while ( !queue.isEmpty ) {
118116
val p = queue.dequeue()
119117
val c = getChildPids(p)
120-
if(!c.isEmpty) {
118+
if (!c.isEmpty) {
121119
queue ++= c
122120
ptree ++= c.toSet
123121
}
@@ -142,9 +140,7 @@ private[spark] class ProcfsMetricsGetter(
142140
val stdErrThread = Utils.processStreamByLine(
143141
"stderr for pgrep",
144142
process.getErrorStream,
145-
{ line =>
146-
errorStringBuilder.append(line)
147-
})
143+
line => errorStringBuilder.append(line))
148144
val exitCode = process.waitFor()
149145
stdoutThread.join()
150146
stdErrThread.join()
@@ -203,7 +199,7 @@ private[spark] class ProcfsMetricsGetter(
203199
}
204200
}
205201
} catch {
206-
case f: FileNotFoundException =>
202+
case f: IOException =>
207203
logWarning("There was a problem with reading" +
208204
" the stat file of the process. ", f)
209205
ProcfsMetrics(0, 0, 0, 0, 0, 0)
@@ -219,7 +215,7 @@ private[spark] class ProcfsMetricsGetter(
219215
for (p <- pids) {
220216
allMetrics = addProcfsMetricsFromOneProcess(allMetrics, p)
221217
}
222-
return allMetrics
218+
allMetrics
223219
}
224220
}
225221

core/src/test/scala/org/apache/spark/executor/ProcfsMetricsGetterSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import org.apache.spark.SparkFunSuite
2222

2323
class ProcfsMetricsGetterSuite extends SparkFunSuite {
2424

25-
val p = new ProcfsMetricsGetter(getTestResourcePath("ProcfsMetrics"), 4096L)
25+
val p = new ProcfsMetricsGetter(getTestResourcePath("ProcfsMetrics"))
2626

2727
test("testGetProcessInfo") {
2828
var r = ProcfsMetrics(0, 0, 0, 0, 0, 0)

0 commit comments

Comments
 (0)