Update contrib.
2 # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 # This component and the accompanying materials are made available
5 # under the terms of "Eclipse Public License v1.0"
6 # which accompanies this distribution, and is available
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 # Initial Contributors:
10 # Nokia Corporation - initial contribution.
15 # Script to upload performance or other data embedded as SQL statements
16 # in test execute output logs.
18 # This script keys off "SQL_UPLOAD_VERSION_0:" and "SQL_SESSION_ID=" tags for
26 # The default perl install does not provide the mysql database driver, needed
27 # to connect to a MySQL database. For convenience we deliver a pure perl
28 # implementation locally. This application can use such GPL modules under the
29 # System Library exception of GPL. If this script needs to be called from
30 # another directory, then the 'use lib ".";' directive won't work. To resolve
31 # this problem, run the script "perl installmysqlperlmodule.pl" first.
41 our ($searchRoot, $helpOnUsage, $jobId);
43 our @globalSessionTransaction;
44 our @bulkSqlTransaction;
48 my ($aRequireParameter,$aMissingParameter) = @_;
49 $aRequireParameter = 0 if not defined $aRequireParameter;
51 print <<END_OF_USAGE_TEXT;
52 Usage: perl uploadsqlfromtestrun.pl --dir=searchRootDir --job=jobID [--help]
54 Note this script requires the Net::MySQL package to either be installed or
55 to be supplied in the search path. An example such commandline is:
57 Q:\\>perl -IQ:\\epoc32\\release\\winscw\\udeb\\z\\uibench
58 \\epoc32\\release\\winscw\\udeb\\z\\uibench\\uploadsqlfromtestrun.pl
59 --dir=\\epoc32\\winscw\\c\\logs\\testexecute
62 This script recurses through searchRootDir looking for htm files containing
63 <prefix>SQL_UPLOAD_VERSION_0:<sql commands>
64 upon which it invokes those <sql commands>
67 <prefix>SQL_SESSION_ID=<session value>
68 upon which it associates the supplied integer jobID with the <session value>
69 in the database. In the database these identifiers are unsigned integers:
70 jobid int(10) unsigned
71 sessionid bigint(20) unsigned
73 The jobID would normally come from the overnight build system. Low numbered
74 jobIDs, i.e. those <10000, would not collide with the build system and so can
75 be used when running this script interactively outside the context of a build
78 The help option (--help, -h or -?) prints this message
82 if (defined $aMissingParameter)
84 print "Error: Parameter \"--$aMissingParameter\" missing\n"
86 exit $aRequireParameter;
96 sub AddToGlobalFileList
100 if (-f $aFile && $aFile =~ /.*.htm$/i)
102 push @main::globalFileList, $File::Find::name;
108 foreach my $file (@main::globalFileList)
110 open (FILE, "$file");
111 foreach my $line (<FILE>)
113 if ($line =~ /.*SQL_UPLOAD_VERSION_0:*/i)
115 $line =~ s/.*SQL_UPLOAD_VERSION_0://g;
116 push @main::bulkSqlTransaction, $line;
118 if ($line =~ /.*SQL_SESSION_ID=/i)
120 $line =~ s/.*SQL_SESSION_ID=//g;
122 $line = "INSERT INTO performance.jobsessionmap (jobid, sessionid) VALUES ('"
123 . $main::jobId . "', '"
126 push @main::globalSessionTransaction, $line;
133 sub connectToSqlDatabase
137 hostname => '4GBD02346',
138 database => 'performance',
147 $dbHandle = connectToSqlDatabase();
148 $dbHandle->query(@bulkSqlTransaction);
149 die if ($dbHandle->is_error);
152 # We are re-creating the connection to the database because this forces
153 # the underlying client-server transaction to flush its socket. There
154 # is no flush API that the MySQL perl module gives us. If we don't do
155 # this, the transaction completes without errors, but does not actually
156 # put the session rows into the database!
157 $dbHandle = connectToSqlDatabase();
158 $dbHandle->query(@globalSessionTransaction);
162 GetOptions ('dir=s' => \$searchRoot,
164 'help|h|?' =>\$helpOnUsage) || Usage();
166 Usage(0) if $helpOnUsage;
167 Usage(1,'dir') if not defined $searchRoot;
168 Usage(1,'job') if not defined $jobId;
170 $searchRoot = RemoveBackSlashes($searchRoot);
172 @globalFileList = ();
173 find(\&AddToGlobalFileList, ($searchRoot));
175 @bulkSqlTransaction = ();
176 @globalSessionTransaction = ();