+
+sub read_timing {
+ my ($id) = @_;
+ open (TIMINGS, "<", "$topdir/timings") or return 0;
+ while (<TIMINGS>) {
+ chomp;
+ my ($key, $value) = /^([^=]+)=(.*)/ or next;
+ return $value if $key eq $id;
+ }
+ close (TIMINGS);
+ return 0;
+}
+
+sub write_timing {
+ my ($id, $time) = @_;
+
+ open (NEWTIMINGS, ">", "$topdir/timings.tmp$$") or return;
+
+ if (open (OLDTIMINGS, "<", "$topdir/timings")) {
+ while (<OLDTIMINGS>) {
+ if (my ($key, $value) = /^([^=]+)=(.*)/) {
+ next if $key eq $id;
+ }
+ print NEWTIMINGS $_;
+ }
+ close (OLDTIMINGS);
+ }
+
+ print NEWTIMINGS "$id=$time\n";
+ close (NEWTIMINGS);
+
+ rename ("$topdir/timings.tmp$$", "$topdir/timings");
+}
+
+sub fail {
+ die "Build failed, refer to:\n\t$topdir/$logfile\nfor details.\n";
+}