VirtualBox

source: vbox/trunk/tools/bin/vboxlogabstime.pl@ 78394

Last change on this file since 78394 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1#!/usr/bin/perl
2# $Id: vboxlogabstime.pl 76553 2019-01-01 01:45:53Z vboxsync $
3## @file
4# ???
5#
6
7#
8# Copyright (C) 2006-2019 Oracle Corporation
9#
10# This file is part of VirtualBox Open Source Edition (OSE), as
11# available from http://www.virtualbox.org. This file is free software;
12# you can redistribute it and/or modify it under the terms of the GNU
13# General Public License (GPL) as published by the Free Software
14# Foundation, in version 2 as it comes in the "COPYING" file of the
15# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17#
18
19use strict;
20use warnings;
21use Time::Local;
22
23if ($#ARGV != 0) { die "Give the VirtualBox log file in the command line\n"; }
24open(LOG, $ARGV[0]) or die "Unable to open $ARGV[0] ($!)\n";
25
26# extract log timestamp from VBox.log
27my $line = 0;
28my ($dummy, $start);
29my $continuation = 0;
30while (<LOG>)
31{
32 chomp;
33 $line++;
34 next if not /^.*Log opened|started.*/;
35 if ($line ge 3) { die "Cannot find timestamp in $ARGV[0]\n"; }
36 ($dummy,$start)=split(/.*?Log opened|started /);
37 $continuation = 1 if /^.*Log started.*/;
38 last;
39}
40
41# compute perl time value corresponding to timestamp
42my ($year,$month,$day,$hh,$mm,$ss,$frac);
43if ($start =~ s/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d+)Z/ /) {
44 ($year,$month,$day,$hh,$mm,$ss,$frac) = ($1,$2-1,$3,$4,$5,$6,$7);
45 $frac = "0.$frac";
46}
47else
48{
49 die "Timestamp $start cannot be parsed\n";
50}
51my $logstamp = timegm($ss,$mm,$hh,$day,$month,$year)+$frac;
52
53# print entire log with absolute timestamps in local time
54seek(LOG, 0, 0);
55my $firstrel;
56# Note that for continuations we're slightly inaccurate, as we have no idea
57# about the time difference between the start of the process and the start of
58# logging as documented by the timestamp. Usually a couple milliseconds.
59if ($continuation) { $firstrel = 0; }
60while (<LOG>)
61{
62 my ($time,$msg) = split('(?<=\s)(.*)');
63 my ($h,$m,$s,$ms) = split(':|\.', $time);
64 my $reltime = $h * 3600 + $m * 60 + $s + "0.$ms";
65 if (!defined $firstrel) { $firstrel = $reltime; }
66 $reltime -= $firstrel;
67 my $abstime = $logstamp + $reltime;
68 $ms = int(($abstime - int($abstime)) * 1000);
69 # msec rounding paranoia
70 if ($ms gt 999) { $ms = 999 };
71 $abstime = int($abstime);
72 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($abstime);
73 printf("%04d-%02d-%02d %02d:%02d:%02d.%03d %s\n", $year + 1900, $mon + 1, $mday, $hour, $min, $sec, $ms, $msg);
74}
75close(LOG);
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette