Skip to content

Commit

Permalink
add file
Browse files Browse the repository at this point in the history
Signed-off-by: Hongbin Ma (Mahone) <[email protected]>
  • Loading branch information
binmahone committed Jun 14, 2024
1 parent 0ba8e9b commit 8b3326e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object ThreadLocalMetrics {
def onMetricsExit(gpuMetric: GpuMetric): Unit = {
if (gpuMetric != NoopMetric) {
if (!ThreadLocalMetrics.currentThreadMetrics.get().contains(gpuMetric)) {
throw new IllegalArgumentException("Metric missing from thread local storage: "
throw new IllegalStateException()("Metric missing from thread local storage: "
+ gpuMetric)
}
ThreadLocalMetrics.currentThreadMetrics.get().remove(gpuMetric)
Expand Down
37 changes: 37 additions & 0 deletions tests/src/test/scala/com/nvidia/spark/rapids/MetricsSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2024, NVIDIA CORPORATION.
*
* Licensed 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 com.nvidia.spark.rapids

import com.nvidia.spark.rapids.Arm.withResource
import org.scalatest.funsuite.AnyFunSuite

class MetricsSuite extends AnyFunSuite {

test("duplicate timing on the same metrics") {
val m1 = new LocalGpuMetric()
val m2 = new LocalGpuMetric()
withResource(new MetricRange(m1, m2)) { _ =>
withResource(new MetricRange(m2, m1)) { _ =>
Thread.sleep(100)
}
}

// if the timing is duplicated, the value should be around 200,000,000
assert(m1.value < 100000000 * 1.5)
assert(m2.value < 100000000 * 1.5)
}
}

0 comments on commit 8b3326e

Please sign in to comment.