/** Close all logfiles. */ void end_all_logs(void) { int n; for (n = 0; n < NLOGS; n++) end_log(logs + n, 0); }
void error( char const* format, ... ) { va_list ap; va_start( ap, format ); vlog_and_fprint( stderr, format, ap ); va_end( ap ); log_and_fprint(stderr, "\n"); end_log(); exit( -1 ); }
void show_error_log() { end_log(); #ifdef IS_WINDOWS system( getLogPath() ); #else FILE* f = open_log("r"); if(f != NULL) { fprintf(stderr, "\nLog:\n"); int c; while((c = getc(f)) != EOF) { putc(c, stderr); } putc('\n', stderr); fclose(f); } end_log(); #endif exit( -1 ); }
void clear_log() { bool was_logging = (gLog != NULL); end_log(); FILE* f = open_log("w"); if(f) { fclose(f); } if(was_logging) { begin_log(); } }
/*{{{ _quit -- really quit*/ int _quit() { register WINDOW *win; static int really_quit=0; if (really_quit++) { /* we're in bad shape */ perror("PANIC!! Error during _quit()!"); setreuid(getuid(),getuid()); abort(); } MOUSE_OFF(screen,mousex,mousey); sleep(1); /* let the key (if any) un-press before resetting the kbd */ set_kbd(0); /* fix up keyboard modes */ kbd_reset(); /* reset the keyboard */ reset_tty(0); /* fix up console tty modes */ #ifdef MOVIE end_log(); /* turn off logging */ #endif /* fix pttys */ if (geteuid() < 2) for(win=active;win != (WINDOW *) 0;win=W(next)) { if (W(pid)>1) killpg(W(pid),SIGHUP); chmod(W(tty),0666); chown(W(tty),0,0); } /* fix utmp file */ #ifdef WHO close(getdtablesize()-1); /* make sure there are enough fd's left */ for(win=active;win != (WINDOW *) 0;win=W(next)) if (W(tty)) rm_utmp(W(tty)); #endif CLEAR(screen,BIT_CLR); do_cmd( 'q' ); /* do the quiting command */ bit_destroy(screen); }
bool run( char* command_line, bool fail_on_error, char const* format, ... ) { char message[4096]; va_list argptr; va_start( argptr, format ); vsprintf( message, format, argptr ); va_end( argptr ); log("\n\n>> %s\n\n=================\n\n%s\n\n", message, command_line ); end_log(); bool result = system(command_line) == 0; begin_log(); if(!result && fail_on_error) { error("ERROR: Command failed!"); } return result; }
UTF8 *pool_alloc_lbuf(__in const UTF8 *tag, __in const UTF8 *file, const int line) { if (mudconf.paranoid_alloc) { pool_check(tag, file, line); } UTF8 *p; POOLFTR *pf; POOLHDR *ph = (POOLHDR *)pools[POOL_LBUF].free_head; if ( ph && ph->magicnum == pools[POOL_LBUF].poolmagic) { p = (UTF8 *)(ph + 1); pf = (POOLFTR *)(p + LBUF_SIZE); pools[POOL_LBUF].free_head = ph->nxtfree; // Check for corrupted footer, just report and fix it. // if (pf->magicnum != pools[POOL_LBUF].poolmagic) { pool_err(T("BUG"), LOG_ALWAYS, POOL_LBUF, tag, ph, T("Alloc"), T("corrupted buffer footer"), file, line); pf->magicnum = pools[POOL_LBUF].poolmagic; } } else { if (ph) { // Header is corrupt. Throw away the freelist and start a new // one. pool_err(T("BUG"), LOG_ALWAYS, POOL_LBUF, tag, ph, T("Alloc"), T("corrupted buffer header"), file, line); // Start a new free list and record stats. // pools[POOL_LBUF].free_head = NULL; pools[POOL_LBUF].num_lost += (pools[POOL_LBUF].tot_alloc - pools[POOL_LBUF].num_alloc); pools[POOL_LBUF].tot_alloc = pools[POOL_LBUF].num_alloc; } ph = NULL; try { ph = reinterpret_cast<POOLHDR *>(new char[LBUF_SIZE + sizeof(POOLHDR) + sizeof(POOLFTR)]); } catch (...) { ; // Nothing. } if (NULL == ph) { ISOUTOFMEMORY(ph); return NULL; } p = (UTF8 *)(ph + 1); pf = (POOLFTR *)(p + LBUF_SIZE); // Initialize. // ph->next = pools[POOL_LBUF].chain_head; ph->nxtfree = NULL; ph->magicnum = pools[POOL_LBUF].poolmagic; ph->pool_size = LBUF_SIZE; pf->magicnum = pools[POOL_LBUF].poolmagic; *((unsigned int *)p) = pools[POOL_LBUF].poolmagic; pools[POOL_LBUF].chain_head = ph; pools[POOL_LBUF].max_alloc++; } ph->u.buf_tag = tag; pools[POOL_LBUF].tot_alloc++; pools[POOL_LBUF].num_alloc++; if ( (LOG_ALLOCATE & mudconf.log_options) && mudstate.logging == 0 && start_log(T("DBG"), T("ALLOC"))) { Log.tinyprintf(T("Alloc[%d] (tag %s) in %s line %d buffer at %p. (%s)"), LBUF_SIZE, tag, file, line, ph, mudstate.debug_cmd); end_log(); } // If the buffer was modified after it was last freed, log it. // unsigned int *pui = (unsigned int *)p; if (*pui != pools[POOL_LBUF].poolmagic) { pool_err(T("BUG"), LOG_PROBLEMS, POOL_LBUF, tag, ph, T("Alloc"), T("buffer modified after free"), file, line); } *pui = 0; return p; }
FILE* open_log(const char * mode) { end_log(); return fopen(getLogPath(), mode); }
void do_intersectN(uint numPhrases, uint REPETITIONS){ uint iters,currPhrase; int error = 0; double time, tot_time = 0; uint **patternSets; uint numIdsPerPattern; uint numOfPatterns; readPatternSetsIntersect (&numIdsPerPattern, &numOfPatterns, &patternSets); #ifdef DEBUG_ON uint i,j; fprintf(stderr,"\n parameters: maxNunPhr %d, numPhr %d, numIdPerPhr=%d",numPhrases , numOfPatterns,numIdsPerPattern); fprintf(stderr,"\n patterns to intersect (1 list per row) = \n"); for (i=0;i<numOfPatterns; i++) { for (j=0;j<numIdsPerPattern;j++) fprintf(stderr,"[%d]", patternSets[i][j]); fprintf(stderr,"\n"); } fprintf(stderr,"\n"); #endif if (numPhrases > numOfPatterns) { fprintf(stderr,"\nBuild_il: Error during intersect2 %u/%u IDs\n", numPhrases, numOfPatterns); exit(0); } //numPhrases = numOfPatterns; #ifdef DO_LOG static char log_file_name[10]="logN.txt"; init_log(log_file_name); #endif uint *occs; uint numocc=0; uint tot_numocc=0; iters=0; currPhrase=0; for (currPhrase=0; currPhrase<numPhrases; currPhrase++) { #ifdef DEBUG_ON fprintf(stderr,"\n intersect Phrase-Pattern <<%u>> \n", currPhrase); #endif /* extract */ time = getTime (); for (iters=0;iters<REPETITIONS;iters++) { if (numocc) free (occs); error = intersect_N_il (Index, patternSets[currPhrase], numIdsPerPattern, &numocc, &occs); } tot_time += (getTime () - time)/REPETITIONS; tot_numocc += numocc; #ifdef DO_LOG out_results(patternSets[currPhrase], numIdsPerPattern, occs, numocc); #endif IFERRORIL (error); if (Verbose) { fwrite(&(currPhrase), sizeof(uint), 1, stdout); fwrite(&numocc, sizeof(numocc), 1, stdout); } #ifdef DEBUG_ON fprintf(stderr,"\n NUMOCCS = %d ",numocc);fflush(stderr); #endif if (numocc) free (occs); numocc=0; } #ifdef DO_LOG end_log() ; #endif freePatternSetsIntersect(patternSets, numOfPatterns); fprintf (stderr, "Total Num occs found = %lu\n", (ulong)tot_numocc); fprintf (stderr, "IntN time = %.8f msecs\n", tot_time*1); fprintf (stderr, "IntN_time/numOfPatterns = %.8f msecs/patt\n\n", (tot_time * 1) / numOfPatterns); fprintf (stderr, "(Load_time+IntN_time)/numOfPatterns = %.8f msecs/patt\n\n", ((Load_time+tot_time) * 1) / numOfPatterns); fprintf (stderr, "IntN_time/occ = %.8f msecs per post \n\n", (tot_time * 1) / tot_numocc); /**/ fprintf(timeFile,"\n\t occs = %9lu :: time = %.8f msecs ",(ulong)tot_numocc,tot_time*1); /**/ fprintf(timeFile,"\n\t avg time per pattern = %.8f msecs ",(tot_time * 1) / numOfPatterns); /**/ fprintf(timeFile,"\n\t avg time per occur = %.8f msecs \n",(tot_time * 1) / tot_numocc); }
void do_intersect2(uint numPhrases, uint REPETITIONS) { uint iters,currPhrase; int error = 0; double time, timeE, tot_time = 0; uint **patternSets; uint numIdsPerPattern; uint numOfPatterns; readPatternSetsIntersect (&numIdsPerPattern, &numOfPatterns, &patternSets); #ifdef DEBUG_ON uint i,j; fprintf(stderr,"\n parameters: maxNunPhr %d, numPhr %d, numIdPerPhr=%d",numPhrases , numOfPatterns,numIdsPerPattern); fprintf(stderr,"\n patterns to intersect (1 list per row) = \n"); for (i=0;i<numOfPatterns; i++) { for (j=0;j<numIdsPerPattern;j++) fprintf(stderr,"[%d]", patternSets[i][j]); fprintf(stderr,"\n"); } fprintf(stderr,"\n"); #endif if (numPhrases > numOfPatterns) { fprintf(stderr,"\nBuild_il: Error during intersect2 %u/%u IDs\n", numPhrases, numOfPatterns); exit(0); } //numPhrases = numOfPatterns; #ifdef DO_LOG static char log_file_name[10]="log.txt"; init_log(log_file_name); #endif uint *occs; uint numocc=0; uint tot_numocc=0; iters=0; currPhrase=0; for (currPhrase=0; currPhrase<numPhrases; currPhrase++) { #ifdef DEBUG_ON fprintf(stderr,"\n intersect Phrase-Pattern <<%u>> -->", currPhrase); for (i=0;i<numIdsPerPattern;i++) fprintf(stderr,"[%d]", patternSets[currPhrase][i]); #endif /* extract */ time = getTime (); for (iters=0;iters<REPETITIONS;iters++) { if (iters) free (occs); //not in the first one. error = intersect_2_il (Index, patternSets[currPhrase][0], patternSets[currPhrase][1], &numocc, &occs); } timeE=(getTime () - time)/REPETITIONS; tot_time += timeE; tot_numocc += numocc; // fprintf(stderr,"\n i %u, occs = %u",currPhrase,numocc); #ifdef DO_LOG out_results(patternSets[currPhrase], numIdsPerPattern, occs, numocc); #endif plotResults(patternSets[currPhrase][0], patternSets[currPhrase][1], timeE, currPhrase+1, matlab, outfilename); // uint i; // fprintf(stderr,"\n ******** %d Ocurrencias found ...",numocc); // for ( i=0;i<numocc; i++) {fprintf(stderr,"\n occ[%3d] ==> %d",i,occs[i]);} IFERRORIL (error); if (Verbose) { fwrite(&(currPhrase), sizeof(uint), 1, stdout); fwrite(&numocc, sizeof(numocc), 1, stdout); } #ifdef DEBUG_ON fprintf(stderr,"\n NUMOCCS = %d ",numocc);fflush(stderr); #endif //fprintf(stderr,"\n NUMOCCS = %d ",numocc);fflush(stderr); if (numocc) free (occs); //the resulting list has always allocated memory even though numoccs==0; numocc=0; } #ifdef DO_LOG end_log() ; #endif endResults( matlab, outfilename, numPhrases); freePatternSetsIntersect(patternSets, numOfPatterns); fprintf (stderr, "\nTotal Num occs found = %lu\n", (ulong)tot_numocc); fprintf (stderr, "Int2 time = %.8f msecs\n", tot_time*1); fprintf (stderr, "Int2_time/numOfPatterns = %.8f msecs/patt\n\n", (tot_time * 1) / numOfPatterns); fprintf (stderr, "(Load_time+Int2_time)/numOfPatterns = %.8f msecs/patt\n\n", ((Load_time+tot_time) * 1) / numOfPatterns); fprintf (stderr, "Int2_time/occ = %.8f msecs per post \n\n", (tot_time * 1) / tot_numocc); /**/ fprintf(timeFile,"\n\t occs = %9lu :: time = %.8f msecs ",(ulong)tot_numocc,tot_time*1); /**/ fprintf(timeFile,"\n\t avg time per pattern = %.8f msecs ",(tot_time * 1) / numOfPatterns); /**/ fprintf(timeFile,"\n\t avg time per occur = %.8f msecs \n",(tot_time * 1) / tot_numocc); }
void do_extract(uint numIdsToExtract, uint REPETITIONS) { uint iters,currID; int error = 0; double time, tot_time = 0; uint *IDs; uint numOfIDs; readPatternSetsExtract (&numOfIDs, &IDs); //max number of ids to extract #ifdef DEBUG_ON uint i; fprintf(stderr,"\n IDS = "); for (i=0;i<numOfIDs; i++) {fprintf(stderr,"[%d]", IDs[i]);} fprintf(stderr,"\n"); #endif if (numIdsToExtract > numOfIDs) { fprintf(stderr,"\nBuild_il: Error during extract %u/%u IDs\n", numIdsToExtract, numOfIDs); exit(0); } numOfIDs = numIdsToExtract; uint *occs; uint numocc=0; uint tot_numocc=0; iters=0; currID=0; for (currID=0; currID<numOfIDs; currID++) { #ifdef DEBUG_ON fprintf(stderr,"\n to extract List of ID <<%u>> \n", IDs[currID]); #endif /* extract */ time = getTime (); #ifdef DO_LOG static char log_file_name[10]="logE.txt"; init_log(log_file_name); #endif for (iters=0;iters<REPETITIONS;iters++) { if (numocc) free (occs); error = extractList_il (Index, IDs[currID], &occs, &numocc); } tot_time += (getTime () - time)/REPETITIONS; tot_numocc += numocc; #ifdef DO_LOG out_results(&(IDs[currID]), 1, occs, numocc); #endif IFERRORIL (error); if (Verbose) { fwrite(&(IDs[currID]), sizeof(uint), 1, stdout); fwrite(&numocc, sizeof(numocc), 1, stdout); } if (numocc) free (occs); numocc=0; } #ifdef DO_LOG end_log() ; #endif freePatternSetsExtract(IDs); fprintf (stderr, "Total Num occs found = %lu\n", (ulong)tot_numocc); fprintf (stderr, "extract time = %.8f msecs\n", tot_time*1); fprintf (stderr, "extract_time/Num_IDs = %.8f msecs/ID\n\n", (tot_time * 1) / numOfIDs); fprintf (stderr, "(Load_time+extract_time)/Num_IDs = %.8f msecs/ID\n\n", ((Load_time+tot_time) * 1) / numOfIDs); fprintf (stderr, "extract_time/occ = %.8f msecs per post \n\n", (tot_time * 1) / tot_numocc); /**/ fprintf(timeFile,"\n\t occs = %9lu :: time = %.8f msecs ",(ulong)tot_numocc,tot_time*1); /**/ fprintf(timeFile,"\n\t avg time per pattern = %.8f msecs ",(tot_time * 1) / numOfIDs); /**/ fprintf(timeFile,"\n\t avg time per occur = %.8f msecs \n",(tot_time * 1) / tot_numocc); }