Permalink
Browse files

Spike can now natively handle zipped logs.

  • Loading branch information...
1 parent 6f39590 commit 42c61e59882b5b524432c5d5e1354ccf20044cab @mmower committed Feb 18, 2009
View
20 English.lproj/ParsingProgress.xib
@@ -8,6 +8,7 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <integer value="2"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -44,7 +45,7 @@
<nil key="NSViewClass"/>
<string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string>
<object class="NSView" key="NSWindowView" id="789084891">
- <nil key="NSNextResponder"/>
+ <reference key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -61,7 +62,7 @@
<object class="NSTextField" id="747799247">
<reference key="NSNextResponder" ref="789084891"/>
<int key="NSvFlags">268</int>
- <string key="NSFrame">{{17, 75}, {110, 17}}</string>
+ <string key="NSFrame">{{17, 75}, {292, 17}}</string>
<reference key="NSSuperview" ref="789084891"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="576475716">
@@ -96,6 +97,7 @@
</object>
</object>
<string key="NSFrameSize">{488, 111}</string>
+ <reference key="NSSuperview"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1920, 1178}}</string>
<string key="NSMaxSize">{3.40282e+38, 3.40282e+38}</string>
@@ -128,6 +130,14 @@
</object>
<int key="connectionID">13</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">statusField</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="747799247"/>
+ </object>
+ <int key="connectionID">14</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -248,7 +258,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">13</int>
+ <int key="maxID">14</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -262,11 +272,13 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<string>indicator</string>
<string>panel</string>
+ <string>statusField</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSProgressIndicator</string>
<string>NSPanel</string>
+ <string>NSTextField</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
@@ -277,7 +289,7 @@
</object>
</object>
<int key="IBDocument.localizationMode">0</int>
- <string key="IBDocument.LastKnownRelativeProjectPath">Spike.xcodeproj</string>
+ <string key="IBDocument.LastKnownRelativeProjectPath">../Spike.xcodeproj</string>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
</data>
</archive>
View
16 Info.plist
@@ -22,6 +22,22 @@
<key>NSPersistentStoreTypeKey</key>
<string>Binary</string>
</dict>
+ <dict>
+ <key>CFBundleTypeExtensions</key>
+ <array>
+ <string>gz</string>
+ </array>
+ <key>CFBundleTypeName</key>
+ <string>Compressed Log File</string>
+ <key>CFBundleTypeRole</key>
+ <string>Editor</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>
View
23 LogDocument.m
@@ -11,12 +11,12 @@
#import "AppController.h"
#import "LogParser.h"
#import "RailsRequest.h"
-// #import "RequestDetailsController.h"
static NSString *SearchToolbarItemIdentifier = @"spike.searchField";
@interface LogDocument (PrivateMethods)
- (void)parseLogFile:(NSData *)data;
+- (NSData *)gunzipedDataFromData:(NSData *)compressedData;
@end
@implementation LogDocument
@@ -76,14 +76,29 @@ - (IBAction)removeSimilarRequests:(id)sender {
#pragma mark Implementation
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError {
- [NSThread detachNewThreadSelector:@selector(parseLogFile:) toTarget:self withObject:data];
+ SEL sel;
+
+ if( [typeName isEqualToString:@"Compressed Log File"] ) {
+ sel = @selector(parseCompressedLogData:);
+ } else {
+ sel = @selector(parseUncompressedLogData:);
+ }
+
+ [NSThread detachNewThreadSelector:sel toTarget:self withObject:data];
+
return YES;
}
-- (void)parseLogFile:(NSData *)data {
+- (void)parseCompressedLogData:(NSData *)data {
+ LogParser *parser = [[LogParser alloc] initWithDocument:self];
+ [self setRequests:[parser parseLogData:data isCompressed:YES]];
+
+}
+
+- (void)parseUncompressedLogData:(NSData *)data {
LogParser *parser = [[LogParser alloc] initWithDocument:self];
- [self setRequests:[parser parseLogData:data]];
+ [self setRequests:[parser parseLogData:data isCompressed:NO]];
}
View
2 LogParser.h
@@ -23,6 +23,6 @@
- (id)initWithDocument:(LogDocument *)theDocument;
-- (NSArray *)parseLogData:(NSData *)data;
+- (NSArray *)parseLogData:(NSData *)data isCompressed:(BOOL)isCompressed;
@end
View
12 LogParser.m
@@ -17,6 +17,7 @@
#import "ParsingProgressController.h"
#import "NSScanner+SpikeAdditions.h"
+#import "NSData+ZlibAdditions.h"
@interface LogParser (PrivateMethods)
- (RailsRequest *)parseRequest:(NSArray *)lines;
@@ -47,10 +48,18 @@ - (id)initWithDocument:(LogDocument *)theDocument {
}
-- (NSArray *)parseLogData:(NSData *)data {
+- (NSArray *)parseLogData:(NSData *)data isCompressed:(BOOL)isCompressed {
progressController = [[ParsingProgressController alloc] init];
[progressController showWindow:self];
+ if( isCompressed ) {
+ [progressController setStatus:@"Decompressing log file"];
+ [progressController setAnimated:YES];
+ data = [data gzipInflate];
+ }
+
+ [progressController setStatus:@"Parsing log file"];
+
NSString *content = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSArray *lines = [content componentsSeparatedByString:@"\n"];
@@ -324,5 +333,4 @@ - (void)scanFilter:(NSString *)line intoRequest:(RailsRequest *)request {
[request setFilter:buffer];
}
-
@end
View
16 NSData+ZlibAdditions.h
@@ -0,0 +1,16 @@
+//
+// NSData+ZlibAdditions.h
+// Spike
+//
+// Created by Matt Mower on 18/02/2009.
+// Copyright 2009 LucidMac Software. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@interface NSData (NSData_ZlibAdditions)
+
+- (NSData *)gzipInflate;
+- (NSData *)gzipDeflate;
+
+@end
View
100 NSData+ZlibAdditions.m
@@ -0,0 +1,100 @@
+//
+// NSData+ZlibAdditions.m
+// Spike
+//
+// Created by Matt Mower on 18/02/2009.
+// Copyright 2009 LucidMac Software. All rights reserved.
+//
+
+#import "NSData+ZlibAdditions.h"
+
+#import "zlib.h"
+
+
+@implementation NSData (NSData_ZlibAdditions)
+
+- (NSData *)gzipInflate
+{
+ if ([self length] == 0) return self;
+
+ unsigned full_length = [self length];
+ unsigned half_length = [self length] / 2;
+
+ NSMutableData *decompressed = [NSMutableData dataWithLength: full_length + half_length];
+ BOOL done = NO;
+ int status;
+
+ z_stream strm;
+ strm.next_in = (Bytef *)[self bytes];
+ strm.avail_in = [self length];
+ strm.total_out = 0;
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+
+ if (inflateInit2(&strm, (15+32)) != Z_OK) return nil;
+ while (!done)
+ {
+ // Make sure we have enough room and reset the lengths.
+ if (strm.total_out >= [decompressed length])
+ [decompressed increaseLengthBy: half_length];
+ strm.next_out = [decompressed mutableBytes] + strm.total_out;
+ strm.avail_out = [decompressed length] - strm.total_out;
+
+ // Inflate another chunk.
+ status = inflate (&strm, Z_SYNC_FLUSH);
+ if (status == Z_STREAM_END) done = YES;
+ else if (status != Z_OK) break;
+ }
+ if (inflateEnd (&strm) != Z_OK) return nil;
+
+ // Set real length.
+ if (done)
+ {
+ [decompressed setLength: strm.total_out];
+ return [NSData dataWithData: decompressed];
+ }
+ else return nil;
+}
+
+- (NSData *)gzipDeflate
+{
+ if ([self length] == 0) return self;
+
+ z_stream strm;
+
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ strm.total_out = 0;
+ strm.next_in=(Bytef *)[self bytes];
+ strm.avail_in = [self length];
+
+ // Compresssion Levels:
+ // Z_NO_COMPRESSION
+ // Z_BEST_SPEED
+ // Z_BEST_COMPRESSION
+ // Z_DEFAULT_COMPRESSION
+
+ if (deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (15+16), 8, Z_DEFAULT_STRATEGY) != Z_OK) return nil;
+
+ NSMutableData *compressed = [NSMutableData dataWithLength:16384]; // 16K chunks for expansion
+
+ do {
+
+ if (strm.total_out >= [compressed length])
+ [compressed increaseLengthBy: 16384];
+
+ strm.next_out = [compressed mutableBytes] + strm.total_out;
+ strm.avail_out = [compressed length] - strm.total_out;
+
+ deflate(&strm, Z_FINISH);
+
+ } while (strm.avail_out == 0);
+
+ deflateEnd(&strm);
+
+ [compressed setLength: strm.total_out];
+ return [NSData dataWithData:compressed];
+}
+
+@end
View
4 ParsingProgressController.h
@@ -10,13 +10,17 @@
@interface ParsingProgressController : NSWindowController {
IBOutlet NSPanel *panel;
+ IBOutlet NSTextField *statusField;
IBOutlet NSProgressIndicator *indicator;
}
+@property NSTextField *statusField;
@property NSPanel *panel;
@property NSProgressIndicator *indicator;
- (void)setMin:(double)min max:(double)max;
- (void)update:(double)value;
+- (void)setStatus:(NSString *)status;
+- (void)setAnimated:(BOOL)animated;
@end
View
14 ParsingProgressController.m
@@ -10,6 +10,7 @@
@implementation ParsingProgressController
+@synthesize statusField;
@synthesize panel;
@synthesize indicator;
@@ -32,4 +33,17 @@ - (void)update:(double)value {
[indicator setDoubleValue:value];
}
+- (void)setStatus:(NSString *)status {
+ [statusField setStringValue:status];
+}
+
+- (void)setAnimated:(BOOL)animated {
+ if( animated ) {
+ [indicator setUsesThreadedAnimation:YES];
+ [indicator startAnimation:self];
+ } else {
+ [indicator stopAnimation:self];
+ }
+}
+
@end
View
14 RequestDetailsController.h
@@ -1,14 +0,0 @@
-//
-// RequestDetailsController.h
-// Spike
-//
-// Created by Matt Mower on 15/02/2009.
-// Copyright 2009 LucidMac Software. All rights reserved.
-//
-
-#import <Cocoa/Cocoa.h>
-
-@interface RequestDetailsController : NSWindowController {
-}
-
-@end
View
12 RequestDetailsController.m
@@ -1,12 +0,0 @@
-//
-// RequestDetailsController.m
-// Spike
-//
-// Created by Matt Mower on 15/02/2009.
-// Copyright 2009 LucidMac Software. All rights reserved.
-//
-
-#import "RequestDetailsController.h"
-
-@implementation RequestDetailsController
-@end
View
14 Spike.xcodeproj/project.pbxproj
@@ -31,7 +31,7 @@
C9AAED650F46EF0900D6C171 /* NSArray+TDParseKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = C9AAED620F46EF0900D6C171 /* NSArray+TDParseKitAdditions.m */; };
C9AAED660F46EF0900D6C171 /* NSString+TDParseKitAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = C9AAED640F46EF0900D6C171 /* NSString+TDParseKitAdditions.m */; };
C9AAEDD70F4781C500D6C171 /* Parameter.m in Sources */ = {isa = PBXBuildFile; fileRef = C9AAEDD60F4781C500D6C171 /* Parameter.m */; };
- C9AAEE1E0F479DFF00D6C171 /* RequestDetailsController.m in Sources */ = {isa = PBXBuildFile; fileRef = C9AAEE1D0F479DFF00D6C171 /* RequestDetailsController.m */; };
+ C9BEA82E0F4C81A400C4F976 /* NSData+ZlibAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = C9BEA82D0F4C81A400C4F976 /* NSData+ZlibAdditions.m */; };
C9EEFC290F45B59900054345 /* RailsRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = C9EEFC280F45B59900054345 /* RailsRequest.m */; };
C9EEFC2E0F45B5A300054345 /* LogParser.m in Sources */ = {isa = PBXBuildFile; fileRef = C9EEFC2D0F45B5A300054345 /* LogParser.m */; };
C9EEFC510F45C82000054345 /* AppController.m in Sources */ = {isa = PBXBuildFile; fileRef = C9EEFC500F45C82000054345 /* AppController.m */; };
@@ -90,8 +90,8 @@
C9AAED640F46EF0900D6C171 /* NSString+TDParseKitAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+TDParseKitAdditions.m"; sourceTree = "<group>"; };
C9AAEDD50F4781C500D6C171 /* Parameter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Parameter.h; sourceTree = "<group>"; };
C9AAEDD60F4781C500D6C171 /* Parameter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Parameter.m; sourceTree = "<group>"; };
- C9AAEE1C0F479DFF00D6C171 /* RequestDetailsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RequestDetailsController.h; sourceTree = "<group>"; };
- C9AAEE1D0F479DFF00D6C171 /* RequestDetailsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RequestDetailsController.m; sourceTree = "<group>"; };
+ C9BEA82C0F4C81A400C4F976 /* NSData+ZlibAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSData+ZlibAdditions.h"; sourceTree = "<group>"; };
+ C9BEA82D0F4C81A400C4F976 /* NSData+ZlibAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+ZlibAdditions.m"; sourceTree = "<group>"; };
C9EEFC270F45B59900054345 /* RailsRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RailsRequest.h; sourceTree = "<group>"; };
C9EEFC280F45B59900054345 /* RailsRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RailsRequest.m; sourceTree = "<group>"; };
C9EEFC2C0F45B5A300054345 /* LogParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LogParser.h; sourceTree = "<group>"; };
@@ -118,6 +118,8 @@
080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
+ C9BEA82C0F4C81A400C4F976 /* NSData+ZlibAdditions.h */,
+ C9BEA82D0F4C81A400C4F976 /* NSData+ZlibAdditions.m */,
C9AAED610F46EF0900D6C171 /* NSArray+TDParseKitAdditions.h */,
C9AAED620F46EF0900D6C171 /* NSArray+TDParseKitAdditions.m */,
C9AAED630F46EF0900D6C171 /* NSString+TDParseKitAdditions.h */,
@@ -132,8 +134,6 @@
C9EEFC500F45C82000054345 /* AppController.m */,
C9AAEDD50F4781C500D6C171 /* Parameter.h */,
C9AAEDD60F4781C500D6C171 /* Parameter.m */,
- C9AAEE1C0F479DFF00D6C171 /* RequestDetailsController.h */,
- C9AAEE1D0F479DFF00D6C171 /* RequestDetailsController.m */,
C95930680F4871B0004A49FA /* HaltedColumnTransformer.h */,
C95930690F4871B0004A49FA /* HaltedColumnTransformer.m */,
C921DB880F4AE1D8008A2505 /* ParamParser.h */,
@@ -291,12 +291,12 @@
C9AAED650F46EF0900D6C171 /* NSArray+TDParseKitAdditions.m in Sources */,
C9AAED660F46EF0900D6C171 /* NSString+TDParseKitAdditions.m in Sources */,
C9AAEDD70F4781C500D6C171 /* Parameter.m in Sources */,
- C9AAEE1E0F479DFF00D6C171 /* RequestDetailsController.m in Sources */,
C959306A0F4871B0004A49FA /* HaltedColumnTransformer.m in Sources */,
C921DB8A0F4AE1D8008A2505 /* ParamParser.m in Sources */,
C92613A90F4C24FF00218378 /* LogDocument.m in Sources */,
C92614390F4C32AE00218378 /* ParsingProgressController.m in Sources */,
C92614C10F4C591900218378 /* NSScanner+SpikeAdditions.m in Sources */,
+ C9BEA82E0F4C81A400C4F976 /* NSData+ZlibAdditions.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -365,6 +365,7 @@
GCC_PREFIX_HEADER = Spike_Prefix.pch;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
+ OTHER_LDFLAGS = "-lz";
PRODUCT_NAME = Spike;
WARNING_CFLAGS = "-Wall";
};
@@ -386,6 +387,7 @@
GCC_PREFIX_HEADER = Spike_Prefix.pch;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Applications";
+ OTHER_LDFLAGS = "-lz";
PRODUCT_NAME = Spike;
WARNING_CFLAGS = "-Wall";
};

0 comments on commit 42c61e5

Please sign in to comment.