/* * This C program will read an DSPJRN outfile of *TYPE1 and return the sum * of the Cached Journal bytes between two consecutive commits. Caculates * the min, max, and average. * * Since a CM operation flushes the memory-resident Journal buffer, this * approach provides a rough approximation of the best case resulting * Journal bundle size. This bundle size can be achieved even with the * Journal Caching support enabled. * * The following is an example of a DSPJRN command with the options * required: * DSPJRN JRN(LIB/JRN) OUTPUT(*OUTFILE) OUTFILFMT(*TYPE1) * OUTFILE(LIB/OUTFILE) INCHIDENT(*YES) * * Syntax: * SUMCM lib file * lib - library * outfile - dspjrn outfile * * Compile Statement: * CRTSQLCI OBJ(LIB/SUMCM) * SRCFILE(LIB/SUMCM) * COMMIT(*NONE) OBJTYPE(*PGM) * * Run Statement: * CALL LIB/SUMCM PARM('LIB' 'OUTFILE') */ /* include the necessary C header files */ #include #include #include #include /* toupper() call */ /* Statements required for embedded SQL */ EXEC sql include SQLCA; EXEC sql include SQLDA; /* Begin main function */ int main(int argc, char *argv[]) { EXEC SQL BEGIN DECLARE SECTION; int i; /* a simple counter */ long int numents = 0; /* number of entries in outfile */ long int curr_ent = 1; /* current entry being processed */ long int entsize = 0; /* size of current entry */ long int totentrysize = -1; /* running total size all entries between CMs*/ long int runningnumCM = 0; /* current number of commits found */ long int totalsize = 0; /* cumulative size of all entries */ long int maxCMwait = -1; /* current max size of data between CMs */ long int minCMwait = 9999999; /* current min size of data between CMs */ char enttype[3]; /* entry type of current entry */ char selstmt[200]; /* character arrays to hold our select statements */ char sel2stmt[200]; char lib[11]; /* character array to hold input library name */ char outfile[11]; /* character array to hold outfile name */ EXEC SQL DECLARE c1 CURSOR FOR exestmt; /* declare SQL cursor C1 */ EXEC SQL DECLARE c2 CURSOR FOR actstmt; /* declare SQL cursor C2 */ EXEC SQL END DECLARE SECTION; /* ***************************************** * Parsing command line / error checking ***************************************** */ if (argc != 3) { printf("ERROR - proper syntax is: SUMCM lib outfile"); } else { /* extract the library from the first argument */ sprintf(lib, "%s", argv[1]); /* extract the outfile from the second argument */ sprintf(outfile, "%s", argv[2]); /* convert the library to upper case */ for (i = 0; i < 10; i++) { lib[i] = toupper(lib[i]); } /* convert the outfile to upper case */ for (i = 0; i < 10; i++) { outfile[i] = toupper(outfile[i]); } /* create the SQL statement to determine the number of entries */ sprintf(selstmt, "SELECT COUNT(*) FROM %s/%s", lib, outfile); EXEC SQL PREPARE actstmt FROM :selstmt; EXEC SQL OPEN c2; /* open the SQL view (cursor) */ EXEC SQL FETCH c2 INTO :numents; /* set the number of entries */ EXEC SQL CLOSE c2; /* close the SQL cursor */ /* output the number of Entries to the screen */ printf("\n\n\n\n\n\n\n"); printf("Number of entries = %d\n", numents); /* Create SQL query which will pull two columns from your OUTFILE: * the entry type and the width in bytes of each Journal entry. * These will be sorted by the Journal Sequence number so that * we see consecutive Journal Entries in the order in which they * were deposited. */ /* Select the entry type and length from the file. If the type is * a CM, we will have completed a bundle of entries we are looking * for. By summing JOENTL, we can calculate the size of the bundles. */ sprintf(sel2stmt, "SELECT JOENTT, JOENTL FROM %s/%s order by JOSEQN", lib, outfile); EXEC SQL PREPARE exestmt FROM :sel2stmt; EXEC SQL OPEN c1; /* open the SQL view (cursor) */ /* loop through each entry in the outfile */ while(curr_ent <= numents) { /* get the next available entry */ EXEC SQL FETCH c1 INTO :enttype, :entsize; /* extract the entry type, size */ /* for each entry, add its length to the total size */ totalsize += entsize; /* test if current entry is a Commit entry */ if (strcmp(enttype, "CM") == 0) { runningnumCM++; /* increment the number of commits found */ totentrysize += totalsize; /* increase the total bundle size */ /* maintain overall stats if we really just finished a commit */ if (totalsize > maxCMwait) maxCMwait = totalsize; if (totalsize < minCMwait && totalsize != -1) minCMwait = totalsize; /* set the totalsize (size of data between commits) to 0 */ totalsize = 0; } curr_ent = curr_ent + 1; } EXEC SQL CLOSE c1; printf("Number of commits = %d\n", runningnumCM); printf("Average Bundle size = %d bytes\n", totentrysize / runningnumCM); printf(" max commit data size = %d bytes\n", maxCMwait); printf(" min commit data size = %d bytes\n", minCMwait); printf("\n"); printf("The optimal Bundle size is 128 KB or wider\n"); printf("\n"); } return 0; }