VirtualBox

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

最後變更 在這個檔案從62500是 53918,由 vboxsync 提交於 10 年 前

export to OSE

  • 屬性 svn:eol-style 設為 LF
  • 屬性 svn:executable 設為 *
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 1.8 KB
 
1#!/usr/bin/perl
2use strict;
3use warnings;
4use Time::Local;
5
6if ($#ARGV != 0) { die "Give the VirtualBox log file in the command line\n"; }
7open(LOG, $ARGV[0]) or die "Unable to open $ARGV[0] ($!)\n";
8
9# extract log timestamp from VBox.log
10my $line = 0;
11my ($dummy, $start);
12my $continuation = 0;
13while (<LOG>)
14{
15 chomp;
16 $line++;
17 next if not /^.*Log opened|started.*/;
18 if ($line ge 3) { die "Cannot find timestamp in $ARGV[0]\n"; }
19 ($dummy,$start)=split(/.*?Log opened|started /);
20 $continuation = 1 if /^.*Log started.*/;
21 last;
22}
23
24# compute perl time value corresponding to timestamp
25my ($year,$month,$day,$hh,$mm,$ss,$frac);
26if ($start =~ s/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d+)Z/ /) {
27 ($year,$month,$day,$hh,$mm,$ss,$frac) = ($1,$2-1,$3,$4,$5,$6,$7);
28 $frac = "0.$frac";
29}
30else
31{
32 die "Timestamp $start cannot be parsed\n";
33}
34my $logstamp = timegm($ss,$mm,$hh,$day,$month,$year)+$frac;
35
36# print entire log with absolute timestamps in local time
37seek(LOG, 0, 0);
38my $firstrel;
39# Note that for continuations we're slightly inaccurate, as we have no idea
40# about the time difference between the start of the process and the start of
41# logging as documented by the timestamp. Usually a couple milliseconds.
42if ($continuation) { $firstrel = 0; }
43while (<LOG>)
44{
45 my ($time,$msg) = split('(?<=\s)(.*)');
46 my ($h,$m,$s,$ms) = split(':|\.', $time);
47 my $reltime = $h * 3600 + $m * 60 + $s + "0.$ms";
48 if (!defined $firstrel) { $firstrel = $reltime; }
49 $reltime -= $firstrel;
50 my $abstime = $logstamp + $reltime;
51 $ms = int(($abstime - int($abstime)) * 1000);
52 # msec rounding paranoia
53 if ($ms gt 999) { $ms = 999 };
54 $abstime = int($abstime);
55 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($abstime);
56 printf("%04d-%02d-%02d %02d:%02d:%02d.%03d %s\n", $year + 1900, $mon + 1, $mday, $hour, $min, $sec, $ms, $msg);
57}
58close(LOG);
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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