Skip to content

Commit

Permalink
Better resource reporting, includes size
Browse files Browse the repository at this point in the history
  • Loading branch information
gf3 committed Nov 8, 2012
1 parent 747ae78 commit 0641766
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
14 changes: 11 additions & 3 deletions page-ready/GCAnalyzer.m
Expand Up @@ -188,8 +188,10 @@ - (void)printSummary
[[error domain] UTF8String], [[url squishToLength:SQUISH_LENGTH] UTF8String], [[error localizedDescription] UTF8String]);
else {
NSTimeInterval interval = [resource.finish timeIntervalSinceDate:resource.start];
printf("\t" COLOR_GREEN STRING_SUCCESS COLOR_RESET " %f sec\t%s\n",
interval, [[url squishToLength:SQUISH_LENGTH] UTF8String]);
printf("\t" COLOR_GREEN STRING_SUCCESS COLOR_RESET " %f sec [%s]\t%s\n",
interval,
[[resource humanReadableContentLength] UTF8String],
[[url squishToLength:SQUISH_LENGTH] UTF8String]);
}
}
}
Expand Down Expand Up @@ -293,9 +295,15 @@ - (void)webView:(WebView *)sender resource:(id)identifier didFinishLoadingFromDa

- (void)webView:(WebView *)sender resource:(id)identifier didFailLoadingWithError:(NSError *)error fromDataSource:(WebDataSource *)dataSource
{
resourceFailed++;
GCResource *resource = [resources objectForKey:identifier];
resource.error = error;
resourceFailed++;
}

- (void)webView:(WebView *)sender resource:(id)identifier didReceiveContentLength:(NSUInteger)length fromDataSource:(WebDataSource *)dataSource
{
GCResource *resource = [resources objectForKey:identifier];
resource.contentLength = (resource.contentLength || 0) + length;
}

- (void)resourcesMaybeFinishedLoading
Expand Down
4 changes: 4 additions & 0 deletions page-ready/GCResource.h
Expand Up @@ -10,17 +10,21 @@

@interface GCResource : NSObject
{
NSUInteger contentLength;
NSError *error;
NSDate *finish;
NSNumber *id;
NSURLRequest *request;
NSDate *start;
}

@property NSUInteger contentLength;
@property (retain) NSNumber *id;
@property (retain) NSError *error;
@property (retain) NSDate *finish;
@property (retain) NSURLRequest *request;
@property (retain) NSDate *start;

- (NSString *)humanReadableContentLength;

@end
15 changes: 14 additions & 1 deletion page-ready/GCResource.m
Expand Up @@ -10,6 +10,19 @@

@implementation GCResource

@synthesize error, finish, id, request, start;
@synthesize contentLength, error, finish, id, request, start;

- (NSString *)humanReadableContentLength
{
if (!contentLength)
return @"null";

char *units[] = {"", "KB", "MB", "GB", "TB", "PB"};
int e = floor(log(contentLength) / log(1024));
char amount[12];
sprintf(amount, "%1.2f%s", contentLength / pow(1024, e), units[e]);

return [NSString stringWithUTF8String:amount];
}

@end

0 comments on commit 0641766

Please sign in to comment.