[Swift-commit] r7433 - in trunk: . bin

davidk at ci.uchicago.edu davidk at ci.uchicago.edu
Tue Dec 17 12:13:19 CST 2013


Author: davidk
Date: 2013-12-17 12:13:18 -0600 (Tue, 17 Dec 2013)
New Revision: 7433

Added:
   trunk/bin/swiftdebug
Modified:
   trunk/build.xml
Log:
Start of a log analyzer/debugger
The basic framework - get log from a run directory, handle multi-line log entries as one entry, reformat timestamps, remove log4j log levels, search for keywords


Added: trunk/bin/swiftdebug
===================================================================
--- trunk/bin/swiftdebug	                        (rev 0)
+++ trunk/bin/swiftdebug	2013-12-17 18:13:18 UTC (rev 7433)
@@ -0,0 +1,71 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+use File::Basename;
+
+# Print basic usage info
+sub usage() {
+   &crash("Usage: $0 <logdir>");
+}
+
+# Print error message and exit
+sub crash() {
+   print STDERR "@_\n";
+   exit(1);
+}
+
+# Check usage
+if ( !$ARGV[0] ) {
+   &usage();
+}
+
+# Given a Swift log entry, decide if we want to it or not
+sub processLogEntry() {
+   (my $date, my $time, my $loglevel, my $class, my $message) = split(/\s+/, $_[0], 5);
+   $time = (split(',', $time))[0];
+   my @keywords_to_keep= ("VERSION", "ARGUMENTS", "SWIFT_CONFIGURATION", "SITES:", "TC:",
+                          "file:", "Using tc.data:");
+   foreach my $keyword(@keywords_to_keep) {
+      if( $message =~ m/$keyword/ ) {
+      # if( grep /$keyword/, @messageArray ) {
+         print "$time $message";
+         last;
+      }
+   }
+}
+
+# Return true if input string starts with a date stamp
+sub hasDateStamp() {
+   my $input = $_[0];
+   if ( $input =~ m/^\d{4}-\d{2}-\d{2}/ ) { 
+      return 1;
+   } 
+   return 0;
+}
+
+# Verify $run_directory
+my $run_directory = $ARGV[0];
+if ( ! -d "$run_directory" ) {
+   &crash("Directory $run_directory does not exist!");
+}
+
+# Open Swift log
+my $swift_log_name = "$run_directory/" . basename($run_directory) . ".log";
+open(SWIFTLOG, $swift_log_name) || &crash("Unable to open log file $swift_log_name");
+
+# Parse Swift log
+my @multiline_entry = ();
+my $previous_line = "";
+
+# Parse each log entry, figure out if they're multiline entries or not
+while(my $line = <SWIFTLOG>) {
+   if ( &hasDateStamp($line) ) {
+      if ( &hasDateStamp($previous_line) ) {
+         &processLogEntry($previous_line);
+      }
+      $previous_line = $line;
+   } else {
+      $previous_line .= "$line";
+   }
+}


Property changes on: trunk/bin/swiftdebug
___________________________________________________________________
Added: svn:executable
   + *

Modified: trunk/build.xml
===================================================================
--- trunk/build.xml	2013-12-15 01:38:32 UTC (rev 7432)
+++ trunk/build.xml	2013-12-17 18:13:18 UTC (rev 7433)
@@ -91,6 +91,7 @@
                                 <include name="prop2scs.pl"/>
 				<include name="start-coaster-service"/>
 				<include name="stop-coaster-service"/>
+                                <include name="swiftdebug"/>
 				<include name="swiftrun"/>
 				<include name="swift-plot-log"/>
                                 <include name="swift-service"/>




More information about the Swift-commit mailing list