Skip to content

Commit 7ddf04d

Browse files
committed
feat: add "On SortVerbose;" for extra sort info
Add information to the final sort summaries (per thread and master) including the number of comparisons made, the number of times the small and large buffers were sorted due to their capacities, and the total size of the unsorted, uncompressed generated terms.
1 parent 7e0ddbf commit 7ddf04d

4 files changed

Lines changed: 84 additions & 37 deletions

File tree

sources/compcomm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ static KEYWORDV onoffoptions[] = {
143143
,{"humanstats", &(AC.HumanStatsFlag), 1, 0}
144144
,{"humanstatistics", &(AC.HumanStatsFlag), 1, 0}
145145
,{"grccverbose", &(AC.GrccVerbose), 1, 0}
146+
,{"sortverbose", &(AC.SortVerbose), 1, 0}
146147
};
147148

148149
static WORD one = 1;

sources/sort.c

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,6 @@ extern LONG nummallocs;
7272
extern LONG numfrees;
7373
#endif
7474

75-
//#define COUNTCOMPARES
76-
#ifdef COUNTCOMPARES
77-
// This needs to be large enough for the number of threads.
78-
// It is hardcoded here, but 1024 should be enough.
79-
// Enabling this has a performance impact.
80-
LONG numcompares[1024];
81-
#endif
82-
8375
/*
8476
#] Includes :
8577
#[ SortUtilities :
@@ -164,10 +156,14 @@ void WriteStats(POSITION *plspace, WORD par, WORD checkLogType)
164156
char humanGenTermsText[HUMANSTRLEN] = "";
165157
char humanTermsLeftText[HUMANSTRLEN] = "";
166158
char humanBytesText[HUMANSTRLEN] = "";
159+
char humanUnsortedBytesText[HUMANSTRLEN] = "";
160+
char humanComparisonsText[HUMANSTRLEN] = "";
167161
if ( AC.HumanStatsFlag ) {
168162
HumanString(humanGenTermsText, (float)(S->GenTerms), humanTermsSuffix);
169163
HumanString(humanTermsLeftText, (float)(S->TermsLeft), humanTermsSuffix);
170164
HumanString(humanBytesText, (float)(BASEPOSITION(*plspace)), humanBytesSuffix);
165+
HumanString(humanUnsortedBytesText, (float)(S->verbUnsortedSize), humanBytesSuffix);
166+
HumanString(humanComparisonsText, (float)(S->verbComparisons), humanTermsSuffix);
171167
}
172168

173169
MLOCK(ErrorMessageLock);
@@ -315,6 +311,23 @@ void WriteStats(POSITION *plspace, WORD par, WORD checkLogType)
315311
MesPrint("%s", buf);
316312
}
317313

314+
if ( par == STATSPOSTSORT ) {
315+
if ( AC.SortVerbose ) {
316+
snprintf(buf, sizeof(buf), "%24s Unsorted bytes =%11ld%s",
317+
"",S->verbUnsortedSize,humanUnsortedBytesText);
318+
MesPrint("%s", buf);
319+
snprintf(buf, sizeof(buf), "%24s Small Buffer =%5ld,%5ld",
320+
"",S->verbSBsortTerms,S->verbSBsortCap);
321+
MesPrint("%s", buf);
322+
snprintf(buf, sizeof(buf), "%24s Large Buffer =%5ld,%5ld",
323+
"",S->verbLBsortPatches,S->verbLBsortCap);
324+
MesPrint("%s", buf);
325+
snprintf(buf, sizeof(buf), "%24s Comparisons =%11ld%s",
326+
"",S->verbComparisons,humanComparisonsText);
327+
MesPrint("%s", buf);
328+
}
329+
}
330+
318331
#ifdef WITHSTATS
319332
MesPrint("Total number of writes: %l, reads: %l, seeks, %l"
320333
,numwrites,numreads,numseeks);
@@ -362,14 +375,6 @@ int NewSort(PHEAD0)
362375
}
363376
if ( AR.sLevel == 0 ) {
364377

365-
#ifdef COUNTCOMPARES
366-
#ifdef WITHPTHREADS
367-
numcompares[AT.identity] = 0;
368-
#else
369-
numcompares[0] = 0;
370-
#endif
371-
#endif
372-
373378
AN.FunSorts[0] = AT.S0;
374379
if ( AR.PolyFun == 0 ) { AT.S0->PolyFlag = 0; }
375380
else if ( AR.PolyFunType == 1 ) { AT.S0->PolyFlag = 1; }
@@ -408,6 +413,13 @@ int NewSort(PHEAD0)
408413
409414
PUTZERO(AN.OldPosOut);
410415
*/
416+
// Zero the SortVerbose counters:
417+
S->verbComparisons = 0;
418+
S->verbSBsortTerms = 0;
419+
S->verbSBsortCap = 0;
420+
S->verbLBsortPatches = 0;
421+
S->verbLBsortCap = 0;
422+
S->verbUnsortedSize = 0;
411423
return(0);
412424
}
413425

