Permalink
Browse files

Fixed Rails 2.2 style logfile parsing.

  • Loading branch information...
1 parent f3969b5 commit 6f39590e7dfed100b66661f9b9798e403aa80ae0 @mmower committed Feb 18, 2009
Showing with 141 additions and 4 deletions.
  1. +20 −1 Info.plist
  2. +65 −1 LogParser.m
  3. +17 −0 NSScanner+SpikeAdditions.h
  4. +25 −0 NSScanner+SpikeAdditions.m
  5. +6 −0 Spike.xcodeproj/project.pbxproj
  6. +8 −2 release_notes.txt
View
@@ -4,6 +4,25 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
+ <key>CFBundleDocumentTypes</key>
+ <array>
+ <dict>
+ <key>CFBundleTypeExtensions</key>
+ <array>
+ <string>log</string>
+ </array>
+ <key>CFBundleTypeName</key>
+ <string>Log File</string>
+ <key>CFBundleTypeRole</key>
+ <string>Viewer</string>
+ <key>LSTypeIsPackage</key>
+ <false/>
+ <key>NSDocumentClass</key>
+ <string>LogDocument</string>
+ <key>NSPersistentStoreTypeKey</key>
+ <string>Binary</string>
+ </dict>
+ </array>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
@@ -19,7 +38,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.0.4</string>
+ <string>1.0.5</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
View
@@ -16,13 +16,17 @@
#import "Parameter.h"
#import "ParsingProgressController.h"
+#import "NSScanner+SpikeAdditions.h"
+
@interface LogParser (PrivateMethods)
- (RailsRequest *)parseRequest:(NSArray *)lines;
- (NSArray *)parseLogLines:(NSArray *)lines;
- (void)scanProcessing:(NSString *)line intoRequest:(RailsRequest *)request;
- (void)scanParameters:(NSString *)line intoRequest:(RailsRequest *)request;
- (void)scanSession:(NSString *)line intoRequest:(RailsRequest *)request;
- (void)scanCompleted:(NSString *)line intoRequest:(RailsRequest *)request;
+- (void)scanCompletedOldFormat:(NSString *)line scanner:(NSScanner *)scanner intoRequest:(RailsRequest *)request;
+- (void)scanCompletedNewFormat:(NSString *)line scanner:(NSScanner *)scanner intoRequest:(RailsRequest *)request;
- (void)scanRender:(NSString *)line intoRequest:(RailsRequest *)request;
- (void)scanFilter:(NSString *)line intoRequest:(RailsRequest *)request;
@end
@@ -174,7 +178,6 @@ - (void)scanSession:(NSString *)line intoRequest:(RailsRequest *)request {
- (void)scanCompleted:(NSString *)line intoRequest:(RailsRequest *)request {
NSScanner *scanner = [NSScanner scannerWithString:line];
float t;
- int n;
[scanner scanString:@"Completed in " intoString:nil];
if( ![scanner scanFloat:&t] ) {
@@ -183,6 +186,18 @@ - (void)scanCompleted:(NSString *)line intoRequest:(RailsRequest *)request {
}
[request setRealTime:t];
+ if( [scanner scanString:@"ms" intoString:nil] ) {
+ [self scanCompletedNewFormat:line scanner:scanner intoRequest:request];
+ } else {
+ [self scanCompletedOldFormat:line scanner:scanner intoRequest:request];
+ }
+}
+
+
+- (void)scanCompletedOldFormat:(NSString *)line scanner:(NSScanner *)scanner intoRequest:(RailsRequest *)request {
+ float t;
+ int n;
+
[scanner scanCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:nil];
[scanner scanString:@"(" intoString:nil];
if( ![scanner scanInt:&n] ) {
@@ -235,6 +250,55 @@ - (void)scanCompleted:(NSString *)line intoRequest:(RailsRequest *)request {
}
+- (void)scanCompletedNewFormat:(NSString *)line scanner:(NSScanner *)scanner intoRequest:(RailsRequest *)request {
+ float t;
+ int n;
+
+
+ [scanner eatWS];
+ [scanner eat:@"("];
+
+ // "View: 8, "
+ if( [scanner detect:@"View:"] ) {
+ [scanner eatWS];
+ [scanner scanFloat:&t];
+ [request setRenderTime:t];
+
+ [scanner eat:@","];
+ [scanner eatWS];
+ }
+
+ if( [scanner detect:@"DB:"] ) {
+ [scanner eatWS];
+ [scanner scanFloat:&t];
+ [request setDbTime:t];
+ }
+
+ // New format is given in millis, convert to (s)
+ [request setRealTime:[request realTime]/1000];
+ [request setRenderTime:[request renderTime]/1000];
+ [request setDbTime:[request dbTime]/1000];
+ // Calculate RPS not given in 2.2 format
+ [request setRps:( 1.0 / [request realTime] )];
+
+ [scanner eat:@")"];
+ [scanner eatWS];
+
+ if( [scanner detect:@"|"] ) {
+ [scanner eatWS];
+ [scanner scanInt:&n];
+ [request setStatus:n];
+ }
+
+ NSRange r1, r2;
+ r1 = [line rangeOfString:@"[" options:NSBackwardsSearch];
+ r2 = [line rangeOfString:@"]" options:NSBackwardsSearch];
+ if( r1.location != NSNotFound && r2.location != NSNotFound ) {
+ [request setUrl:[line substringWithRange:NSMakeRange( r1.location+1, r2.location - r1.location - 1)]];
+ }
+}
+
+
- (void)scanRender:(NSString *)line intoRequest:(RailsRequest *)request {
NSString *render = [line substringFromIndex:10];
View
@@ -0,0 +1,17 @@
+//
+// NSScanner+SpikeAdditions.h
+// Spike
+//
+// Created by Matt Mower on 18/02/2009.
+// Copyright 2009 LucidMac Software. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@interface NSScanner (NSScanner_SpikeAdditions)
+
+- (void)eatWS;
+- (void)eat:(NSString *)string;
+- (BOOL)detect:(NSString *)string;
+
+@end
View
@@ -0,0 +1,25 @@
+//
+// NSScanner+SpikeAdditions.m
+// Spike
+//
+// Created by Matt Mower on 18/02/2009.
+// Copyright 2009 LucidMac Software. All rights reserved.
+//
+
+#import "NSScanner+SpikeAdditions.h"
+
+@implementation NSScanner (NSScanner_SpikeAdditions)
+
+- (void)eatWS {
+ [self scanCharactersFromSet:[NSCharacterSet whitespaceCharacterSet] intoString:nil];
+}
+
+- (void)eat:(NSString *)string {
+ [self scanString:string intoString:nil];
+}
+
+- (BOOL)detect:(NSString *)string {
+ return [self scanString:string intoString:nil];
+}
+
+@end
@@ -19,6 +19,7 @@
C92614390F4C32AE00218378 /* ParsingProgressController.m in Sources */ = {isa = PBXBuildFile; fileRef = C92614380F4C32AE00218378 /* ParsingProgressController.m */; };
C92614830F4C45D800218378 /* LogDocument.xib in Resources */ = {isa = PBXBuildFile; fileRef = C926147F0F4C45D800218378 /* LogDocument.xib */; };
C92614840F4C45D800218378 /* ParsingProgress.xib in Resources */ = {isa = PBXBuildFile; fileRef = C92614810F4C45D800218378 /* ParsingProgress.xib */; };
+ C92614C10F4C591900218378 /* NSScanner+SpikeAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = C92614C00F4C591900218378 /* NSScanner+SpikeAdditions.m */; };
C9592FB60F483CF5004A49FA /* RequestDetails.xib in Resources */ = {isa = PBXBuildFile; fileRef = C9592FB40F483CF5004A49FA /* RequestDetails.xib */; };
C9592FBB0F483D45004A49FA /* TDParseKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9592FBA0F483D45004A49FA /* TDParseKit.framework */; };
C9592FBE0F483D4B004A49FA /* TDParseKit.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = C9592FBA0F483D45004A49FA /* TDParseKit.framework */; };
@@ -73,6 +74,8 @@
C92614380F4C32AE00218378 /* ParsingProgressController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ParsingProgressController.m; sourceTree = "<group>"; };
C92614800F4C45D800218378 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/LogDocument.xib; sourceTree = "<group>"; };
C92614820F4C45D800218378 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/ParsingProgress.xib; sourceTree = "<group>"; };
+ C92614BF0F4C591900218378 /* NSScanner+SpikeAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSScanner+SpikeAdditions.h"; sourceTree = "<group>"; };
+ C92614C00F4C591900218378 /* NSScanner+SpikeAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSScanner+SpikeAdditions.m"; sourceTree = "<group>"; };
C9592FB50F483CF5004A49FA /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/RequestDetails.xib; sourceTree = "<group>"; };
C9592FBA0F483D45004A49FA /* TDParseKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TDParseKit.framework; path = frameworks/TDParseKit.framework; sourceTree = "<group>"; };
C95930680F4871B0004A49FA /* HaltedColumnTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HaltedColumnTransformer.h; sourceTree = "<group>"; };
@@ -139,6 +142,8 @@
C92613A80F4C24FF00218378 /* LogDocument.m */,
C92614370F4C32AE00218378 /* ParsingProgressController.h */,
C92614380F4C32AE00218378 /* ParsingProgressController.m */,
+ C92614BF0F4C591900218378 /* NSScanner+SpikeAdditions.h */,
+ C92614C00F4C591900218378 /* NSScanner+SpikeAdditions.m */,
);
name = Classes;
sourceTree = "<group>";
@@ -291,6 +296,7 @@
C921DB8A0F4AE1D8008A2505 /* ParamParser.m in Sources */,
C92613A90F4C24FF00218378 /* LogDocument.m in Sources */,
C92614390F4C32AE00218378 /* ParsingProgressController.m in Sources */,
+ C92614C10F4C591900218378 /* NSScanner+SpikeAdditions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -1,7 +1,13 @@
-h1. <span>2009-02-17</span> Release 1.0.3
+h1. <span>2009-02-18</span> Release 1.0.5
+
+Spike is now document based, open multipe log files
+Spike supports Rails 2.2 style logfiles
+
+h1. <span>2009-02-17</span> Release 1.0.4
Improved main UI
-Small improvements to parser
+Small improvements to parser, trap some errors
+Shiny new icon!
h1. <span>2009-02-16</span> Release 1.0.2

0 comments on commit 6f39590

Please sign in to comment.