ENH: Added XSL script to convert DocBook to MarkDown
[freefoam.git] / bin / freefoam-graphExecTime.py.in
blob89dc8678a2d6bda1f3e14d6d5fbee8dabd580c28
1 #!@PYTHON_EXECUTABLE@
2 #-------------------------------------------------------------------------------
3 # ______ _ ____ __ __
4 # | ____| _| |_ / __ \ /\ | \/ |
5 # | |__ _ __ ___ ___ / \| | | | / \ | \ / |
6 # | __| '__/ _ \/ _ ( (| |) ) | | |/ /\ \ | |\/| |
7 # | | | | | __/ __/\_ _/| |__| / ____ \| | | |
8 # |_| |_| \___|\___| |_| \____/_/ \_\_| |_|
10 # FreeFOAM: The Cross-Platform CFD Toolkit
12 # Copyright (C) 2008-2010 Michael Wild <themiwi@users.sf.net>
13 # Gerber van der Graaf <gerber_graaf@users.sf.net>
14 #-------------------------------------------------------------------------------
15 # License
16 # This file is part of FreeFOAM.
18 # FreeFOAM is free software; you can redistribute it and/or modify it
19 # under the terms of the GNU General Public License as published by the
20 # Free Software Foundation; either version 2 of the License, or (at your
21 # option) any later version.
23 # FreeFOAM is distributed in the hope that it will be useful, but WITHOUT
24 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
26 # for more details.
28 # You should have received a copy of the GNU General Public License
29 # along with FreeFOAM; if not, write to the Free Software Foundation,
30 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 # Script
33 # freefoam-graphExecTime
35 # Description
36 # This utility computes the time used per iteration in seconds and writes
37 # it to the file 'executionTime.dat' in TecPlot format.
38 #------------------------------------------------------------------------------
40 """Usage: freefoam@PY_SCRIPT_SUFFIX@ graphExecTime [-h, -help] <logFile>
42 This utility computes the time used per iteration in seconds and writes it to
43 the file 'executionTime.dat' in TecPlot format.
45 Options
46 -------
47 <logFile> The log file from which to extract the data.
48 -h, -help Display this help message.
50 """
52 # want to be future proof
53 from FreeFOAM.compat import *
55 import sys
56 import os.path
57 import re
59 if len(sys.argv[1:]) != 1:
60 sys.stderr.write('Error: Require a log file as argument\n')
61 sys.stderr.write(__doc__+'\n')
62 sys.exit(1)
64 if sys.argv[1] == '-h' or sys.argv[1] == '-help':
65 print(__doc__)
66 sys.exit(0)
68 logFile = sys.argv[1]
69 if not os.path.isfile(logFile):
70 sys.stderr.write('Error: no such file')
71 sys.exit(1)
73 # parse the execution times from the log file and compute differences
74 regex = re.compile(r'ExecutionTime\s+=\s+(?P<time>\S+)')
75 tprev = 0
76 dt = []
77 for l in open(logFile, 'rt'):
78 m = regex.match(l)
79 if m:
80 t = float(m.group('time'))
81 dt.append(t-tprev)
82 tprev = t
84 # write file header
85 outFile = open('ExecutionTime.dat', 'wt')
86 outFile.write("""Solver Performance
87 iterations
88 time/iteration
89 0 0
90 0 0
92 """)
94 # write data
95 if len(dt) > 0:
96 outFile.write("""time
99 """%len(dt))
101 for i, v in enumerate(dt):
102 outFile.write('%d %g\n'%(i+1, v))
104 outFile.close()
106 # ------------------- vim: set sw=3 sts=3 ft=python et: ------------ end-of-file