Skip to content
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

Add physical plan to the dot file as the graph label #2640

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,16 @@ class CollectInformation(apps: ArrayBuffer[ApplicationInfo],
list += row.getLong(1) -> row.getLong(2)
}

for ((sqlID, planInfo) <- app.sqlPlan) {
val sqlPlansMap = app.sqlPlan.map { case (sqlId, sparkPlanInfo) =>
sqlId -> ((sparkPlanInfo, app.physicalPlanDescription(sqlId)))
}
for ((sqlID, (planInfo, physicalPlan)) <- sqlPlansMap) {
val dotFileWriter = new ToolTextFileWriter(outputDirectory,
s"${app.appId}-query-$sqlID.dot")
try {
val metrics = map.getOrElse(sqlID, Seq.empty).toMap
GenerateDot.generateDotGraph(
QueryPlanWithMetrics(planInfo, metrics), None, dotFileWriter, sqlID + ".dot")
GenerateDot.generateDotGraph(QueryPlanWithMetrics(planInfo, metrics),
physicalPlan, None, dotFileWriter, sqlID, app.appId)
} finally {
dotFileWriter.close()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ object GenerateDot {
*
* @param plan First query plan and metrics
* @param comparisonPlan Optional second query plan and metrics
* @param filename Filename to write dot graph to
* @param sqlId id of the SQL query for the dot graph
* @param appId Spark application Id
*/
def generateDotGraph(
plan: QueryPlanWithMetrics,
comparisonPlan: Option[QueryPlanWithMetrics],
fileWriter: ToolTextFileWriter,
filename: String): Unit = {

plan: QueryPlanWithMetrics,
physicalPlanString: String,
comparisonPlan: Option[QueryPlanWithMetrics],
fileWriter: ToolTextFileWriter,
sqlId: Long,
appId: String
): Unit = {

val fileName = s"$sqlId.dot"
var nextId = 1

def isGpuPlan(plan: SparkPlanInfo): Boolean = {
Expand Down Expand Up @@ -166,8 +171,25 @@ object GenerateDot {
}
}

val leftAlignedLabel =
s"""
|Application: $appId
|Query: $sqlId
|
|$physicalPlanString"""
.stripMargin
.replace("\n", "\\l")

// write the dot graph to a file
fileWriter.write("digraph G {\n")
fileWriter.write(
s"""digraph G {
|
|label="$leftAlignedLabel"
|labelloc=b
|fontname=Courier
|
|""".stripMargin)

writeGraph(fileWriter, plan, comparisonPlan.getOrElse(plan), 0)
fileWriter.write("}\n")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class GenerateDotSuite extends FunSuite with BeforeAndAfterAll with Logging {
source.close()
}
}
assert(hashAggCount === 2)
// 2 node labels + 1 graph label
assert(hashAggCount === 3)
}
}
}
Expand Down