Skip to content

Commit c477745

Browse files
committed
address Joseph's comments
1 parent f981a49 commit c477745

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

mllib/src/main/scala/org/apache/spark/ml/util/stopwatches.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private[spark] abstract class Stopwatch extends Serializable {
5050
*/
5151
def stop(): Long = {
5252
assume(running, "stop() called but the stopwatch is not running.")
53-
val duration = now - startTime
53+
val duration = now - startTime
5454
add(duration)
5555
running = false
5656
duration
@@ -100,7 +100,7 @@ private[spark] class DistributedStopwatch(
100100
sc: SparkContext,
101101
override val name: String) extends Stopwatch {
102102

103-
val elapsedTime: Accumulator[Long] = sc.accumulator(0L, s"DistributedStopwatch($name)")
103+
private val elapsedTime: Accumulator[Long] = sc.accumulator(0L, s"DistributedStopwatch($name)")
104104

105105
override def elapsed(): Long = elapsedTime.value
106106

@@ -144,9 +144,8 @@ private[spark] class MultiStopwatch(@transient private val sc: SparkContext) ext
144144
def apply(name: String): Stopwatch = stopwatches(name)
145145

146146
override def toString: String = {
147-
"MultiStopwatch" +
148-
stopwatches.values.toArray.sortBy(_.name)
149-
.map(c => s" ${c.name} -> ${c.elapsed()}ms")
150-
.mkString("(\n", ",\n", "\n)")
147+
stopwatches.values.toArray.sortBy(_.name)
148+
.map(c => s" ${c.name}: ${c.elapsed()}ms")
149+
.mkString("{\n", ",\n", "\n}")
151150
}
152151
}

mllib/src/test/scala/org/apache/spark/ml/util/StopwatchSuite.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ class StopwatchSuite extends SparkFunSuite with MLlibTestSparkContext {
3434
val duration = sw.stop()
3535
assert(duration >= 50 && duration < 100) // using a loose upper bound
3636
val elapsed = sw.elapsed()
37-
assert(elapsed >= 50 && elapsed < 100)
37+
assert(elapsed === duration)
3838
sw.start()
3939
Thread.sleep(50)
4040
val duration2 = sw.stop()
4141
assert(duration2 >= 50 && duration2 < 100)
4242
val elapsed2 = sw.elapsed()
43-
assert(elapsed2 >= 100 && elapsed2 < 200)
43+
assert(elapsed2 == duration + duration2)
4444
sw.start()
4545
assert(sw.isRunning)
4646
intercept[AssertionError] {
@@ -80,7 +80,7 @@ class StopwatchSuite extends SparkFunSuite with MLlibTestSparkContext {
8080
intercept[NoSuchElementException] {
8181
sw("some")
8282
}
83-
assert(sw.toString === "MultiStopwatch(\n local -> 0ms,\n spark -> 0ms\n)")
83+
assert(sw.toString === "{\n local: 0ms,\n spark: 0ms\n}")
8484
sw("local").start()
8585
sw("spark").start()
8686
Thread.sleep(50)
@@ -92,7 +92,7 @@ class StopwatchSuite extends SparkFunSuite with MLlibTestSparkContext {
9292
assert(localElapsed >= 50 && localElapsed < 100)
9393
assert(sparkElapsed >= 100 && sparkElapsed < 200)
9494
assert(sw.toString ===
95-
s"MultiStopwatch(\n local -> ${localElapsed}ms,\n spark -> ${sparkElapsed}ms\n)")
95+
s"{\n local: ${localElapsed}ms,\n spark: ${sparkElapsed}ms\n}")
9696
val rdd = sc.parallelize(0 until 4, 4)
9797
rdd.foreach { i =>
9898
sw("local").start()

0 commit comments

Comments
 (0)