Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability for users to specify PAPI events in Dr Hook #27

Draft
wants to merge 5 commits into
base: papi
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
285 changes: 168 additions & 117 deletions src/fiat/drhook/drhook.c
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,8 @@ insert_calltree(int tid, drhook_key_t *keyptr)
static void
remove_calltree(int tid, drhook_key_t *keyptr,
const double *delta_wall, const double *delta_cpu,
const long long int *delta_cycles,long_long * delta_counters)
const long long int *delta_cycles,long_long * delta_counters
)
{
if (tid >= 1 && tid <= numthreads) {
drhook_calltree_t *treeptr = thiscall[tid-1];
Expand All @@ -1061,10 +1062,10 @@ remove_calltree(int tid, drhook_key_t *keyptr,
drhook_key_t *parent_keyptr = treeptr->prev->keyptr;
if (parent_keyptr) { /* extra security */
#if defined(DR_HOOK_HAVE_PAPI)
drhook_papi_add(NULL,
parent_keyptr->delta_counters_child,
delta_counters
);
drhook_papi_add(NULL,
parent_keyptr->delta_counters_child,
delta_counters
);
#endif
if (opt_walltime) {
parent_keyptr->delta_wall_child += (*delta_wall);
Expand Down Expand Up @@ -1626,7 +1627,7 @@ signal_drhook(int sig SIG_EXTRA_ARGS)
------------------------------------------------------------*/

/* if (sig != SIGTERM) signal(SIGTERM, SIG_DFL); */ /* Let the default SIGTERM to occur */

// max_threads = drhook_oml_get_max_threads();
if (nsigs == 1) {
/*---- First call to signal handler: call alarm(drhook_harakiri_timeout), tracebacks, exit ------*/
Expand Down Expand Up @@ -2609,7 +2610,7 @@ process_options()
opt_cpuprof = 0; /* Note: Switches cpuprof OFF */
opt_calls = 1;
opt_cycles = 1;
opt_papi = 1;
opt_papi = 1;
OPTPRINT(fp,"%s%s",comma,"COUNTERS"); comma = ",";
}
else if (strequ(p,"CPUPROF")) {
Expand Down Expand Up @@ -2648,7 +2649,7 @@ process_options()
opt_callpath = 1;
OPTPRINT(fp,"%s%s",comma,"CALLPATH"); comma = ",";
} else {
printf("DrHook: Note - no match for HOOK_OPT : %s\n",p);
printf("DrHook: Note - no match for HOOK_OPT : %s\n",p);
}
p = strtok(NULL,delim);
}
Expand Down Expand Up @@ -2687,6 +2688,45 @@ process_options()
OPTPRINT(fp,"%s %s [%s@%s:%d] DR_HOOK_CALLTRACE=%d\n",pfx,TIMESTR(tid),FFL,opt_calltrace);
}

#if defined(DR_HOOK_HAVE_PAPI)
if (opt_papi) {
newline = 0;
env = getenv("DR_HOOK_PAPI_COUNTERS");
if (env) {
const char delim[] = ", \t/";
char *comma = " DR_HOOK_PAPI_COUNTERS=\"";
char *s = strdup_drhook(env);
char *p = s;
while (*p) {
if (islower(*p)) *p = toupper(*p);
p++;
}
p = strtok(s,delim);
for (int i = 0; p && i < drhook_papi_max_num_counters(); p = strtok(NULL,delim), i++) {
drhook_papi_add_counter_name(strdup_drhook(p));
OPTPRINT(fp,"%s%s",comma,p); comma = ",";
}

free_drhook(s);
if (*comma == ',') {
OPTPRINT(fp,"\"\n");
newline = 0;
}
if (newline) OPTPRINT(fp,"\n");
} else {
const char* default_events[4] = {
"PAPI_TOT_CYC",
"PAPI_FP_OPS",
"PAPI_L1_DCA",
"PAPI_L2_DCM"
};
for (int i = 0; i < 4; i++) {
drhook_papi_add_counter_name(strdup_drhook(default_events[i]));
}
}
}
#endif

if (opt_wallprof || opt_cpuprof || opt_memprof || opt_timeline) {
atexit(do_prof);
}
Expand Down Expand Up @@ -2826,9 +2866,9 @@ getkey(int tid, const char *name, int name_len,
(opt_trim && strncasecmp(keyptr->name, name, name_len) == 0)))) {
if (opt_walltime) keyptr->wall_in = walltime ? *walltime : WALLTIME();
if (opt_cputime) keyptr->cpu_in = cputime ? *cputime : CPUTIME();
if (opt_cycles) keyptr->cycles_in = cycles ? *cycles : ec_get_cycles();
if (opt_cycles) keyptr->cycles_in = cycles ? *cycles : ec_get_cycles();
#if defined(DR_HOOK_HAVE_PAPI)
drhook_papi_readAll(keyptr->counters_in);
drhook_papi_readAll(keyptr->counters_in);
#endif
if (any_memstat) memstat(keyptr,&tid,1);
if (opt_calls) {
Expand Down Expand Up @@ -3426,7 +3466,7 @@ c_drhook_check_watch_(const char *where,
double cputime = opt_cputime ? CPUTIME() : 0; \
long long int cycles = opt_cycles ? ec_get_cycles() : 0; \
long long int hwm = opt_gethwm ? gethwm_() : 0; \
long long int stk = opt_getstk ? getstk_() : 0; \
long long int stk = opt_getstk ? getstk_() : 0; \
PAPIREAD

/*=== c_drhook_set_lhook_ ===*/
Expand Down Expand Up @@ -4310,11 +4350,11 @@ c_drhook_print_(const int *ftnunitno,
while (keyptr) {
if (keyptr->name && (keyptr->status == 0 || signal_handler_called)) {
#if defined(DR_HOOK_HAVE_PAPI)
drhook_papi_subtract(p->counter_self,
keyptr->delta_counters_all,
keyptr->delta_counters_child);
drhook_papi_cpy(p->counter_tot,
keyptr->delta_counters_all);
drhook_papi_subtract(p->counter_self,
keyptr->delta_counters_all,
keyptr->delta_counters_child
);
drhook_papi_cpy(p->counter_tot, keyptr->delta_counters_all);
#endif
p->self = opt_wallprof ?
keyptr->delta_wall_all - keyptr->delta_wall_child :
Expand Down Expand Up @@ -4367,19 +4407,20 @@ c_drhook_print_(const int *ftnunitno,
pfx,TIMESTR(tid),FFL,
myproc,filename);
}
fp = fopen(filename,"w");
fp = fopen(filename,"w");
if (!fp) goto finish_3;

if (opt_papi==1){
if ((myproc == 1 && mon_out_procs == -1) || mon_out_procs == myproc) {
fprintf(stderr,
"%s %s [%s@%s:%d] Writing counter information of proc#%d into file '%s'\n",
pfx,TIMESTR(tid),FFL,
myproc,csvfilename);
}
fpcsv = fopen(csvfilename,"w");
if (!fpcsv) goto finish_3;
}
if (opt_papi==1){
if ((myproc == 1 && mon_out_procs == -1) || mon_out_procs == myproc) {
fprintf(stderr,
"%s %s [%s@%s:%d] Writing counter information of proc#%d into file '%s'\n",
pfx,TIMESTR(tid),FFL,
myproc,csvfilename
);
}
fpcsv = fopen(csvfilename,"w");
if (!fpcsv) goto finish_3;
}

/* alphanumerical sorting to find out clusters of the same routine but on different threads */
/* also find out total wall clock time */
Expand Down Expand Up @@ -4535,99 +4576,109 @@ c_drhook_print_(const int *ftnunitno,
}
}

fprintf(fp,"\n");
{
len =
fprintf(fp," # %% Time Cumul Self Total # of calls Self Total ");
}
fprintf(fp,"Routine@<thread-id>");
if (opt_clusterinfo) fprintf(fp," [Cluster:(id,size)]");
fprintf(fp,"\n");
if (opt_sizeinfo) fprintf(fp,"%*s %s\n",len-20," ","(Size; Size/sec; Size/call; MinSize; MaxSize)");
fprintf(fp, " (self) (sec) (sec) (sec) ms/call ms/call\n");
fprintf(fp,"\n");

cumul = 0;
for (j=0; j<nprof; ) {
int cluster_size = clusize[p->cluster];
if (p->pc < percent_limit) break;
if (opt_cputime) {
cumul += p->self;
}
else {
if (p->is_max || cluster_size == 1) cumul += p->self;
}

{
fprintf(fp, fmt,
++j, p->pc, cumul, p->self, p->total, p->calls,
p->percall_ms_self, p->percall_ms_total,
p->is_max ? "*" : " ");
}
print_routine_name(fp, p, len, cluster_size);

if (opt_sizeinfo && p->sizeinfo > 0) {
char s1[DRHOOK_STRBUF], s2[DRHOOK_STRBUF], s3[DRHOOK_STRBUF];
char s4[DRHOOK_STRBUF], s5[DRHOOK_STRBUF];
lld_commie(p->sizeinfo,s1);
dbl_commie(p->sizespeed,s2);
dbl_commie(p->sizeavg,s3);
lld_commie(p->min_sizeinfo,s4);
lld_commie(p->max_sizeinfo,s5);
fprintf(fp,"\n%*s (%s; %s; %s; %s; %s)",len-20," ",s1,s2,s3,s4,s5);
}
fprintf(fp,"\n");
p++;
} /* for (j=0; j<nprof; ) */
fprintf(fp,"\n");
{
len =
fprintf(fp," # %% Time Cumul Self Total # of calls Self Total ");
}
fprintf(fp, "Routine@<thread-id>");
if (opt_clusterinfo)
fprintf(fp, " [Cluster:(id,size)]");
fprintf(fp, "\n");
if (opt_sizeinfo)
fprintf(fp, "%*s %s\n",len-20," ","(Size; Size/sec; Size/call; MinSize; MaxSize)");
fprintf(fp, " (self) (sec) (sec) (sec) ms/call ms/call\n");
fprintf(fp, "\n");

cumul = 0;
for (j = 0; j < nprof; ) {
int cluster_size = clusize[p->cluster];
if (p->pc < percent_limit)
break;
if (opt_cputime) {
cumul += p->self;
} else {
if (p->is_max || cluster_size == 1)
cumul += p->self;
}

{
fprintf(fp, fmt,
++j, p->pc, cumul, p->self, p->total, p->calls,
p->percall_ms_self, p->percall_ms_total,
p->is_max ? "*" : " ");
}
print_routine_name(fp, p, len, cluster_size);

if (opt_sizeinfo && p->sizeinfo > 0) {
char s1[DRHOOK_STRBUF], s2[DRHOOK_STRBUF], s3[DRHOOK_STRBUF];
char s4[DRHOOK_STRBUF], s5[DRHOOK_STRBUF];
lld_commie(p->sizeinfo,s1);
dbl_commie(p->sizespeed,s2);
dbl_commie(p->sizeavg,s3);
lld_commie(p->min_sizeinfo,s4);
lld_commie(p->max_sizeinfo,s5);
fprintf(fp,"\n%*s (%s; %s; %s; %s; %s)",len-20," ",s1,s2,s3,s4,s5);
}
fprintf(fp,"\n");
p++;
} /* for (j=0; j<nprof; ) */
fclose(fp);

#if defined(DR_HOOK_HAVE_PAPI)
if (opt_papi){
p=prof;
int first_counter_is_cyc=0;
if (strcmp(drhook_papi_counter_name(0,0),"PAPI_TOT_CYC")==0)
first_counter_is_cyc=1;
{
len =
fprintf(fpcsv,"Routine,MPI Rank,ThreadId,SelfRank,%% Self Time,Cumul,Excl Time,Incl. Time,#Calls");
for (int c=0;c<drhook_papi_num_counters();c++)
fprintf(fpcsv,",%s(excl)",drhook_papi_counter_name(c,1));
for (int c=0;c<drhook_papi_num_counters();c++)
fprintf(fpcsv,",%s(incl)",drhook_papi_counter_name(c,1));
if (first_counter_is_cyc==1)
fprintf(fpcsv,",Mcyc/sec(excl),Mcyc/sec(incl)");
fprintf(fpcsv,"\n");
}

cumul = 0;
for (j=0; j<nprof; ) {
int cluster_size = clusize[p->cluster];
if (opt_cputime)
cumul += p->self;
else
if (p->is_max || cluster_size == 1) cumul += p->self;

{
fprintf(fpcsv, csvfmt,
p->name,
myproc-1,
p->tid-1
,++j, p->pc, cumul, p->self, p->total, p->calls,
p->is_max ? "*" : " ");
for (int c=0;c<drhook_papi_num_counters();c++)
fprintf(fpcsv,",%lld",p->counter_self[c]);
for (int c=0;c<drhook_papi_num_counters();c++)
fprintf(fpcsv,",%lld",p->counter_tot[c]);
if (first_counter_is_cyc==1)
fprintf(fpcsv,",%.3f,%.3f",
p->counter_self[0]/p->self/1000000.0,
p->counter_tot[0]/p->total/1000000.0
);
}
fprintf(fpcsv,"\n");
p++;
} /* for (j=0; j<nprof; ) */
}
if (opt_papi){
p=prof;
int first_counter_is_cyc=0;
char event_name[drhook_papi_max_name_len()];
drhook_papi_counter_name(0, event_name);
if (strcmp(event_name,"PAPI_TOT_CYC") == 0)
first_counter_is_cyc=1;
{
len =
fprintf(fpcsv,"Routine,MPI Rank,ThreadId,SelfRank,%% Self Time,Cumul,Excl Time,Incl. Time,#Calls");
for (int c=0; c < drhook_papi_num_counters(); c++) {
drhook_papi_counter_name(c, event_name);
fprintf(fpcsv, ",%s(excl)", event_name);
}
for (int c=0; c < drhook_papi_num_counters(); c++) {
drhook_papi_counter_name(c, event_name);
fprintf(fpcsv, ",%s(incl)", event_name);
}
if (first_counter_is_cyc == 1)
fprintf(fpcsv, ",Mcyc/sec(excl),Mcyc/sec(incl)");
fprintf(fpcsv, "\n");
}

cumul = 0;
for (j=0; j<nprof; ) {
int cluster_size = clusize[p->cluster];
if (opt_cputime)
cumul += p->self;
else
if (p->is_max || cluster_size == 1) cumul += p->self;

{
fprintf(fpcsv, csvfmt,
p->name,
myproc-1,
p->tid-1,
++j, p->pc, cumul, p->self, p->total, p->calls,
p->is_max ? "*" : " "
);
for (int c=0;c<drhook_papi_num_counters();c++)
fprintf(fpcsv,",%lld",p->counter_self[c]);
for (int c=0;c<drhook_papi_num_counters();c++)
fprintf(fpcsv,",%lld",p->counter_tot[c]);
if (first_counter_is_cyc==1)
fprintf(fpcsv,",%.3f,%.3f",
p->counter_self[0]/p->self/1000000.0,
p->counter_tot[0]/p->total/1000000.0
);
}
fprintf(fpcsv, "\n");
p++;
} /* for (j=0; j<nprof; ) */
}
#endif
finish_3:
free_drhook(filename);
Expand Down
Loading
Loading