-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtimes_to_chain.py
85 lines (72 loc) · 2.38 KB
/
times_to_chain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/python
# Usage: ./times_to_chain.py TIMES_FILE.times
# Get modules
import sys
import os
import math
# Get input file name from command line and name output file
inFileName = sys.argv[1]
movieFileName = inFileName[:-6] + "-chain.mpg"
# Open input file
inFile = open(inFileName, 'r')
# Read file into list of lines
lines = inFile.readlines()
# Find maximum number of leading zeroes so the "cat" command sorts in the right order
maxPadding = int(math.log(len(lines),10))
# Make lists for values and the output file's name
values = []
outFileName = []
# Get rid of comment lines
toKill = []
for i in range(len(lines)):
tokens = lines[i].split()
if (tokens[0] == '#'):
toKill.append(i)
toKill.reverse()
for i in toKill:
del lines[i]
# Loop over lines
for i in range(len(lines)):
# Tokenize
tokens = lines[i].split()
# Get the number of tasks
nPEs = len(tokens)
# Figure out how many leading zeroes must be added
if (i == 0):
padding = 0
else:
padding = int( math.log( i, 10))
# Add nessesary zeroes
zeroes = ""
for k in range(maxPadding - padding):
zeroes = zeroes + str(0)
# Name and open a file for the output of a frame
outFileName.append(zeroes + str(i) + ".crv")
outFile = open(outFileName[i], 'w')
# Write out task number and coresponding time value, store time in values
for j in range(len(tokens)):
outFile.write(str(j) + "\t" + tokens[j] + "\n")
values.append(float(tokens[j]))
# Close this particular file
outFile.close()
# Sort values and get max and min (outlier safe)
values.sort()
maxVal = values[ 99 * len(values) / 100 ]
minVal = values[ len(values) / 100 ]
# Write gnuplot command files to make pngs
for i in range(len(lines)):
gnuplotFile = open('tmp.gnuplot', 'w')
gnuplotFile.write("set terminal png ; set xrange [0:" + str(nPEs) + "]; set yrange[" + str(minVal) + ":" + str(maxVal) + "]; \n")
gnuplotFile.write("plot '" + outFileName[i] + "' using 1:2 with lp \n")
gnuplotFile.close()
# Run gnuplot
os.system("gnuplot tmp.gnuplot > " + outFileName[i] + ".png")
# Convert png to ppm
os.system("pngtopnm " + outFileName[i] + ".png > " + outFileName[i] + ".ppm ")
# Make the movie
os.system("cat *.ppm | ppmtoy4m -S 420jpeg | mpeg2enc --format 3 --video-bitrate 5000 --motion-search-radius 32 --no-constraints -o " + movieFileName)
# clean up
os.system("rm *.crv")
os.system("rm *.png")
os.system("rm *.ppm")
os.system("rm tmp.gnuplot")