home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / TP1.ZIP / SQLQUEEN.C < prev    next >
Text File  |  1989-08-06  |  10KB  |  379 lines

  1. /***************************************************************************/
  2. /* Copyright (C) 1989 Microsoft Corporation                                */
  3. /* Program: SQLQUEEN.C                                                     */
  4. /* Description:  Control workstations that are running "benchw.exe".       */
  5. /*               SQLQUEEN communicates with the workstations using         */
  6. /*               Lan Manager Mailslots.  A mail message is sent to         */
  7. /*               initiate the connection to the server under test and to   */
  8. /*               the tracking server.  Then a message is sent to start     */
  9. /*               testing.  After the tests have been run, the performance  */
  10. /*               tracking database is updated.                             */
  11. /*                                                                         */
  12. /* Created:   Trish Millines 1/23/89                                       */
  13. /* Modified:  Bob Muglia     4/5/89                                        */
  14. /*                                                                         */
  15. /***************************************************************************/
  16. #define INCL_BASE
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <time.h>
  20. #include <math.h>
  21. #include <types.h>
  22. #include <stat.h>
  23. #include <timeb.h>
  24. #include <fcntl.h>
  25. #include <share.h>
  26. #include <io.h>
  27. #include <sqlfront.h>
  28. #include <sqldb.h>
  29. #include <netcons.h>
  30. #include <mailslot.h>
  31. #include <neterr.h>
  32. #include <os2def.h>
  33. #include <bse.h>
  34. #include "bench.h"
  35.  
  36. #define MAILPATH "\\\\*\\mailslot\\sqlbench\\"
  37.  
  38. struct queen_data qd;            /* Program data structure */
  39.  
  40. time_t stime,etime;         /* Start and end times */
  41. FILE *outptr;
  42.  
  43. main(argc,argv)
  44. int argc;
  45. char **argv;
  46. {
  47.  DBPROCESS far *dbproc, *track_proc;
  48.  LOGINREC far *login;
  49.  RETCODE retc;                       /* return code for dblib funcs  */
  50.  time_t ltoday;
  51.  char message[100];                  /* buffer for mailslot message */
  52.  char mailbox[50];                   /* where to send mail to */
  53.  char server[31];
  54.  int i;
  55.  
  56. /* */
  57. /* Forward declaration of SQL Server error handlers */
  58. /* */
  59.  
  60.  int queen_err_handler();
  61.  int queen_msg_handler();
  62.  
  63. /* */
  64. /* Call routine to parse the arguments */
  65. /* */
  66.  
  67.  if (Check_arguments(argc,argv) == FAIL)
  68.    exit(-1);
  69.  
  70. /* */
  71. /* Install the SQL Server error handlers */
  72. /* */
  73.  
  74.  dberrhandle(queen_err_handler);
  75.  dbmsghandle(queen_msg_handler);
  76.  
  77. /* */
  78. /* Open a connection to the performance tracking database */
  79. /* */
  80.  
  81.  if((login = dblogin()) == NULL)
  82.   {
  83.    printf("\nSQLQUEEN ERROR: dblogin failed\n");
  84.    exit(FAIL);
  85.   }
  86.  
  87.  DBSETLUSER(login,"sa");
  88.  DBSETLPWD(login,"");
  89.  DBSETLAPP(login,"bench_stats");
  90.  
  91.  if((track_proc = dbopen(login,qd.track_server)) == NULL)
  92.   {
  93.    printf("\nSQLQUEEN ERROR:  dbopen failed\n");
  94.    exit(FAIL);
  95.   }
  96.  
  97. /* */
  98. /* Use the bench_stat database */
  99. /* */
  100.  
  101.  if(dbuse(track_proc,"bench_stat") == FAIL)
  102.   {
  103.    printf("\nSQLQUEEN ERROR: Cannot find bench_stat database\n");
  104.    dbexit();
  105.    exit(FAIL);
  106.   }
  107.  
  108. /* */
  109. /* Determine the starting number which workstations will log their 
  110. /* results to in the bench_stat database */                                       
  111. /* */
  112.  
  113.  qd.startrun = Get_max_value(track_proc,"runs","number");
  114.  ++qd.startrun;
  115.  
  116. /* */
  117. /* Determine the number to log sqlqueen results */  
  118. /* */
  119.  
  120.  qd.multi_number = Get_max_value(track_proc,"multi_runs","multi_number");
  121.  ++qd.multi_number;
  122.  
  123.  
  124. /* */
  125. /* Open the status log.  This log contains information about each run */
  126. /* */
  127.  
  128.  if((outptr = fopen("sqlstat.log","a")) == NULL)
  129.    {
  130.     printf("\nSQLQUEEN ERROR: Can't open sqlstat.log\n");
  131.     dbexit();
  132.     exit(FAIL);
  133.    }
  134.  
  135. /* */
  136. /*  Build a message packet to mail to the workstations.  The message packet */
  137. /*  contains the name of the tracking server and the server under test */
  138. /* */
  139.  
  140.  sprintf(message,"%c,%s,%s,%s",GET_SERVERS,qd.test_server,qd.track_server,
  141.          qd.database);
  142.  printf("\nTelling workstations to connect to servers %s and %s",qd.test_server,
  143.          qd.track_server);
  144.  
  145. /* */
  146. /* Send a mailslot mail message to all the workstations.  Supply the */
  147. /* connection message.  Upto 10 instances of the benchmark program (benchw) */
  148. /* can be running on a single workstation.  Send the message to all ten */
  149. /* mailslots. */
  150. /* */           
  151.  
  152.  for(i=1; i<=10; i++)
  153.  {
  154.   sprintf(mailbox,"%s%d",MAILPATH,i);
  155.   
  156.   if(DosWriteMailslot(mailbox, message, sizeof(message), 1, 2, (long) 0) 
  157.      != NERR_Success)
  158.    {
  159.     printf("\nSQLQUEEN ERROR: Can't send the connect mail message\n");
  160.     dbexit();
  161.     exit(FAIL);
  162.    }
  163.   DosSleep(150);
  164.  }
  165.  
  166. /* */
  167. /* Give the workstations a chance to connect to the server under test and
  168. /* the tracking server */
  169.  
  170.  Wait(45L);
  171.  
  172. /* */
  173. /* Start the tests! */
  174. /* */
  175.  
  176.  time(<oday);
  177.  fprintf(outptr,"\n\nStarting off the workstations at %s",ctime(<oday));
  178.  printf("\nTelling all workstations to test for %ld seconds",
  179.          qd.seconds);
  180.  
  181.  sprintf(message,"%c,%ld,%ld,%ld,%ld",ALL_START,qd.seconds,
  182.          qd.max_accts,qd.max_teller, qd.max_branch);
  183.  
  184.  for(i=1; i<=10; i++)
  185.  {
  186.   sprintf(mailbox,"%s%d",MAILPATH,i);
  187.   
  188.   if(DosWriteMailslot(mailbox, message, sizeof(message), 1, 2, (long) 0) 
  189.      != NERR_Success)
  190.    {
  191.     printf("\nSQLQUEEN ERROR: Can't send the start testing mail message\n");
  192.     dbexit();
  193.     exit(FAIL);
  194.    }
  195.   DosSleep(150);
  196.  }
  197.  
  198. /* */
  199. /* Wait the number of seconds */
  200. /* Keep reading the server file for error messages */
  201. /* */
  202.  
  203.  time(&stime);            /* Start time */
  204.  Wait(qd.seconds);
  205.  time(&etime);            /* End time */
  206.  
  207. /* */
  208. /* Give the workstations a chance to update the tracking database */
  209. /* */
  210.  
  211.  printf("\nWorkstations should be writing to the database");
  212.  Wait(90L);
  213.  
  214. /* */
  215. /* Update the run statistics */
  216. /* */
  217.  
  218.  Update_queen_stats(track_proc);
  219.  
  220. /* */
  221. /* Clean up and exit */
  222. /* */
  223.  
  224.  dbexit();
  225.  exit(0);
  226. }
  227.  
  228. /***************************************************************************/
  229. /*                      FUNCTION TO PARSE THE ARGUMENTS                    */
  230. /***************************************************************************/
  231. int Check_arguments(argc,argv)
  232. int argc;
  233. char **argv;
  234. {
  235.  
  236. /* */
  237. /* See if all the necessary arguments are there */
  238. /* */
  239.  
  240.  if(argc != 8)
  241.   {
  242.    system("cls");
  243.    printf("\nUSAGE: SQLQUEEN Required_Arguments");
  244.    printf("\nThe arguments are as follows:");
  245.    printf("\n  Test_Server Tracking_Server Test_Database test_length");
  246.    printf(" Account Teller Branch");
  247.    printf("\n\nExample:");
  248.    printf("\n  SQLQUEEN Isis Rugger Bench 180 100000 1000 100");
  249.    return(FAIL);
  250.   }
  251.  
  252. /* */
  253. /* Initialize variables */
  254. /* */
  255.  
  256.  strcpy(qd.test_server,argv[1]);
  257.  strcpy(qd.track_server,argv[2]);
  258.  strcpy(qd.database,argv[3]);
  259.  qd.seconds = atol(argv[4]);
  260.  qd.max_accts = atol(argv[5]);
  261.  qd.max_teller = atol(argv[6]);
  262.  qd.max_branch = atol(argv[7]);
  263. }
  264.  
  265. /***************************************************************************/
  266. /*               FUNCTION TO UPDATE THE PERFORMANCE TRACKING DATABASE      */
  267. /***************************************************************************/
  268. void Update_queen_stats(track_proc)
  269. DBPROCESS far *track_proc;
  270. {
  271.  char cmd[500];
  272.  struct tm *t;
  273.  int i;
  274.  
  275. /* */
  276. /* Convert the start and end time into SQL Server datetime format */
  277. /* */
  278.  
  279.  t = localtime(&stime);
  280.  sprintf(qd.start_time,"%d/%d/%d %d:%d:%d",t->tm_mon + 1,t->tm_mday,t->tm_year,\
  281.          t->tm_hour,t->tm_min,t->tm_sec);
  282.  t = localtime(&etime);
  283.  sprintf(qd.end_time,"%d/%d/%d %d:%d:%d",t->tm_mon + 1,t->tm_mday,t->tm_year,\
  284.          t->tm_hour,t->tm_min,t->tm_sec);
  285.  
  286. /* */
  287. /* Determine how many users completed successfully */
  288. /* */
  289.  
  290.  qd.endrun = Get_max_value(track_proc,"runs","number");  
  291.  qd.users = (qd.endrun - qd.startrun) + 1;
  292.  
  293. /* */
  294. /* Update the performance tracking database */
  295. /* */
  296.  
  297.  printf("\nUpdating the performance tracking database workstation: %ld to %ld",
  298.         qd.startrun,qd.endrun);
  299.  printf("\nMultiuser run number: %ld",qd.multi_number);
  300.  
  301.  fprintf(outptr,
  302.         "\nUpdating the performance tracking database workstation: %ld to %ld",
  303.         qd.startrun,qd.endrun);
  304.  fprintf(outptr,"\nMultiuser run number: %ld",qd.multi_number);
  305.  
  306.  
  307.  sprintf(cmd,"insert into multi_runs values\
  308.          (%ld,'%s','%s',%ld,%ld,%ld,%ld,'%s','%s','%s',%ld,%ld,%ld)",
  309.          qd.multi_number,qd.start_time,qd.end_time,qd.startrun,qd.endrun,
  310.          qd.seconds,qd.users,qd.test_server,qd.database,qd.track_server,
  311.          qd.max_accts,qd.max_teller,qd.max_branch);
  312.  
  313.  dbcmd(track_proc,(char DBDIST *)cmd);
  314.  if(dbsqlexec(track_proc) == FAIL)
  315.   {
  316.    fprintf(outptr,"Error writing to queen table");
  317.    printf(" ... FAILED writing to queen table\n");
  318.    return;
  319.   }
  320.  else
  321.    Get_results(track_proc);
  322.  
  323. /* */
  324. /* Call procedure to update the multi_results table */
  325. /* */
  326.  
  327.  sprintf(cmd,"exec tp_comp_multiuser %ld,%ld,%ld",
  328.          qd.multi_number,qd.startrun,qd.endrun);
  329.  
  330.  dbcmd(track_proc,(char DBDIST *)cmd);
  331.  if(dbsqlexec(track_proc) == FAIL)
  332.   {
  333.    fprintf(outptr,"Error writing to results and/or multiresults table");
  334.    fprintf(outptr,"Command: %s",cmd);
  335.    printf(" ... FAILED writing to results or mulitresults table\n");
  336.    return;
  337.   }
  338.  else
  339.    Get_results(track_proc);
  340.  
  341.  printf("\n\nDone.");
  342. }
  343.  
  344. /***************************************************************************/
  345. /* DB-Library Error and Message handlers                                   */
  346. /***************************************************************************/
  347.  
  348.  
  349. int queen_err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr)
  350. DBPROCESS       *dbproc;
  351. int             severity;
  352. int             dberr;
  353. int             oserr;
  354. char            *dberrstr;
  355. char            *oserrstr;
  356. {
  357.  printf("DB-LIB error:\n   %d=%s\n\n",dberr,dberrstr);
  358.  printf("oserr=%d\n",oserr);
  359.  dbexit();
  360.  exit(FAIL);
  361. }
  362.  
  363.  
  364. int queen_msg_handler(dbproc, msgno, msgstate, severity, msgtext)
  365. DBPROCESS        *dbproc;
  366. DBINT            msgno;
  367. int              msgstate;
  368. int              severity;
  369. char             *msgtext;
  370. {
  371.  if (msgno != 5701)
  372.  {
  373.    printf("Server error:\n    %ld=%s\n\n",msgno,msgtext);
  374.    dbexit();
  375.    exit(FAIL);
  376.  }
  377. }
  378.  
  379.