sl@0: #!perl sl@0: # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: # All rights reserved. sl@0: # This component and the accompanying materials are made available sl@0: # under the terms of "Eclipse Public License v1.0" sl@0: # which accompanies this distribution, and is available sl@0: # at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: # sl@0: # Initial Contributors: sl@0: # Nokia Corporation - initial contribution. sl@0: # sl@0: # Contributors: sl@0: # sl@0: # Description: sl@0: # Script to upload performance or other data embedded as SQL statements sl@0: # in test execute output logs. sl@0: # sl@0: # This script keys off "SQL_UPLOAD_VERSION_0:" and "SQL_SESSION_ID=" tags for sl@0: # data extraction. sl@0: sl@0: use Getopt::Long; sl@0: use File::Basename; sl@0: use File::Find; sl@0: use Cwd; sl@0: sl@0: # The default perl install does not provide the mysql database driver, needed sl@0: # to connect to a MySQL database. For convenience we deliver a pure perl sl@0: # implementation locally. This application can use such GPL modules under the sl@0: # System Library exception of GPL. If this script needs to be called from sl@0: # another directory, then the 'use lib ".";' directive won't work. To resolve sl@0: # this problem, run the script "perl installmysqlperlmodule.pl" first. sl@0: sl@0: sl@0: use lib "."; sl@0: sl@0: use MySQL; sl@0: sl@0: use strict; sl@0: use warnings; sl@0: sl@0: our ($searchRoot, $helpOnUsage, $jobId); sl@0: our @globalFileList; sl@0: our @globalSessionTransaction; sl@0: our @bulkSqlTransaction; sl@0: sl@0: sub Usage sl@0: { sl@0: my ($aRequireParameter,$aMissingParameter) = @_; sl@0: $aRequireParameter = 0 if not defined $aRequireParameter; sl@0: sl@0: print <perl -IQ:\\epoc32\\release\\winscw\\udeb\\z\\uibench sl@0: \\epoc32\\release\\winscw\\udeb\\z\\uibench\\uploadsqlfromtestrun.pl sl@0: --dir=\\epoc32\\winscw\\c\\logs\\testexecute sl@0: --job=655433 sl@0: sl@0: This script recurses through searchRootDir looking for htm files containing sl@0: SQL_UPLOAD_VERSION_0: sl@0: upon which it invokes those sl@0: sl@0: It also looks for sl@0: SQL_SESSION_ID= sl@0: upon which it associates the supplied integer jobID with the sl@0: in the database. In the database these identifiers are unsigned integers: sl@0: jobid int(10) unsigned sl@0: sessionid bigint(20) unsigned sl@0: sl@0: The jobID would normally come from the overnight build system. Low numbered sl@0: jobIDs, i.e. those <10000, would not collide with the build system and so can sl@0: be used when running this script interactively outside the context of a build sl@0: system. sl@0: sl@0: The help option (--help, -h or -?) prints this message sl@0: sl@0: END_OF_USAGE_TEXT sl@0: sl@0: if (defined $aMissingParameter) sl@0: { sl@0: print "Error: Parameter \"--$aMissingParameter\" missing\n" sl@0: } sl@0: exit $aRequireParameter; sl@0: } sl@0: sl@0: sub RemoveBackSlashes sl@0: { sl@0: my ($aPath) = @_; sl@0: $aPath =~ s/\\/\//g; sl@0: return $aPath; sl@0: } sl@0: sl@0: sub AddToGlobalFileList sl@0: { sl@0: my $aFile = $_; sl@0: sl@0: if (-f $aFile && $aFile =~ /.*.htm$/i) sl@0: { sl@0: push @main::globalFileList, $File::Find::name; sl@0: } sl@0: } sl@0: sl@0: sub ParseFiles() sl@0: { sl@0: foreach my $file (@main::globalFileList) sl@0: { sl@0: open (FILE, "$file"); sl@0: foreach my $line () sl@0: { sl@0: if ($line =~ /.*SQL_UPLOAD_VERSION_0:*/i) sl@0: { sl@0: $line =~ s/.*SQL_UPLOAD_VERSION_0://g; sl@0: push @main::bulkSqlTransaction, $line; sl@0: } sl@0: if ($line =~ /.*SQL_SESSION_ID=/i) sl@0: { sl@0: $line =~ s/.*SQL_SESSION_ID=//g; sl@0: chomp $line; sl@0: $line = "INSERT INTO performance.jobsessionmap (jobid, sessionid) VALUES ('" sl@0: . $main::jobId . "', '" sl@0: . $line . "');\n" sl@0: ; sl@0: push @main::globalSessionTransaction, $line; sl@0: } sl@0: } sl@0: close FILE; sl@0: } sl@0: } sl@0: sl@0: sub connectToSqlDatabase sl@0: { sl@0: return sl@0: Net::MySQL->new( sl@0: hostname => '4GBD02346', sl@0: database => 'performance', sl@0: user => 'uibench', sl@0: password => 'grui' sl@0: ); sl@0: } sl@0: sl@0: sub UploadSqlData() sl@0: { sl@0: my $dbHandle; sl@0: $dbHandle = connectToSqlDatabase(); sl@0: $dbHandle->query(@bulkSqlTransaction); sl@0: die if ($dbHandle->is_error); sl@0: $dbHandle->close; sl@0: sl@0: # We are re-creating the connection to the database because this forces sl@0: # the underlying client-server transaction to flush its socket. There sl@0: # is no flush API that the MySQL perl module gives us. If we don't do sl@0: # this, the transaction completes without errors, but does not actually sl@0: # put the session rows into the database! sl@0: $dbHandle = connectToSqlDatabase(); sl@0: $dbHandle->query(@globalSessionTransaction); sl@0: $dbHandle->close; sl@0: } sl@0: sl@0: GetOptions ('dir=s' => \$searchRoot, sl@0: 'job=s' => \$jobId, sl@0: 'help|h|?' =>\$helpOnUsage) || Usage(); sl@0: sl@0: Usage(0) if $helpOnUsage; sl@0: Usage(1,'dir') if not defined $searchRoot; sl@0: Usage(1,'job') if not defined $jobId; sl@0: sl@0: $searchRoot = RemoveBackSlashes($searchRoot); sl@0: sl@0: @globalFileList = (); sl@0: find(\&AddToGlobalFileList, ($searchRoot)); sl@0: sl@0: @bulkSqlTransaction = (); sl@0: @globalSessionTransaction = (); sl@0: ParseFiles(); sl@0: UploadSqlData();