Report times found in a build log.
durations.py is a Python script that reports the length of time each triggered shell action ran sorted longest to shortest. It can be used to identify slow areas of the build which may be candidates for optimization.
python durations.py [ --help ] filename.xml
python durations.py makelog.xml
0:03:32.864556 targ2 src/cmd/t2 0:01:33.858293 targ3 src/cmd/t3 0:01:04.085014 targ4 src/cmd/t4 0:00:33.030622 targ1 src/cmd/t1 0:00:00.695936 ca.o src/cmd/t1 0:00:00.693648 cc.o src/cmd/t3 0:00:00.691520 cb.o src/cmd/t2 0:00:00.675594 b.o src/cmd/t3 0:00:00.660692 a.o src/cmd/t3 0:00:00.615385 a.o src/cmd/t2 0:00:00.612100 a.o src/cmd/t1 0:00:00.608247 b.o src/cmd/t2 0:00:00.121718 /home/richb/bin/targ4 src/cmd/t4 0:00:00.063113 ../../../bin/targ2 src/cmd/t2 0:00:00.061131 ../../../bin/targ3 src/cmd/t3 0:00:00.061090 ../../../bin/targ1 src/cmd/t1 0:00:00.044407 ../../../bin src/cmd/t2 0:00:00.042788 ../../../bin src/cmd/t1 0:00:00.041787 /home/richb/bin src/cmd/t4 0:00:00.041720 ../../../bin src/cmd/t3
The XML build log is parsed and stored in the
variable as an element tree structure. The tree is pre-processed, adding
a few attributes for later use: the parent node is saved to allow access
to parent elements in the tree, and starting, ending, and duration time
attribute data is saved on each target element. The script then iterates
over all leaf target elements in the tree (that is, all targets not
containing a child makelog element). The iteration is in reverse order of
duration, that is from longest to shortest. For each of these targets,
the duration, target name, and target directory relative to the vpath is
printed. The vpath itself is obtained from the build log. Building block
routines handling time and viewpath operations are imported from
nmreport.py to allow reuse across multiple scripts.