home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
TP1.ZIP
/
SQLQUEEN.C
< prev
next >
Wrap
Text File
|
1989-08-06
|
10KB
|
379 lines
/***************************************************************************/
/* Copyright (C) 1989 Microsoft Corporation */
/* Program: SQLQUEEN.C */
/* Description: Control workstations that are running "benchw.exe". */
/* SQLQUEEN communicates with the workstations using */
/* Lan Manager Mailslots. A mail message is sent to */
/* initiate the connection to the server under test and to */
/* the tracking server. Then a message is sent to start */
/* testing. After the tests have been run, the performance */
/* tracking database is updated. */
/* */
/* Created: Trish Millines 1/23/89 */
/* Modified: Bob Muglia 4/5/89 */
/* */
/***************************************************************************/
#define INCL_BASE
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <types.h>
#include <stat.h>
#include <timeb.h>
#include <fcntl.h>
#include <share.h>
#include <io.h>
#include <sqlfront.h>
#include <sqldb.h>
#include <netcons.h>
#include <mailslot.h>
#include <neterr.h>
#include <os2def.h>
#include <bse.h>
#include "bench.h"
#define MAILPATH "\\\\*\\mailslot\\sqlbench\\"
struct queen_data qd; /* Program data structure */
time_t stime,etime; /* Start and end times */
FILE *outptr;
main(argc,argv)
int argc;
char **argv;
{
DBPROCESS far *dbproc, *track_proc;
LOGINREC far *login;
RETCODE retc; /* return code for dblib funcs */
time_t ltoday;
char message[100]; /* buffer for mailslot message */
char mailbox[50]; /* where to send mail to */
char server[31];
int i;
/* */
/* Forward declaration of SQL Server error handlers */
/* */
int queen_err_handler();
int queen_msg_handler();
/* */
/* Call routine to parse the arguments */
/* */
if (Check_arguments(argc,argv) == FAIL)
exit(-1);
/* */
/* Install the SQL Server error handlers */
/* */
dberrhandle(queen_err_handler);
dbmsghandle(queen_msg_handler);
/* */
/* Open a connection to the performance tracking database */
/* */
if((login = dblogin()) == NULL)
{
printf("\nSQLQUEEN ERROR: dblogin failed\n");
exit(FAIL);
}
DBSETLUSER(login,"sa");
DBSETLPWD(login,"");
DBSETLAPP(login,"bench_stats");
if((track_proc = dbopen(login,qd.track_server)) == NULL)
{
printf("\nSQLQUEEN ERROR: dbopen failed\n");
exit(FAIL);
}
/* */
/* Use the bench_stat database */
/* */
if(dbuse(track_proc,"bench_stat") == FAIL)
{
printf("\nSQLQUEEN ERROR: Cannot find bench_stat database\n");
dbexit();
exit(FAIL);
}
/* */
/* Determine the starting number which workstations will log their
/* results to in the bench_stat database */
/* */
qd.startrun = Get_max_value(track_proc,"runs","number");
++qd.startrun;
/* */
/* Determine the number to log sqlqueen results */
/* */
qd.multi_number = Get_max_value(track_proc,"multi_runs","multi_number");
++qd.multi_number;
/* */
/* Open the status log. This log contains information about each run */
/* */
if((outptr = fopen("sqlstat.log","a")) == NULL)
{
printf("\nSQLQUEEN ERROR: Can't open sqlstat.log\n");
dbexit();
exit(FAIL);
}
/* */
/* Build a message packet to mail to the workstations. The message packet */
/* contains the name of the tracking server and the server under test */
/* */
sprintf(message,"%c,%s,%s,%s",GET_SERVERS,qd.test_server,qd.track_server,
qd.database);
printf("\nTelling workstations to connect to servers %s and %s",qd.test_server,
qd.track_server);
/* */
/* Send a mailslot mail message to all the workstations. Supply the */
/* connection message. Upto 10 instances of the benchmark program (benchw) */
/* can be running on a single workstation. Send the message to all ten */
/* mailslots. */
/* */
for(i=1; i<=10; i++)
{
sprintf(mailbox,"%s%d",MAILPATH,i);
if(DosWriteMailslot(mailbox, message, sizeof(message), 1, 2, (long) 0)
!= NERR_Success)
{
printf("\nSQLQUEEN ERROR: Can't send the connect mail message\n");
dbexit();
exit(FAIL);
}
DosSleep(150);
}
/* */
/* Give the workstations a chance to connect to the server under test and
/* the tracking server */
Wait(45L);
/* */
/* Start the tests! */
/* */
time(<oday);
fprintf(outptr,"\n\nStarting off the workstations at %s",ctime(<oday));
printf("\nTelling all workstations to test for %ld seconds",
qd.seconds);
sprintf(message,"%c,%ld,%ld,%ld,%ld",ALL_START,qd.seconds,
qd.max_accts,qd.max_teller, qd.max_branch);
for(i=1; i<=10; i++)
{
sprintf(mailbox,"%s%d",MAILPATH,i);
if(DosWriteMailslot(mailbox, message, sizeof(message), 1, 2, (long) 0)
!= NERR_Success)
{
printf("\nSQLQUEEN ERROR: Can't send the start testing mail message\n");
dbexit();
exit(FAIL);
}
DosSleep(150);
}
/* */
/* Wait the number of seconds */
/* Keep reading the server file for error messages */
/* */
time(&stime); /* Start time */
Wait(qd.seconds);
time(&etime); /* End time */
/* */
/* Give the workstations a chance to update the tracking database */
/* */
printf("\nWorkstations should be writing to the database");
Wait(90L);
/* */
/* Update the run statistics */
/* */
Update_queen_stats(track_proc);
/* */
/* Clean up and exit */
/* */
dbexit();
exit(0);
}
/***************************************************************************/
/* FUNCTION TO PARSE THE ARGUMENTS */
/***************************************************************************/
int Check_arguments(argc,argv)
int argc;
char **argv;
{
/* */
/* See if all the necessary arguments are there */
/* */
if(argc != 8)
{
system("cls");
printf("\nUSAGE: SQLQUEEN Required_Arguments");
printf("\nThe arguments are as follows:");
printf("\n Test_Server Tracking_Server Test_Database test_length");
printf(" Account Teller Branch");
printf("\n\nExample:");
printf("\n SQLQUEEN Isis Rugger Bench 180 100000 1000 100");
return(FAIL);
}
/* */
/* Initialize variables */
/* */
strcpy(qd.test_server,argv[1]);
strcpy(qd.track_server,argv[2]);
strcpy(qd.database,argv[3]);
qd.seconds = atol(argv[4]);
qd.max_accts = atol(argv[5]);
qd.max_teller = atol(argv[6]);
qd.max_branch = atol(argv[7]);
}
/***************************************************************************/
/* FUNCTION TO UPDATE THE PERFORMANCE TRACKING DATABASE */
/***************************************************************************/
void Update_queen_stats(track_proc)
DBPROCESS far *track_proc;
{
char cmd[500];
struct tm *t;
int i;
/* */
/* Convert the start and end time into SQL Server datetime format */
/* */
t = localtime(&stime);
sprintf(qd.start_time,"%d/%d/%d %d:%d:%d",t->tm_mon + 1,t->tm_mday,t->tm_year,\
t->tm_hour,t->tm_min,t->tm_sec);
t = localtime(&etime);
sprintf(qd.end_time,"%d/%d/%d %d:%d:%d",t->tm_mon + 1,t->tm_mday,t->tm_year,\
t->tm_hour,t->tm_min,t->tm_sec);
/* */
/* Determine how many users completed successfully */
/* */
qd.endrun = Get_max_value(track_proc,"runs","number");
qd.users = (qd.endrun - qd.startrun) + 1;
/* */
/* Update the performance tracking database */
/* */
printf("\nUpdating the performance tracking database workstation: %ld to %ld",
qd.startrun,qd.endrun);
printf("\nMultiuser run number: %ld",qd.multi_number);
fprintf(outptr,
"\nUpdating the performance tracking database workstation: %ld to %ld",
qd.startrun,qd.endrun);
fprintf(outptr,"\nMultiuser run number: %ld",qd.multi_number);
sprintf(cmd,"insert into multi_runs values\
(%ld,'%s','%s',%ld,%ld,%ld,%ld,'%s','%s','%s',%ld,%ld,%ld)",
qd.multi_number,qd.start_time,qd.end_time,qd.startrun,qd.endrun,
qd.seconds,qd.users,qd.test_server,qd.database,qd.track_server,
qd.max_accts,qd.max_teller,qd.max_branch);
dbcmd(track_proc,(char DBDIST *)cmd);
if(dbsqlexec(track_proc) == FAIL)
{
fprintf(outptr,"Error writing to queen table");
printf(" ... FAILED writing to queen table\n");
return;
}
else
Get_results(track_proc);
/* */
/* Call procedure to update the multi_results table */
/* */
sprintf(cmd,"exec tp_comp_multiuser %ld,%ld,%ld",
qd.multi_number,qd.startrun,qd.endrun);
dbcmd(track_proc,(char DBDIST *)cmd);
if(dbsqlexec(track_proc) == FAIL)
{
fprintf(outptr,"Error writing to results and/or multiresults table");
fprintf(outptr,"Command: %s",cmd);
printf(" ... FAILED writing to results or mulitresults table\n");
return;
}
else
Get_results(track_proc);
printf("\n\nDone.");
}
/***************************************************************************/
/* DB-Library Error and Message handlers */
/***************************************************************************/
int queen_err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr)
DBPROCESS *dbproc;
int severity;
int dberr;
int oserr;
char *dberrstr;
char *oserrstr;
{
printf("DB-LIB error:\n %d=%s\n\n",dberr,dberrstr);
printf("oserr=%d\n",oserr);
dbexit();
exit(FAIL);
}
int queen_msg_handler(dbproc, msgno, msgstate, severity, msgtext)
DBPROCESS *dbproc;
DBINT msgno;
int msgstate;
int severity;
char *msgtext;
{
if (msgno != 5701)
{
printf("Server error:\n %ld=%s\n\n",msgno,msgtext);
dbexit();
exit(FAIL);
}
}