@@ -621,6 +633,10 @@ LONG EndSort(PHEAD WORD *buffer, int par)
621633
/*
622634
The large buffer is too full. Merge and write it
623635
*/
636+
// Update SortVerbose counters
637+
if ( S->lPatch >= S->MaxPatches ) S->verbLBsortPatches++;
638+
else S->verbLBsortCap++;
639+
624640
#ifdef GZIPDEBUG
625641
MLOCK(ErrorMessageLock);
626642
MesPrint("%w EndSort: lPatch = %d, MaxPatches = %d,lFill = %x, sSpace = %ld, MaxTer = %d, lTop = %x"
@@ -977,18 +993,6 @@ LONG EndSort(PHEAD WORD *buffer, int par)
977993
}
978994
}
979995

980-
#ifdef COUNTCOMPARES
981-
if ( AR.sLevel < 0 ) {
982-
#ifdef WITHPTHREADS
983-
MLOCK(ErrorMessageLock);
984-
MesPrint(">>>number of calls to Compare: %l (tid %d)", numcompares[AT.identity], AT.identity);
985-
MUNLOCK(ErrorMessageLock);
986-
#else
987-
MesPrint(">>>number of calls to Compare: %l", numcompares[0]);
988-
#endif
989-
}
990-
#endif
991-
992996
return(retval);
993997
WorkSpaceError:
994998
MLOCK(ErrorMessageLock);
@@ -2344,15 +2348,8 @@ WORD Compare1(PHEAD WORD *term1, WORD *term2, WORD level)
23442348
WORD prevorder;
23452349
WORD count = -1, localPoly, polyhit = -1;
23462350

2347-
#ifdef COUNTCOMPARES
2348-
if ( AR.sLevel == 0 ) {
2349-
#ifdef WITHPTHREADS
2350-
numcompares[AT.identity]++;
2351-
#else
2352-
numcompares[0]++;
2353-
#endif
2354-
}
2355-
#endif
2351+
// Update SortVerbose counter
2352+
S->verbComparisons++;
23562353

