VirtualBox

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

Last change on this file was 98103, checked in by vboxsync, 16 months ago

Copyright year updates by scm.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use