7 profiler::profiler(
int nlogs)
16 pthread_mutex_init(&my_mutex, NULL);
18 pthread_mutexattr_t attr;
19 pthread_mutexattr_init(&attr);
20 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
22 pthread_mutex_init(&thmutex, &attr);
25 pthread_cond_init(&thcond, NULL);
29 int profiler::set_numlogs(
int nlogs)
31 if(logs)
delete[] logs;
34 logs =
new seqlog[numlogs];
43 int profiler::set_base_path(
const std::string& bp)
49 int profiler::get_nextlog(
int clog)
51 if(clog == numlogs - 1)
return 0;
55 int profiler::logseqmsg(
const char * sm,
const char * sp, timespec *st)
59 currlog = get_nextlog(currlog);
62 memcpy(&(logs[currlog].seqmsg), sm, SEQ_MSG_LEN);
63 memcpy(logs[currlog].seqpt, sp, 4);
64 logs[currlog].seqtm.tv_sec = st->tv_sec;
65 logs[currlog].seqtm.tv_nsec = st->tv_nsec;
72 bool profiler::logs_to_write()
78 int profiler::write_logs()
80 while(abslast_written < abscurrlog && fd >= 0)
85 curr_path = base_path +
"_" + fnamebuff +
".prof";
86 fd = open(curr_path.c_str(), O_WRONLY | O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
90 std::cerr <<
"Profiler error opening file: " << curr_path <<
"\n";
118 last_written = get_nextlog(last_written);
131 void profiler::start()
137 sigaddset(&set, SIGIO);
139 pthread_sigmask(SIG_BLOCK, &set, 0);
141 std::cout <<
"profiler started\n";
145 pthread_mutex_lock(&thmutex);
146 pthread_cond_wait(&thcond, &thmutex);
147 pthread_mutex_unlock(&thmutex);
int logs_per_file
maximum number of logs to write per file.
int abslast_written
last file written
int last_written
index of the last file written.
int logs_in_file
number of logs in current file.
int get_visao_filename(char *buffer, struct timeval *tv)
Writes the standard visao unique filename for a timeval to the buffer.
The namespace of VisAO software.
int fd
file descriptor of the currently open file.