Search in sources :

Example 1 with Graph

use of org.apache.tez.dag.utils.Graph in project tez by apache.

the class Utils method generateDAGVizFile.

public static void generateDAGVizFile(DagInfo dagInfo, String fileName, @Nullable List<String> criticalVertices) throws IOException {
    Graph graph = new Graph(sanitizeLabelForViz(dagInfo.getName()));
    for (VertexInfo v : dagInfo.getVertices()) {
        String nodeLabel = sanitizeLabelForViz(v.getVertexName()) + "[" + getShortClassName(v.getProcessorClassName() + ", tasks=" + v.getTasks().size() + ", time=" + v.getTimeTaken() + " ms]");
        Graph.Node n = graph.newNode(sanitizeLabelForViz(v.getVertexName()), nodeLabel);
        boolean criticalVertex = (criticalVertices != null) ? criticalVertices.contains(v.getVertexName()) : false;
        if (criticalVertex) {
            n.setColor("red");
        }
        for (AdditionalInputOutputDetails input : v.getAdditionalInputInfoList()) {
            Graph.Node inputNode = graph.getNode(sanitizeLabelForViz(v.getVertexName()) + "_" + sanitizeLabelForViz(input.getName()));
            inputNode.setLabel(sanitizeLabelForViz(v.getVertexName()) + "[" + sanitizeLabelForViz(input.getName()) + "]");
            inputNode.setShape("box");
            inputNode.addEdge(n, "Input name=" + input.getName() + " [inputClass=" + getShortClassName(input.getClazz()) + ", initializer=" + getShortClassName(input.getInitializer()) + "]");
        }
        for (AdditionalInputOutputDetails output : v.getAdditionalOutputInfoList()) {
            Graph.Node outputNode = graph.getNode(sanitizeLabelForViz(v.getVertexName()) + "_" + sanitizeLabelForViz(output.getName()));
            outputNode.setLabel(sanitizeLabelForViz(v.getVertexName()) + "[" + sanitizeLabelForViz(output.getName()) + "]");
            outputNode.setShape("box");
            n.addEdge(outputNode, "Output name=" + output.getName() + " [outputClass=" + getShortClassName(output.getClazz()) + ", committer=" + getShortClassName(output.getInitializer()) + "]");
        }
    }
    for (EdgeInfo e : dagInfo.getEdges()) {
        Graph.Node n = graph.getNode(sanitizeLabelForViz(e.getInputVertexName()));
        n.addEdge(graph.getNode(sanitizeLabelForViz(e.getOutputVertexName())), "[input=" + getShortClassName(e.getEdgeSourceClass()) + ", output=" + getShortClassName(e.getEdgeDestinationClass()) + ", dataMovement=" + e.getDataMovementType().trim() + "]");
    }
    graph.save(fileName);
}
Also used : Graph(org.apache.tez.dag.utils.Graph) AdditionalInputOutputDetails(org.apache.tez.history.parser.datamodel.AdditionalInputOutputDetails) VertexInfo(org.apache.tez.history.parser.datamodel.VertexInfo) EdgeInfo(org.apache.tez.history.parser.datamodel.EdgeInfo)

Example 2 with Graph

use of org.apache.tez.dag.utils.Graph in project tez by apache.

the class DAGAppMaster method generateDAGVizFile.

private void generateDAGVizFile(TezDAGID dagId, DAGPlan dagPB, String[] logDirs) {
    Graph graph = new Graph(sanitizeLabelForViz(dagPB.getName()));
    for (VertexPlan v : dagPB.getVertexList()) {
        String nodeLabel = sanitizeLabelForViz(v.getName()) + "[" + getShortClassName(v.getProcessorDescriptor().getClassName() + "]");
        Graph.Node n = graph.newNode(sanitizeLabelForViz(v.getName()), nodeLabel);
        for (DAGProtos.RootInputLeafOutputProto input : v.getInputsList()) {
            Graph.Node inputNode = graph.getNode(sanitizeLabelForViz(v.getName()) + "_" + sanitizeLabelForViz(input.getName()));
            inputNode.setLabel(sanitizeLabelForViz(v.getName()) + "[" + sanitizeLabelForViz(input.getName()) + "]");
            inputNode.setShape("box");
            inputNode.addEdge(n, "Input" + " [inputClass=" + getShortClassName(input.getIODescriptor().getClassName()) + ", initializer=" + getShortClassName(input.getControllerDescriptor().getClassName()) + "]");
        }
        for (DAGProtos.RootInputLeafOutputProto output : v.getOutputsList()) {
            Graph.Node outputNode = graph.getNode(sanitizeLabelForViz(v.getName()) + "_" + sanitizeLabelForViz(output.getName()));
            outputNode.setLabel(sanitizeLabelForViz(v.getName()) + "[" + sanitizeLabelForViz(output.getName()) + "]");
            outputNode.setShape("box");
            n.addEdge(outputNode, "Output" + " [outputClass=" + getShortClassName(output.getIODescriptor().getClassName()) + ", committer=" + getShortClassName(output.getControllerDescriptor().getClassName()) + "]");
        }
    }
    for (DAGProtos.EdgePlan e : dagPB.getEdgeList()) {
        Graph.Node n = graph.getNode(sanitizeLabelForViz(e.getInputVertexName()));
        n.addEdge(graph.getNode(sanitizeLabelForViz(e.getOutputVertexName())), "[" + "input=" + getShortClassName(e.getEdgeSource().getClassName()) + ", output=" + getShortClassName(e.getEdgeDestination().getClassName()) + ", dataMovement=" + e.getDataMovementType().name().trim() + ", schedulingType=" + e.getSchedulingType().name().trim() + "]");
    }
    String outputFile = "";
    if (logDirs != null && logDirs.length != 0) {
        outputFile += logDirs[0];
        outputFile += File.separator;
    }
    outputFile += dagId.toString() + ".dot";
    try {
        LOG.info("Generating DAG graphviz file" + ", dagId=" + dagId.toString() + ", filePath=" + outputFile);
        graph.save(outputFile);
    } catch (Exception e) {
        LOG.warn("Error occurred when trying to save graph structure" + " for dag " + dagId.toString(), e);
    }
}
Also used : VertexPlan(org.apache.tez.dag.api.records.DAGProtos.VertexPlan) Graph(org.apache.tez.dag.utils.Graph) DAGProtos(org.apache.tez.dag.api.records.DAGProtos) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) JSONException(org.codehaus.jettison.json.JSONException) URISyntaxException(java.net.URISyntaxException) FileNotFoundException(java.io.FileNotFoundException) TezException(org.apache.tez.dag.api.TezException) ServiceStateException(org.apache.hadoop.service.ServiceStateException)

Aggregations

Graph (org.apache.tez.dag.utils.Graph)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 ServiceStateException (org.apache.hadoop.service.ServiceStateException)1 TezException (org.apache.tez.dag.api.TezException)1 TezUncheckedException (org.apache.tez.dag.api.TezUncheckedException)1 DAGProtos (org.apache.tez.dag.api.records.DAGProtos)1 VertexPlan (org.apache.tez.dag.api.records.DAGProtos.VertexPlan)1 AdditionalInputOutputDetails (org.apache.tez.history.parser.datamodel.AdditionalInputOutputDetails)1 EdgeInfo (org.apache.tez.history.parser.datamodel.EdgeInfo)1 VertexInfo (org.apache.tez.history.parser.datamodel.VertexInfo)1 JSONException (org.codehaus.jettison.json.JSONException)1