Skip to content

Instantly share code, notes, and snippets.

@BenjaminPoulain
Created September 1, 2011 17:32
Show Gist options
  • Save BenjaminPoulain/1186709 to your computer and use it in GitHub Desktop.
Save BenjaminPoulain/1186709 to your computer and use it in GitHub Desktop.
From b04c392ecf5b3c097b4d2a06502193e237d681c4 Mon Sep 17 00:00:00 2001
From: Benjamin Poulain <benjamin@webkit.org>
Date: Thu, 1 Sep 2011 19:32:04 +0200
Subject: [PATCH] Add basic parsing for the command header.
The "cmd:" header represent the command profiled by Valgrind.
---
Callgrind Viewer/FileLoader.m | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/Callgrind Viewer/FileLoader.m b/Callgrind Viewer/FileLoader.m
index e00c5ea..86fdb26 100644
--- a/Callgrind Viewer/FileLoader.m
+++ b/Callgrind Viewer/FileLoader.m
@@ -41,6 +41,27 @@ static inline ssize_t indexOfNextNewLineChar(const char* data, size_t offset, si
- (BOOL)processHeaderLine:(NSString *)string
{
+ if (![string length])
+ return YES;
+ if ([string hasPrefix:@"#"])
+ return YES;
+
+ { // Command parsing.
+ NSError *error = 0;
+ NSRegularExpression *commandRegex = [NSRegularExpression regularExpressionWithPattern:@"^cmd:[ \t]*(.*)$"
+ options:0
+ error:&error];
+ NSTextCheckingResult *match = [commandRegex firstMatchInString: string options: 0 range:NSMakeRange(0, [string length])];
+ if (match) {
+ NSRange commandRange = [match rangeAtIndex: 1];
+ NSString *commandName = [string substringWithRange: commandRange];
+ // FIXME: store the command in a nice object representing the profile.
+ NSLog(@"command = %@", commandName);
+ return YES;
+ }
+ }
+
+ // FIXME: parse the remaining headers.
return YES;
}
--
1.7.4.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment