-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use a stub to store Spark StageInfo #1525
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2025, 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 org.apache.spark.rapids.tool.benchmarks | ||
|
||
import org.apache.spark.sql.rapids.tool.util.RuntimeUtil | ||
|
||
/** | ||
* A simple implementation to insert checkpoints during runtime to pull some performance metrics | ||
* related to Tools. This is disabled by default and can be enabled by setting the build | ||
* property `benchmarks.checkpoints`. | ||
*/ | ||
class DevRuntimeCheckpoint extends RuntimeCheckpointTrait { | ||
/** | ||
* Insert a memory marker with the given label. This will print the memory information. | ||
* @param label the label for the memory marker | ||
*/ | ||
override def insertMemoryMarker(label: String): Unit = { | ||
val memoryInfo = RuntimeUtil.getJVMHeapInfo(runGC = true) | ||
// scalastyle:off println | ||
println(s"Memory Marker: $label, ${memoryInfo.mkString("\n")}") | ||
// scalastyle:on println | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2025, 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 org.apache.spark.rapids.tool.benchmarks | ||
|
||
import scala.annotation.nowarn | ||
|
||
/** | ||
* An empty implementation of the Checkpoint interface that inserts NoOps. | ||
* This is the default implementation that will be used in production and normal builds. | ||
*/ | ||
class NoOpRuntimeCheckpoint extends RuntimeCheckpointTrait { | ||
override def insertMemoryMarker(@nowarn label: String): Unit = { | ||
// Do nothing. This is a noOp | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2025, 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 org.apache.spark.rapids.tool.benchmarks | ||
|
||
/** | ||
* API for inserting checkpoints in runtime. | ||
* This is used for debugging and benchmarking purposes. | ||
*/ | ||
trait RuntimeCheckpointTrait { | ||
/** | ||
* Insert a memory marker with the given label. | ||
* @param label the label for the memory marker | ||
*/ | ||
def insertMemoryMarker(label: String): Unit | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2025, 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 org.apache.spark.rapids.tool.benchmarks | ||
|
||
import org.apache.spark.sql.rapids.tool.util.RapidsToolsConfUtil | ||
|
||
/** | ||
* The global runtime injector that will be used to insert checkpoints during runtime. | ||
* This is used to pull some performance metrics related to Tools. | ||
*/ | ||
object RuntimeInjector extends RuntimeCheckpointTrait { | ||
/** | ||
* Initializes the runtime injector based on the build properties "benchmarks.checkpoints". | ||
* @return the runtime injector | ||
*/ | ||
private def loadRuntimeCheckPoint(): RuntimeCheckpointTrait = { | ||
val buildProps = RapidsToolsConfUtil.loadBuildProperties | ||
if (buildProps.getProperty("build.benchmarks.checkpoints").contains("dev")) { | ||
// The benchmark injection is enabled. | ||
new DevRuntimeCheckpoint | ||
} else { // loads the noOp implementation by default | ||
new NoOpRuntimeCheckpoint | ||
} | ||
} | ||
private lazy val runtimeCheckpoint: RuntimeCheckpointTrait = loadRuntimeCheckPoint() | ||
|
||
override def insertMemoryMarker(label: String): Unit = { | ||
runtimeCheckpoint.insertMemoryMarker(label) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright (c) 2024, NVIDIA CORPORATION. | ||
* Copyright (c) 2024-2025, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -20,6 +20,7 @@ import com.nvidia.spark.rapids.tool.profiling.ProfileUtils | |
|
||
import org.apache.spark.scheduler.StageInfo | ||
import org.apache.spark.sql.rapids.tool.annotation.{Calculated, Since, WallClock} | ||
import org.apache.spark.sql.rapids.tool.util.stubs.StageInfoStub | ||
|
||
/** | ||
* StageModel is a class to store the information of a stage. | ||
|
@@ -31,16 +32,16 @@ import org.apache.spark.sql.rapids.tool.annotation.{Calculated, Since, WallClock | |
@Since("24.02.3") | ||
class StageModel private(sInfo: StageInfo) { | ||
|
||
var stageInfo: StageInfo = _ | ||
var stageInfo: StageInfoStub = _ | ||
updateInfo(sInfo) | ||
|
||
/** | ||
* @param newStageInfo | ||
* @return a new StageInfo object. | ||
* TODO: https://github.com/NVIDIA/spark-rapids-tools/issues/1260 | ||
*/ | ||
private def initStageInfo(newStageInfo: StageInfo): StageInfo = { | ||
newStageInfo | ||
private def initStageInfo(newStageInfo: StageInfo): StageInfoStub = { | ||
StageInfoStub.fromStageInfo(newStageInfo) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @amahussein Currently we are reassigning the StageInfo object and updating the StageModel class with the incoming StageInfo object. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mmm, yeah it is possible we do only update to some fields that get changed.
|
||
} | ||
|
||
@WallClock | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2025, 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 org.apache.spark.sql.rapids.tool.util.stubs | ||
|
||
import org.apache.spark.scheduler.StageInfo | ||
import org.apache.spark.sql.rapids.tool.annotation.ToolsReflection | ||
|
||
@ToolsReflection("Common", | ||
"StageInfo is a common class used in all versions of Spark but the constructor signature is" + | ||
" different across versions.") | ||
case class StageInfoStub( | ||
stageId: Int, | ||
attemptId: Int, | ||
name: String, | ||
numTasks: Int, | ||
details: String, | ||
/** When this stage was submitted from the DAGScheduler to a TaskScheduler. */ | ||
submissionTime: Option[Long] = None, | ||
/** Time when the stage completed or when the stage was cancelled. */ | ||
completionTime: Option[Long] = None, | ||
/** If the stage failed, the reason why. */ | ||
failureReason: Option[String] = None) { | ||
|
||
def attemptNumber(): Int = attemptId | ||
} | ||
|
||
object StageInfoStub { | ||
def fromStageInfo(stageInfo: StageInfo): StageInfoStub = { | ||
StageInfoStub( | ||
stageInfo.stageId, | ||
stageInfo.attemptNumber(), | ||
stageInfo.name, | ||
stageInfo.numTasks, | ||
stageInfo.details, | ||
stageInfo.submissionTime, | ||
stageInfo.completionTime, | ||
stageInfo.failureReason) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: new line between 2 defs