[bugzilla-gnome-org-extensions] This is the first revision that can actually successfully parse and insert traces into the DB during



commit 312bf966cd374fdc1a33bb3f9b732326d0c22dd0
Author: Max Kanat-Alexander <mkanat everythingsolved com>
Date:   Mon Aug 3 08:04:22 2009 -0500

    This is the first revision that can actually successfully parse and insert
    traces into the DB during the upgrade phase.

 code/db_schema-abstract_schema.pl |    8 ++++-
 code/install-requirements.pl      |    2 +-
 code/install-update_db.pl         |   29 +++++++++++++---------
 lib/TraceParser/Trace.pm          |   49 +++++++++++++++++++++++-------------
 4 files changed, 55 insertions(+), 33 deletions(-)
---
diff --git a/code/db_schema-abstract_schema.pl b/code/db_schema-abstract_schema.pl
index c7170a6..82a920d 100644
--- a/code/db_schema-abstract_schema.pl
+++ b/code/db_schema-abstract_schema.pl
@@ -29,17 +29,21 @@ $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},
         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},
     ],
     INDEXES => [
         trace_short_hash_idx => ['short_hash'],
-        trace_full_hash_idx  => ['full_hash'],
+        trace_full_hash_idx  => ['stack_hash'],
+        trace_bug_id_idx => ['bug_id'],
     ],
 };
diff --git a/code/install-requirements.pl b/code/install-requirements.pl
index c04cc59..dd4da99 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.05,
+        version => 0.07,
     },
 ];
 
diff --git a/code/install-update_db.pl b/code/install-update_db.pl
index 3a66f57..818ecc8 100644
--- a/code/install-update_db.pl
+++ b/code/install-update_db.pl
@@ -27,12 +27,6 @@ use Bugzilla::Install::Util qw(indicate_progress);
 
 use TraceParser::Trace;
 
-use constant IGNORE_FUNCTIONS => qw(
-   __kernel_vsyscall
-   raise
-   abort
-);
-
 my $dbh = Bugzilla->dbh;
 my $has_traces = $dbh->selectrow_array('SELECT 1 FROM trace ' 
                                         . $dbh->sql_limit('1'));
@@ -44,21 +38,32 @@ if (!$has_traces) {
         $dbh->{'mysql_use_result'} = 1;
     }
 
-    $dbh->bz_start_transaction();
-    my $sth = $dbh->prepare('SELECT bug_id,thetext FROM longdescs');
+    my $sth = $dbh->prepare('SELECT bug_id, thetext FROM longdescs');
     $sth->execute();
     my $count = 0;
+    my @traces;
     while (my ($bug_id, $text) = $sth->fetchrow_array) {
         $count++;
-        my $trace = TraceParser::Trace->parse_from_text($text);
+        my $trace = TraceParser::Trace->parse_from_text($text, $bug_id);
+        push(@traces, $trace) if $trace;
         indicate_progress({ current => $count, total => $total, 
                             every => 100 });
-        next if !$trace;
-        TraceParser::Trace->create({ %$trace, bug_id => $bug_id });
     }
-    $dbh->bz_commit_transaction();
+
+    my $total_traces = scalar(@traces);
+    print "Parsed $total_traces traces.\n";
 
     if ($dbh->isa('Bugzilla::DB::Mysql')) {
         $dbh->{'mysql_use_result'} = 0;
     }
+
+    print "Inserting parsed traces into DB...\n";
+    $count = 1;
+    $dbh->bz_start_transaction();
+    while (my $trace = shift @traces) {
+        TraceParser::Trace->create($trace);
+        indicate_progress({ current => $count++, total => $total_traces, 
+                            every => 100 });
+    }
+    $dbh->bz_commit_transaction();
 }
diff --git a/lib/TraceParser/Trace.pm b/lib/TraceParser/Trace.pm
index b364467..1652503 100644
--- a/lib/TraceParser/Trace.pm
+++ b/lib/TraceParser/Trace.pm
@@ -35,11 +35,13 @@ use Digest::MD5 qw(md5_base64);
 ###############################
 
 use constant DB_COLUMNS => qw(
-    has_symbols
     id
-    full_hash
+    bug_id
     short_hash
-    thetext
+    short_stack
+    stack_hash
+    trace_hash
+    trace_text
     type
     quality
 );
@@ -47,16 +49,22 @@ use constant DB_COLUMNS => qw(
 use constant DB_TABLE => 'trace';
 
 use constant VALIDATORS => {
-    has_symbols => \&Bugzilla::Object::check_boolean,
-    full_hash   => \&_check_hash,
+    stack_hash  => \&_check_hash,
     short_hash  => \&_check_hash,
+    trace_hash  => \&_check_hash,
     short_stack => \&_check_short_stack,
-    thetext     => \&_check_thetext,
+    trace_text  => \&_check_thetext,
     type        => \&_check_type,
     quality     => \&_check_quality,
 };
 
-use constant REQUIRED_CREATE_FIELDS => qw(type full_hash short_hash);
+use constant REQUIRED_CREATE_FIELDS => qw(
+    type
+    trace_hash
+    stack_hash
+    short_hash
+    trace_text
+);
 
 # This is how long a Base64 MD5 Hash is.
 use constant HASH_SIZE => 22;
@@ -77,14 +85,13 @@ use constant IGNORE_FUNCTIONS => qw(
 # 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 ($class, $text, $bug_id) = @_;
     my $trace = Parse::StackTrace->parse(types => TRACE_TYPES, 
                                          text => $text);
     return undef if !$trace;
 
     my @all_functions;
     my $quality = 0;
-    my $has_symbols = 1;
     my $crash_thread = $trace->thread_with_crash || $trace->threads->[0];
     foreach my $frame (@{ $crash_thread->frames }) {
         foreach my $item (qw(args number file line code)) {
@@ -93,11 +100,6 @@ sub parse_from_text {
         my $function = $frame->function;
         if (!grep($_ eq $function, IGNORE_FUNCTIONS)) {
             push(@all_functions, $frame->function);
-        }
-        if ($function eq '??') {
-            $has_symbols = 0;
-        }
-        else {
             $quality++;
         }
     }
@@ -107,28 +109,39 @@ sub parse_from_text {
     my $stack_hash = md5_base64(join(',', @all_functions));
     my $short_hash = md5_base64(join(',', @short_stack));
     my $trace_text = $trace->text;
+    my $trace_hash = md5_base64($trace_text);
 
     return {
-        has_symbols => $has_symbols,
+        bug_id      => $bug_id,
         stack_hash  => $stack_hash,
         short_hash  => $short_hash,
         short_stack => join(', ', @short_stack),
-        trace_hash  => md5_base64($text),
+        trace_hash  => $trace_hash,
         trace_text  => $trace_text,
         type        => ref($trace),
         quality     => $quality,
     };
 }
 
+sub new_from_text {
+    my ($class, $text, $bug_id) = @_;
+    my $parsed = Parse::StackTrace->parse(types => TRACE_TYPES,
+                                          text => $text);
+    return undef if !$parsed;
+    my $hash = md5_base64($parsed->text);
+    my $traces = $class->match({ trace_hash => $hash, bug_id => $bug_id });
+    return $traces->[0];
+}
+
 ###############################
 ####      Accessors      ######
 ###############################
 
-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 trace_hash  { return $_[0]->{trace_hash};  }
+sub text        { return $_[0]->{trace_text};  }
 sub type        { return $_[0]->{type};        }
 sub quality     { return $_[0]->{quality};     }
 


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