[bugzilla-gnome-org-extensions] Make traceparser actually work, add the trace text and so forth to the table.



commit 39339967570f5f6e1387122d766d7ef8ad9312bd
Author: Max Kanat-Alexander <mkanat everythingsolved com>
Date:   Fri Jul 31 22:08:21 2009 -0500

    Make traceparser actually work, add the trace text and so forth to the table.

 code/db_schema-abstract_schema.pl |    8 ++---
 code/install-requirements.pl      |    2 +-
 lib/TraceParser/Trace.pm          |   52 ++++++++++++++++++++++++-------------
 3 files changed, 38 insertions(+), 24 deletions(-)
---
diff --git a/code/db_schema-abstract_schema.pl b/code/db_schema-abstract_schema.pl
index 9235340..c7170a6 100644
--- a/code/db_schema-abstract_schema.pl
+++ b/code/db_schema-abstract_schema.pl
@@ -29,14 +29,12 @@ $schema->{trace} = {
     FIELDS => [
         id          => {TYPE => 'MEDIUMSERIAL',  NOTNULL => 1, 
                         PRIMARYKEY => 1},
-        bug_id      => {TYPE => 'INT3',  NOTNULL => 1, 
-                        REFERENCES => {TABLE  => 'bugs',
-                                       COLUMN => 'bug_id',
-                                       DELETE => 'CASCADE'}},
         type        => {TYPE => 'varchar(255)', NOTNULL => 1},
         short_stack => {TYPE => 'MEDIUMTEXT', NOTNULL => 1},
         short_hash  => {TYPE => 'char(22)', NOTNULL => 1},
-        full_hash   => {TYPE => 'char(22)', NOTNULL => 1},
+        stack_hash  => {TYPE => 'char(22)', NOTNULL => 1},
+        trace_hash  => {TYPE => 'char(22)', NOTNULL => 1},
+        trace_text  => {TYPE => 'LONGTEXT', NOTNULL => 1},
         has_symbols => {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 0},
         quality     => {TYPE => 'INT3', NOTNULL => 1},
     ],
diff --git a/code/install-requirements.pl b/code/install-requirements.pl
index d99d9f6..c04cc59 100644
--- a/code/install-requirements.pl
+++ b/code/install-requirements.pl
@@ -27,7 +27,7 @@ use constant REQUIRED_MODULES => [
     {
         package => 'Parse-StackTrace',
         module  => 'Parse::StackTrace',
-        version => 0.04,
+        version => 0.05,
     },
 ];
 
diff --git a/lib/TraceParser/Trace.pm b/lib/TraceParser/Trace.pm
index 2ccdfa3..b364467 100644
--- a/lib/TraceParser/Trace.pm
+++ b/lib/TraceParser/Trace.pm
@@ -35,11 +35,11 @@ use Digest::MD5 qw(md5_base64);
 ###############################
 
 use constant DB_COLUMNS => qw(
-    bug_id
     has_symbols
     id
     full_hash
     short_hash
+    thetext
     type
     quality
 );
@@ -47,11 +47,11 @@ use constant DB_COLUMNS => qw(
 use constant DB_TABLE => 'trace';
 
 use constant VALIDATORS => {
-    bug_id      => \&_check_bug_id,
     has_symbols => \&Bugzilla::Object::check_boolean,
     full_hash   => \&_check_hash,
     short_hash  => \&_check_hash,
     short_stack => \&_check_short_stack,
+    thetext     => \&_check_thetext,
     type        => \&_check_type,
     quality     => \&_check_quality,
 };
@@ -74,8 +74,8 @@ use constant IGNORE_FUNCTIONS => qw(
 # Constructors #
 ################
 
-# Returns a hash suitable for passing to create() (without the bug_id
-# argument), or undef if there is no trace in the comment.
+# Returns a hash suitable for passing to create(), or undef if there is no
+# trace in the comment.
 sub parse_from_text {
     my ($class, $text) = @_;
     my $trace = Parse::StackTrace->parse(types => TRACE_TYPES, 
@@ -87,26 +87,34 @@ sub parse_from_text {
     my $has_symbols = 1;
     my $crash_thread = $trace->thread_with_crash || $trace->threads->[0];
     foreach my $frame (@{ $crash_thread->frames }) {
-        foreach my $item (qw(function args number file line code)) {
-            $quality++ if defined $frame->$item;
+        foreach my $item (qw(args number file line code)) {
+            $quality++ if defined $frame->$item && $frame->$item ne '';
         }
         my $function = $frame->function;
         if (!grep($_ eq $function, IGNORE_FUNCTIONS)) {
             push(@all_functions, $frame->function);
         }
-        $has_symbols = 0 if $function eq '??';
+        if ($function eq '??') {
+            $has_symbols = 0;
+        }
+        else {
+            $quality++;
+        }
     }
 
     my $max_short_stack = $#all_functions > 4 ? 4 : $#all_functions;
     my @short_stack = @all_functions[0..$max_short_stack];
-    my $full_hash = md5_base64(join(',', @all_functions));
+    my $stack_hash = md5_base64(join(',', @all_functions));
     my $short_hash = md5_base64(join(',', @short_stack));
+    my $trace_text = $trace->text;
 
     return {
         has_symbols => $has_symbols,
-        full_hash   => $full_hash,
+        stack_hash  => $stack_hash,
         short_hash  => $short_hash,
         short_stack => join(', ', @short_stack),
+        trace_hash  => md5_base64($text),
+        trace_text  => $trace_text,
         type        => ref($trace),
         quality     => $quality,
     };
@@ -120,24 +128,22 @@ sub has_symbols { return $_[0]->{has_symbols}; }
 sub full_hash   { return $_[0]->{full_hash};   }
 sub short_hash  { return $_[0]->{short_hash};  }
 sub short_stack { return $_[0]->{short_stack}; }
+sub trace_text  { return $_[0]->{trace_text};  }
 sub type        { return $_[0]->{type};        }
 sub quality     { return $_[0]->{quality};     }
 
-sub bug {
+sub stacktrace_object {
     my $self = shift;
-    $self->{bug} ||= new Bugzilla::Bug($self->{bug_id});
-    return $self->{bug};
+    my $type = $self->type;
+    eval("use $type") || die $@;
+    $self->{stacktrace_object} ||= $type->parse({ text => $self->trace_text });
+    return $self->{stacktrace_object};
 }
 
 ###############################
 ###       Validators        ###
 ###############################
 
-sub _check_bug_id {
-    my ($self, $bug_id) = @_;
-    return Bugzilla::Bug->check($bug_id)->id;
-}
-
 sub _check_hash {
     my ($self, $hash) = @_;
     $hash = trim($hash);
@@ -149,10 +155,20 @@ sub _check_hash {
 
 sub _check_short_stack { return trim($_[1]) || '' }
 
+sub _check_thetext {
+    my ($invocant, $text) = @_;
+    if (!$text or $text =~ /^\s+$/s) {
+        my $class = ref($invocant) || $invocant;
+        ThrowCodeError('param_required', { function => "${class}::create",
+                                           param    => 'thetext' });
+    }
+    return $text;
+}
+
 sub _check_type {
     my ($invocant, $type) = @_;
     $type = trim($type);
-    if (!$type)
+    if (!$type) {
         my $class = ref($invocant) || $invocant;
         ThrowCodeError('param_required', { function => "${class}::create",
                                            param    => 'type' });


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]