23572354
if ( S->PolyFlag ) {
23582355
/*
@@ -4252,6 +4249,9 @@ int StoreTerm(PHEAD WORD *term)
42524249
POSITION pp;
42534250
LONG lSpace, sSpace, RetCode, over, tover;
42544251

4252+
// Update SortVerbose counters
4253+
S->verbUnsortedSize += *term * sizeof(*term);
4254+
42554255
if ( ( ( AP.PreDebug & DUMPTOSORT ) == DUMPTOSORT ) && AR.sLevel == 0 ) {
42564256
#ifdef WITHPTHREADS
42574257
snprintf((char *)(THRbuf),100,"StoreTerm(%d)",AT.identity);
@@ -4266,6 +4266,10 @@ int StoreTerm(PHEAD WORD *term)
42664266
/*
42674267
The small buffer is full. It has to be sorted and written.
42684268
*/
4269+
// Update SortVerbose counters
4270+
if ( S->sTerms >= S->TermsInSmall ) S->verbSBsortTerms++;
4271+
else S->verbSBsortCap++;
4272+
42694273
tover = over = S->sTerms;
42704274
ss = S->sPointer;
42714275
ss[over] = 0;
@@ -4298,6 +4302,10 @@ int StoreTerm(PHEAD WORD *term)
42984302
/*
42994303
The large buffer is too full. Merge and write it
43004304
*/
4305+
// Update SortVerbose counters
4306+
if ( S->lPatch >= S->MaxPatches ) S->verbLBsortPatches++;
4307+
else S->verbLBsortCap++;
4308+
43014309
if ( MergePatches(1) ) goto StoreCall;
43024310
/*
43034311
pp = S->SizeInFile[1];

sources/structs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,12 @@ typedef struct sOrT {
11561156
LONG SpaceLeft; /* Space needed for still existing terms */
11571157
LONG putinsize; /* Size of buffer in putin */
11581158
LONG ninterms; /* Which input term ? */
1159+
LONG verbComparisons; /* Counters for "On SortVerbose;" statistics */
1160+
LONG verbSBsortTerms;
1161+
LONG verbSBsortCap;
1162+
LONG verbLBsortPatches;
1163+
LONG verbLBsortCap;
1164+
LONG verbUnsortedSize;
11591165
int MaxPatches; /* Maximum number of patches in large buffer */
11601166
int MaxFpatches; /* Maximum number of patches in one filesort */
11611167
int type; /* Main, function or sub(routine) */
@@ -1826,6 +1832,7 @@ struct C_const {
18261832
int FlintPolyFlag; /* Use Flint for polynomial arithmetic */
18271833
int HumanStatsFlag; /* Print human-readable stats in the stats print? */
18281834
int GrccVerbose; /* Enable extra print statements in grcc? */
1835+
int SortVerbose; /* Enable extra sort stats information? */
18291836
int doloopstacksize;
18301837
int dolooplevel;
18311838
int CheckpointFlag; /**< Tells preprocessor whether checkpoint code must executed.

sources/threads.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,6 +1987,8 @@ void *RunSortBot(void *dummy)
19871987
AT.SB.FillBlock = 1;
19881988
AT.SB.MasterFill[1] = AT.SB.MasterStart[1];
19891989
SETBASEPOSITION(AN.theposition,0);
1990+
// Reset the sortbot comparison count
1991+
AT.SS->verbComparisons = 0;
19901992
break;
19911993
/*
19921994
#] INISORTBOT :
@@ -4052,10 +4054,23 @@ int MasterMerge(void)
40524054
fin->handle = -1;
40534055
position = S->SizeInFile[0];
40544056
MULPOS(position,sizeof(WORD));
4057+
4058+
// Collect global sort statistics information from the threads.
4059+
// The total GenTerms is the sum of the thread GenTerms.
4060+
// The total small/large buffer sort info is the sum of the thread info.
4061+
// The total comparison count is the sum of the thread counts.
4062+
// The total unsorted size is the sum of the total generated terms sizes
40554063
S->GenTerms = 0;
40564064
for ( j = 1; j <= numberofworkers; j++ ) {
40574065
S->GenTerms += AB[j]->T.SS->GenTerms;
4066+
S->verbComparisons += AB[j]->T.SS->verbComparisons;
4067+
S->verbSBsortTerms += AB[j]->T.SS->verbSBsortTerms;
4068+
S->verbSBsortCap += AB[j]->T.SS->verbSBsortCap;
4069+
S->verbLBsortPatches += AB[j]->T.SS->verbLBsortPatches;
4070+
S->verbLBsortCap += AB[j]->T.SS->verbLBsortCap;
4071+
S->verbUnsortedSize += AB[j]->T.SS->verbUnsortedSize;
40584072
}
4073+
40594074
WriteStats(&position,STATSPOSTSORT,NOCHECKLOGTYPE);
40604075
Expressions[AR0.CurExpr].counter = S->TermsLeft;
40614076
Expressions[AR0.CurExpr].size = position;
@@ -4193,10 +4208,26 @@ int SortBotMasterMerge(void)
41934208
}
41944209
position = S->SizeInFile[0];
41954210
MULPOS(position,sizeof(WORD));
4211+
4212+
// Collect global sort statistics information from the threads.
4213+
// The total GenTerms is the sum of the thread GenTerms.
4214+
// The total small/large buffer sort info is the sum of the thread info.
4215+
// The total comparison count is the sum of the thread and sortbot counts.
4216+
// The total unsorted size is the sum of the total generated terms sizes
41964217
S->GenTerms = 0;
41974218
for ( j = 1; j <= numberofworkers; j++ ) {
41984219
S->GenTerms += AB[j]->T.SS->GenTerms;
4220+
S->verbComparisons += AB[j]->T.SS->verbComparisons;
4221+
S->verbSBsortTerms += AB[j]->T.SS->verbSBsortTerms;
4222+
S->verbSBsortCap += AB[j]->T.SS->verbSBsortCap;
4223+
S->verbLBsortPatches += AB[j]->T.SS->verbLBsortPatches;
4224+
S->verbLBsortCap += AB[j]->T.SS->verbLBsortCap;
4225+
S->verbUnsortedSize += AB[j]->T.SS->verbUnsortedSize;
41994226
}
4227+
for ( j = numberofworkers+1; j <= numberofworkers+numberofsortbots; j++ ) {
4228+
S->verbComparisons += AB[j]->T.SS->verbComparisons;
4229+
}
4230+
42004231
S->TermsLeft = numberofterms;
42014232
WriteStats(&position,STATSPOSTSORT,NOCHECKLOGTYPE);
42024233
Expressions[AR.CurExpr].counter = S->TermsLeft;

0 commit comments

Comments
 (0)