from edu.uoregon.tau.perfexplorer.glue import * from edu.uoregon.tau.perfdmf import * from java.util import * from java.lang import * import java.util.HashMap as HashMap import java.util.ArrayList as ArrayList import java.util.HashSet as HashSet import java.io.File as File import org.jfree.chart.ChartUtilities as ChartUtilities import java.util.concurrent.TimeUnit as TimeUnit import java.util.Collections as Collections import edu.uoregon.tau.perfexplorer.common.RMISortableIntervalEvent as RMISortableIntervalEvent import edu.uoregon.tau.perfdmf.DataSource as DataSource True = 1 False = 0 app = 'lra_csv' db = 'phylanx_test' experimentDateKey = 'Experiment' experimentDate = 'Unknown' def processTrial(trial): metric = "TIME" type = AbstractResult.EXCLUSIVE #Create a base trial result firsttrial=TrialResult(trial, None, None, None, False) firsttrial.setIgnoreWarnings(True) #Remove all the helper threads (those with the listed events) # excludeRankWithEvents=ArrayList() # excludeRankWithEvents.add("[SAMPLE] __epoll_wait_nocancel [{} {0}]") # excludeRankWithEvents.add("[SAMPLE] __pthread_cond_wait [{} {0}]") # selopt = SelectRanksByEventsOperation(firsttrial,excludeRankWithEvents,True) # seldata = selopt.processData().get(0) #Exclude the top level timer exeopt=ExtractEventOperation(firsttrial,".TAU application") exeopt.setExclude(True) exedata=exeopt.processData().get(0) #Take the mean of the processed input mR=TrialMeanResult(exedata,False) #Treat absent as 0 will eventually be the 2nd argument here #Show only the top events topX = TopXEvents(mR,metric,type,15) reduced = topX.processData().get(0) # inputs.add(0,topX.processData().get(0)) # then, extract those events from the actual data tmpEvents = ArrayList(reduced.getEvents()) reducer = ExtractEventOperation(exedata, tmpEvents) reduced = reducer.processData().get(0) # cluster the data theta = .9 numThreads=firsttrial.getThreads().size() print("trial size: ",numThreads) if numThreads <=11: print("small run") theta=.4 print("theta: ",theta) clusterer = DBSCANOperation(reduced, metric, type, theta) clusterResult = clusterer.processData() k = str(clusterResult.get(0).getThreads().size()) clusters = ArrayList() print "Estimated value for k:", k if k > 0: clusterIDs = clusterResult.get(4) # split the trial into the clusters splitter = SplitTrialClusters(reduced, clusterResult) clusters = splitter.processData() else: clusters.put(result) if(clusters.size()>1): return (clusters.get(0),clusters.get(1)) return None def loadFromDB(): Utilities.setSession(db) #theConnection = PerfExplorerConnection() #server = PerfExplorerConnection.getConnection(); #Utilities.setSession("phylanx_test") metadata = HashMap() inputs0 = ArrayList() inputs1 = ArrayList() conjoin = " and " # here are the conditions for the selection metadata.put("Application"," = '"+app+"'") #metadata.put("threads"," = '36'") #metadata.put("dataFile"," = 'fishtank'") # metadata.put("trialname"," like '%Med_8_4%'") trials = Utilities.getTrialsFromMetadata(metadata, conjoin) global experimentDate experimentDate = trials.get(trials.size()-2).getMetaData().get(experimentDateKey) for trial in reversed(trials): # get just one event if trial.getMetaData().get(experimentDateKey) == experimentDate: inputTuple=processTrial(trial) if inputTuple is not None: inputs0 .add( inputTuple[0] ) inputs1 .add( inputTuple[1] ) else: break return (inputs0,inputs1) """ def drawGraph(results): # change this to P_WALL_CLOCK_TIME as necessary metric = "TIME" grapher = DrawGraph(results) metrics = HashSet() metrics.add(metric) grapher.setAutoDisplayWindow(False) grapher.setMetrics(metrics) grapher.setLogYAxis(False) grapher.setShowZero(True) grapher.setTitle("Graph of Multiple Trials: " + metric) #grapher.setMetadataField("threads") grapher.setSeriesType(DrawGraph.EVENTNAME) grapher.setUnits(DrawGraph.SECONDS) #grapher.setMetadataField(experimentDateKey) grapher.setCategoryMetadata("threads") grapher.setXAxisLabel("Number of Threads") grapher.setValueType(AbstractResult.INCLUSIVE) grapher.setYAxisLabel("Inclusive " + metric + " (seconds)") grapher.processData() chart = grapher.getChart() pngOut = File(db+"-"+app+"-"+experimentDate+"-scaling.png") #Threaded chart work may result in concurrency issues so wait before saving png. TimeUnit.SECONDS.sleep(1); ChartUtilities.saveChartAsPNG(pngOut, chart, 700, 500); """ def drawAreaGraph(results): # change this to P_WALL_CLOCK_TIME as necessary metric = "TIME" grapher = DrawGraph(results) metrics = HashSet() metrics.add(metric) grapher.setAutoDisplayWindow(False) grapher.setMetrics(metrics) grapher.setLogYAxis(False) grapher.setShowZero(True) grapher.setTitle("Runtime Breakdown for Phylanx: " + metric) grapher.setSeriesType(DrawGraph.EVENTNAME) grapher.setChartType(DrawGraph.STACKEDAREACHART); # for processor count X axis #grapher.setCategoryType(DrawGraph.PROCESSORCOUNT) grapher.setCategoryMetadata("threads") # for trial name X axis #grapher.setCategoryType(DrawGraph.TRIALNAME) # for metadata field on X axis #grapher.setCategoryType(DrawGraph.METADATA) #grapher.setMetadataField("pid") grapher.setXAxisLabel("Processor Count") grapher.setValueType(AbstractResult.EXCLUSIVE) grapher.setYAxisLabel("Fraction of " + metric) grapher.processData() chart = grapher.getChart() pngOut = File(db+"-"+app+"-"+experimentDate+"-area.png") #Threaded chart work may result in concurrency issues so wait before saving png. TimeUnit.SECONDS.sleep(1); ChartUtilities.saveChartAsPNG(pngOut, chart, 700, 500); def drawBarGraph(results, nametag, percent): # change this to P_WALL_CLOCK_TIME as necessary metric = "TIME" grapher = DrawGraph(results) metrics = HashSet() metrics.add(metric) grapher.setAutoDisplayWindow(False) grapher.setMetrics(metrics) grapher.setLogYAxis(False) grapher.setShowZero(True) grapher.setTitle("Runtime Breakdown for Phylanx: " + metric) grapher.setSeriesType(DrawGraph.EVENTNAME) grapher.setChartType(DrawGraph.STACKEDBARCHART); if percent == False: grapher.setUnits(DrawGraph.SECONDS); # for processor count X axis #grapher.setCategoryType(DrawGraph.PROCESSORCOUNT) grapher.setCategoryMetadata("threads") # for trial name X axis #grapher.setCategoryType(DrawGraph.TRIALNAME) # for metadata field on X axis #grapher.setCategoryType(DrawGraph.METADATA) #grapher.setMetadataField("pid") grapher.setXAxisLabel("Processor Count") grapher.setValueType(AbstractResult.EXCLUSIVE) if percent == True: grapher.setYAxisLabel("Fraction of " + metric) else: grapher.setYAxisLabel(metric + ", seconds") grapher.processData() chart = grapher.getChart() pngOut = File(db+"-"+app+"-"+experimentDate+"-"+nametag+"-bar.png") #Threaded chart work may result in concurrency issues so wait before saving png. TimeUnit.SECONDS.sleep(1); ChartUtilities.saveChartAsPNG(pngOut, chart, 800, 600); def main(): print "--------------- JPython test script start ------------" # load the data inputs = loadFromDB() #drawGraph(inputs) #drawAreaGraph(inputs) drawBarGraph(inputs[0],"cluster1",False) drawBarGraph(inputs[1],"cluster2",False) print "---------------- JPython test script end -------------" if __name__ == "__main__": main()