static int pi_prof_print(struct profiler *profiler) { unsigned long counter = 0; int err; int len_name, len_raw_cnt, len_ms_cnt, overflow; u8 buffer[32]; u8 str_raw_cnt[] = "RAW_CNT:"; u8 str_ms_cnt[] = "MS_CNT:"; profiler_dbg("%s\n", __func__); err = pi_prof_get_counter(profiler, &counter, &overflow); if (err < 0) return err; len_name = strlen(profiler->name); len_raw_cnt = strlen(str_raw_cnt); len_ms_cnt = strlen(str_ms_cnt); memcpy(buffer, profiler->name, len_name); memcpy(buffer + len_name, str_raw_cnt, len_raw_cnt); memcpy(buffer + len_name + len_raw_cnt, str_ms_cnt, len_ms_cnt); profiler_print(buffer); return 0; }
int main( int argc, const char* argv[] ) { int i,j,iret; double first[SIZE][SIZE]; double second[SIZE][SIZE]; double multiply[SIZE][SIZE]; double dtime; for (i = 0; i < SIZE; i++) { //rows in first for (j = 0; j < SIZE; j++) { //columns in first first[i][j]=i+j; second[j][i]=i-j; multiply[i][j]=0.0; } } profiler_init(); dtime = dclock(); profiler_start(); iret=mm(first,second,multiply); profiler_stop(); dtime = dclock()-dtime; profiler_print(); printf( "Time: %le \n", dtime); fflush( stdout ); double check=0.0; for(i=0;i<SIZE;i++){ for(j=0;j<SIZE;j++){ check+=multiply[i][j]; } } printf("check %le \n",check); return iret; }
/** * @brief Generic routine for profiler error output * @param file Generally called with __FILE__ (gcc), contains the file name where allocation is done * @param func Generally called with __FUNCTION__ (gcc), contains the function name where allocation is done * @param line Generally called with __LINE__ (gcc), contains the line number in related file * @param msg Profiling message suffix to be printed */ void profiler_err(char *file, char *func, u_int line, char *msg) { char buff[80]; char buf[BUFSIZ]; char *fill; if (!(aspectworld.proflevel & PROFILE_WARN)) return; /* Stock a pattern without printing */ if (profiler_print(file, func, line, msg)) return; fill = (profiler_depth - 6 > 0 ? alloca(profiler_depth + 1) : ""); if (profiler_depth - 6 > 0) { memset(fill, ' ', profiler_depth); fill[profiler_depth] = 0x00; } if (aspectworld.endline != NULL) { snprintf(buff, sizeof(buff), " <%s@%s:%s>", aspectworld.colorfunction(func), aspectworld.colorfilename(file), aspectworld.colornumber("%u", line)); snprintf(buf, BUFSIZ, " %s %s %-70s %s \n", aspectworld.colorwarn("[W]"), fill, buff, aspectworld.colorwarn(msg)); } else { snprintf(buff, sizeof(buff), " <%s@%s:%u>", func, file, line); snprintf(buf, BUFSIZ, " [W] %s %-70s %s \n", fill, buff, msg); } if (aspectworld.profile_err != NULL) aspectworld.profile_err(buf); else fprintf(stderr, "No profiling function specified.\n"); if (aspectworld.endline != NULL) aspectworld.endline(); profiler_reset(0); }
/** * @brief Write the last profiling information * @param file Generally called with __FILE__ (gcc), contains the file name where allocation is done * @param func Generally called with __FUNCTION__ (gcc), contains the function name where allocation is done * @param line Generally called with __LINE__ (gcc), contains the line number in related file */ void profiler_out(char *file, char *func, u_int line) { char buff[160]; char *space; char b_dir[2]; if (!(aspectworld.proflevel & PROFILE_FUNCS)) return; /* Stock a pattern, without printing */ if (profiler_print(file, func, line, NULL)) return; if (profiler_depth > 80) profiler_depth = 1; space = alloca(profiler_depth + 1); memset(space, 0x00, profiler_depth); memset(space, ' ', profiler_depth); space[profiler_depth] = 0x00; if (aspectworld.endline != NULL) { b_dir[0] = profiler_direction; b_dir[1] = '\0'; snprintf(buff, sizeof(buff), "%s %s %s <%s@%s:%s>\n", space, aspectworld.colornumber("%u", profiler_depth), aspectworld.colorfieldstr(b_dir), aspectworld.colorfunction(func), aspectworld.colorfilename(file), aspectworld.colornumber("%u", line)); } else { snprintf(buff, sizeof(buff), "%s %u %c <%s@%s:%u>\n", space, profiler_depth, profiler_direction, func, file,line); } if (aspectworld.profile) aspectworld.profile(buff); if (aspectworld.endline != NULL) aspectworld.endline(); }