from edu.uoregon.tau.perfexplorer.glue import * from edu.uoregon.tau.perfdmf import * from java.util import * from java.lang import * import json import gzip True = 1 False = 0 def loadFile(fileName): # load the trial files = [] files.append(fileName) if fileName.endswith("ppk"): input = DataSourceResult(DataSourceResult.PPK, files, False) elif fileName.endswith("gprof"): input = DataSourceResult(DataSourceResult.GPROF, files, False) elif fileName.endswith("xml") or fileName.endswith("xml.gz"): input = DataSourceResult(DataSourceResult.SNAP, files, False) else: input = DataSourceResult(DataSourceResult.TAUPROFILE, files, False) return input def loadFromFiles(): inputs = ArrayList() inputs.add(loadFile("tauprofile.xml")) return inputs.get(0) def dumpNode(myfile,node,parent,parentPath,result,metric): comma = False for key, value in node.iteritems(): if comma: myfile.write(",") currentPath = key if parentPath != "": currentPath = parentPath + " => " + key myfile.write("{\"name\":") myfile.write("\"" + key + "\", \"size\":") myfile.write(str(result.getInclusive(0, currentPath, metric))) if value != {}: myfile.write(", \"children\": [") dumpNode(myfile,value,key,currentPath,result,metric) myfile.write("]") myfile.write("}") comma = True """ if comma: myfile.write(",") myfile.write("{\"name\":") myfile.write("\"" + parent + "\", \"size\":") myfile.write(str(result.getExclusive(0, parentPath, metric))) myfile.write("}\n") """ def main(): print "--------------- JPython test script start ------------" # load the data t = 0 raw = loadFromFiles() raw.setIgnoreWarnings(True) statmaker = BasicStatisticsOperation(raw, False) result = statmaker.processData().get(BasicStatisticsOperation.MEAN) mainEvent = result.getMainEvent() metric = result.getTimeMetric() # build the callpath tree callpathOperation = ExtractCallpathEventOperation(result) callpath = callpathOperation.processData().get(0) tree = {} for e in callpath.getEvents(): nodes = e.split(" => ") current = tree for n in nodes: if not n in current: current[str(n)] = {} current = current[str(n)] mydata = open("profile.json",'w') dumpNode(mydata,tree,"","",result,metric) mydata.close() print "---------------- JPython test script end -------------" if __name__ == "__main__": main()