From: Gonzalo A. <ga...@us...> - 2007-08-02 15:00:31
|
Update of /cvsroot/mod-c/ehtml/src In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv1837/src Modified Files: Profiling.cpp Log Message: Optimization: saveProfile() is now a little gentler. >From now on, saveProfile() generates a single file per process, not a file for each request. This makes profiling data merges quite faster, provided that saveProfile() is called once per process (preferably with atexti(saveProfile);). Index: Profiling.cpp =================================================================== RCS file: /cvsroot/mod-c/ehtml/src/Profiling.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Profiling.cpp 12 Mar 2007 19:18:46 -0000 1.8 --- Profiling.cpp 2 Aug 2007 15:00:25 -0000 1.9 *************** *** 108,120 **** } void saveProfile() { void* cb = NULL; struct runspec spec; - char file[48]; - struct timeval now; - gettimeofday(&now, NULL); - snprintf(file, sizeof(file), "/tmp/ehtml_profile.%d.%lu.%lu", - getpid(), now.tv_sec, now.tv_usec); - FILE* f = fopen(file, "at"); while (profile_tick(&cb, &spec), cb != NULL) fprintf(f, "%s@%s:%d\ta%llu\ts%llu\tn%llu\n", --- 108,135 ---- } + #define EHTML_PROFILE "ehtml_profile" + void saveProfile() { + char* file = NULL; + if (file == NULL) { + char* tmpdir = getenv("TMPDIR"); + if (tmpdir == NULL) + tmpdir = "/tmp"; + size_t len = strlen(tmpdir)+1+strlen(EHTML_PROFILE)+1+10; + file = (char*)malloc(len+1); + if (file == NULL) + return; + snprintf(file, len, "%s/%s.%d", + tmpdir, EHTML_PROFILE, getpid()); + } + + FILE* f = fopen(file, "at"); + free(file); + + if (f == NULL) + return; + void* cb = NULL; struct runspec spec; while (profile_tick(&cb, &spec), cb != NULL) fprintf(f, "%s@%s:%d\ta%llu\ts%llu\tn%llu\n", *************** *** 122,129 **** spec.accum, spec.self, spec.ncalls); fclose(f); - char file1[53]; - snprintf(file1, sizeof(file1), "%s.done", file); - rename(file, file1); - unlink(file); } --- 137,140 ---- |