graphicstest/uibench/scripts/uploadsqlfromtestrun.pl
changeset 69 3365349494cc
equal deleted inserted replaced
45:36b2e23a8629 69:3365349494cc
       
     1 #!perl
       
     2 # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     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".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 # Script to upload performance or other data embedded as SQL statements
       
    16 # in test execute output logs.
       
    17 #
       
    18 # This script keys off "SQL_UPLOAD_VERSION_0:" and "SQL_SESSION_ID=" tags for
       
    19 # data extraction.
       
    20 
       
    21 use Getopt::Long;
       
    22 use File::Basename;
       
    23 use File::Find;
       
    24 use Cwd;
       
    25 
       
    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.
       
    32 
       
    33 
       
    34 use lib ".";
       
    35 
       
    36 use MySQL;
       
    37 
       
    38 use strict;
       
    39 use warnings;
       
    40 
       
    41 our ($searchRoot, $helpOnUsage, $jobId);
       
    42 our @globalFileList;
       
    43 our @globalSessionTransaction;
       
    44 our @bulkSqlTransaction;
       
    45 
       
    46 sub Usage
       
    47 	{
       
    48 	my ($aRequireParameter,$aMissingParameter) = @_;
       
    49 	$aRequireParameter = 0 if not defined $aRequireParameter;
       
    50 
       
    51   	print <<END_OF_USAGE_TEXT;
       
    52 Usage: perl uploadsqlfromtestrun.pl --dir=searchRootDir --job=jobID [--help]
       
    53 
       
    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:
       
    56 
       
    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
       
    60    --job=655433
       
    61 
       
    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>
       
    65 
       
    66 It also looks for 
       
    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
       
    72 
       
    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
       
    76 system.
       
    77 
       
    78 The help option (--help, -h or -?) prints this message
       
    79 
       
    80 END_OF_USAGE_TEXT
       
    81 	
       
    82 	if (defined $aMissingParameter)
       
    83 		{	
       
    84   		print "Error: Parameter \"--$aMissingParameter\" missing\n"
       
    85   		}
       
    86  	exit $aRequireParameter;
       
    87 	}
       
    88 	
       
    89 sub RemoveBackSlashes
       
    90 	{
       
    91 	my ($aPath) = @_;
       
    92 	$aPath =~ s/\\/\//g;
       
    93 	return $aPath;
       
    94 	}
       
    95 
       
    96 sub AddToGlobalFileList
       
    97 	{
       
    98 	my $aFile = $_;
       
    99 	
       
   100 	if (-f $aFile && $aFile =~ /.*.htm$/i)
       
   101 		{
       
   102 		push @main::globalFileList, $File::Find::name;
       
   103 		}
       
   104 	}
       
   105 	
       
   106 sub ParseFiles()
       
   107 	{
       
   108 	foreach my $file (@main::globalFileList)
       
   109 		{
       
   110 		open (FILE, "$file");		
       
   111 		foreach my $line (<FILE>)
       
   112 			{
       
   113 			if ($line =~ /.*SQL_UPLOAD_VERSION_0:*/i)
       
   114 				{
       
   115 				$line =~ s/.*SQL_UPLOAD_VERSION_0://g;
       
   116 				push @main::bulkSqlTransaction, $line;
       
   117 				}
       
   118 			if ($line =~ /.*SQL_SESSION_ID=/i)
       
   119 				{
       
   120 				$line =~ s/.*SQL_SESSION_ID=//g;
       
   121 				chomp $line;
       
   122 				$line = "INSERT INTO performance.jobsessionmap (jobid, sessionid) VALUES ('"
       
   123 						. $main::jobId . "', '"
       
   124 						. $line . "');\n"
       
   125 						;
       
   126 				push @main::globalSessionTransaction, $line;
       
   127 				}
       
   128 			}
       
   129 		close FILE;
       
   130 		}
       
   131 	}
       
   132 
       
   133 sub connectToSqlDatabase
       
   134 	{
       
   135 	return
       
   136 		Net::MySQL->new(
       
   137 		hostname => '4GBD02346',
       
   138 		database => 'performance',
       
   139 		user     => 'uibench',
       
   140 		password => 'grui'
       
   141 		);
       
   142 	}
       
   143 	
       
   144 sub UploadSqlData()
       
   145 	{
       
   146 	my $dbHandle;
       
   147 	$dbHandle = connectToSqlDatabase();
       
   148 	$dbHandle->query(@bulkSqlTransaction);
       
   149 	die if ($dbHandle->is_error);
       
   150 	$dbHandle->close;
       
   151 	
       
   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);
       
   159 	$dbHandle->close;
       
   160 	}
       
   161 	
       
   162 GetOptions ('dir=s' => \$searchRoot,
       
   163             'job=s' => \$jobId,
       
   164             'help|h|?' =>\$helpOnUsage) || Usage();
       
   165 
       
   166 Usage(0) if $helpOnUsage;
       
   167 Usage(1,'dir') if not defined $searchRoot;
       
   168 Usage(1,'job') if not defined $jobId;
       
   169 
       
   170 $searchRoot = RemoveBackSlashes($searchRoot);
       
   171 
       
   172 @globalFileList = ();
       
   173 find(\&AddToGlobalFileList, ($searchRoot));
       
   174 
       
   175 @bulkSqlTransaction = ();
       
   176 @globalSessionTransaction  = ();
       
   177 ParseFiles();
       
   178 UploadSqlData();