/* output a specific function's hash table to the profile file */ void writeHashTable(uint32_t functionNumber, pathHashTable_t* hashTable) { int outFile = getOutFile(); PathProfileHeader header; uint32_t i; header.fnNumber = functionNumber; header.numEntries = hashTable->pathCounts; if (write(outFile, &header, sizeof(PathProfileHeader)) < 0) { fprintf(stderr, "error: unable to write function header to output file.\n"); return; } for (i = 0; i < ARBITRARY_HASH_BIN_COUNT; i++) { pathHashEntry_t* hashEntry = hashTable->hashBins[i]; while (hashEntry) { pathHashEntry_t* temp; PathProfileTableEntry pte; pte.pathNumber = hashEntry->pathNumber; pte.pathCounter = hashEntry->pathCount; if (write(outFile, &pte, sizeof(PathProfileTableEntry)) < 0) { fprintf(stderr, "error: unable to write path entry to output file.\n"); return; } temp = hashEntry; hashEntry = hashEntry->next; free (temp); } } }
/* write an array table to file */ void writeArrayTable(uint32_t fNumber, ftEntry_t* ft, uint32_t* funcCount) { int outFile = getOutFile(); uint32_t arrayHeaderLocation = 0; uint32_t arrayCurrentLocation = 0; uint32_t arrayIterator = 0; uint32_t functionUsed = 0; uint32_t pathCounts = 0; /* look through each entry in the array to determine whether the function was executed at all */ for( arrayIterator = 0; arrayIterator < ft->size; arrayIterator++ ) { uint32_t pc = ((uint32_t*)ft->array)[arrayIterator]; /* was this path executed? */ if( pc ) { PathProfileTableEntry pte; pte.pathNumber = arrayIterator; pte.pathCounter = pc; pathCounts++; /* one-time initialization stuff */ if(!functionUsed) { arrayHeaderLocation = lseek(outFile, 0, SEEK_CUR); lseek(outFile, sizeof(PathProfileHeader), SEEK_CUR); functionUsed = 1; (*funcCount)++; } /* write path data */ if (write(outFile, &pte, sizeof(PathProfileTableEntry)) < 0) { fprintf(stderr, "error: unable to write path entry to output file.\n"); return; } } } /* If this function was executed, write the header */ if( functionUsed ) { PathProfileHeader fHeader; fHeader.fnNumber = fNumber; fHeader.numEntries = pathCounts; arrayCurrentLocation = lseek(outFile, 0, SEEK_CUR); lseek(outFile, arrayHeaderLocation, SEEK_SET); if (write(outFile, &fHeader, sizeof(PathProfileHeader)) < 0) { fprintf(stderr, "error: unable to write function header to output file.\n"); return; } lseek(outFile, arrayCurrentLocation, SEEK_SET); } }
void lsSnpPdbChimeraSnpAnn(struct sqlConnection *conn, char *pdbId, char *primarySnpId, struct tempName *outName) /* Generate a chimerax file for the given pdb with all non-synonymous SNPs * that have been mapped to this protein. If primarySnpId is not NULL, it is * colored differently than the other SNPs. Fills in outName structure. */ { getOutFile(pdbId, primarySnpId, outName); char where[512]; sqlSafefFrag(where, sizeof(where), "(pdbId=\"%s\")", pdbId); chimeraxGen(conn, pdbId, where, primarySnpId, outName->forCgi); }
/* write_profiling_data - Write a raw block of profiling counters out to the * llvmprof.out file. Note that we allow programs to be instrumented with * multiple different kinds of instrumentation. For this reason, this function * may be called more than once. */ void write_profiling_data(enum ProfilingType PT, unsigned *Start, unsigned NumElements) { int PTy; int outFile = getOutFile(); /* Write out this record! */ PTy = PT; if( write(outFile, &PTy, sizeof(int)) < 0 || write(outFile, &NumElements, sizeof(unsigned)) < 0 || write(outFile, Start, NumElements*sizeof(unsigned)) < 0 ) { fprintf(stderr,"error: unable to write to output file."); exit(0); } }
/* write_profiling_data - Write a raw block of profiling counters out to the * llvmprof.out file. Note that we allow programs to be instrumented with * multiple different kinds of instrumentation. For this reason, this function * may be called more than once. */ void write_profiling_data(enum ProfilingType PT, unsigned *Start, unsigned NumElements) { int PTy; int outFile = getOutFile(); int w1, w2, w3; /* Write out this record! */ PTy = PT; w1 = write(outFile, (const char *) &PTy, sizeof(int)); w2 = write(outFile, (const char *) &NumElements, sizeof(unsigned)); w3 = write(outFile, (const char *) Start, NumElements*sizeof(unsigned)); if (w1 < 0 || w2 < 0 || w3 < 0) { fprintf(stderr,"error: unable to write to output file."); exit(0); } printf("write_profiling_data: type=%d, elements=%u\n", PT, NumElements); printf("written to file: %d/%d/%d\n", w1, w2, w3); }
/* * Writes out a path profile given a function table, in the following format. * * * | <-- 32 bits --> | * +-----------------+-----------------+ * 0x00 | profileType | functionCount | * +-----------------+-----------------+ * 0x08 | functionNum | profileEntries | // function 1 * +-----------------+-----------------+ * 0x10 | pathNumber | pathCounter | // entry 1.1 * +-----------------+-----------------+ * 0x18 | pathNumber | pathCounter | // entry 1.2 * +-----------------+-----------------+ * ... | ... | ... | // entry 1.n * +-----------------+-----------------+ * ... | functionNum | profileEntries | // function 2 * +-----------------+-----------------+ * ... | pathNumber | pathCounter | // entry 2.1 * +-----------------+-----------------+ * ... | pathNumber | pathCounter | // entry 2.2 * +-----------------+-----------------+ * ... | ... | ... | // entry 2.n * +-----------------+-----------------+ * */ static void pathProfAtExitHandler() { int outFile = getOutFile(); uint32_t i; uint32_t header[2] = { PathInfo, 0 }; uint32_t headerLocation; uint32_t currentLocation; /* skip over the header for now */ headerLocation = lseek(outFile, 0, SEEK_CUR); lseek(outFile, 2*sizeof(uint32_t), SEEK_CUR); /* Iterate through each function */ for( i = 0; i < ftSize; i++ ) { if( ft[i].type == ProfilingArray ) { writeArrayTable(i+1,&ft[i],header + 1); } else if( ft[i].type == ProfilingHash ) { /* If the hash exists, write it to file */ if( ft[i].array ) { writeHashTable(i+1,ft[i].array); header[1]++; free(ft[i].array); } } } /* Setup and write the path profile header */ currentLocation = lseek(outFile, 0, SEEK_CUR); lseek(outFile, headerLocation, SEEK_SET); if (write(outFile, header, sizeof(header)) < 0) { fprintf(stderr, "error: unable to write path profile header to output file.\n"); return; } lseek(outFile, currentLocation, SEEK_SET); }