diff --git a/examples/main.c b/examples/main.c index e785edf837445ee5622c1b10474762401bb0d286..4ac3b55aa8c40190903275efb3758c1aa7f591b2 100644 --- a/examples/main.c +++ b/examples/main.c @@ -183,6 +183,7 @@ int main(int argc, char *argv[]) { char *param_filename = NULL; char restart_file[200] = ""; unsigned long long cpufreq = 0; + float dump_tasks_threshold = 0.f; struct cmdparams cmdps; cmdps.nparam = 0; cmdps.param[0] = NULL; @@ -304,6 +305,10 @@ int main(int argc, char *argv[]) { OPT_INTEGER('Y', "threadpool-dumps", &dump_threadpool, "Time-step frequency at which threadpool tasks are dumped.", NULL, 0, 0), + OPT_FLOAT(0, "dump-tasks-threshold", &dump_tasks_threshold, + "Fraction of the total step's time spent in a task to trigger " + "a dump of the task plot on this step", + NULL, 0, 0), OPT_END(), }; struct argparse argparse; @@ -1410,13 +1415,14 @@ int main(int argc, char *argv[]) { /* Dump the task data using the given frequency. */ if (dump_tasks && (dump_tasks == 1 || j % dump_tasks == 1)) { #ifdef SWIFT_DEBUG_TASKS - task_dump_all(&e, j + 1); + if (dump_tasks_threshold == 0.) task_dump_all(&e, j + 1); #endif /* Generate the task statistics. */ char dumpfile[40]; snprintf(dumpfile, 40, "thread_stats-step%d.dat", e.step + 1); - task_dump_stats(dumpfile, &e, /* header = */ 0, /* allranks = */ 1); + task_dump_stats(dumpfile, &e, dump_tasks_threshold, + /* header = */ 0, /* allranks = */ 1); } #ifdef SWIFT_CELL_GRAPH diff --git a/src/task.c b/src/task.c index 81e386a107bbb0ad9d013c14f39fc8dca7ca8511..3efc2fe4f8457e6d9c69a60b3e19ec8accbed05b 100644 --- a/src/task.c +++ b/src/task.c @@ -1095,12 +1095,14 @@ void task_dump_all(struct engine *e, int step) { * * @param dumpfile name of the file for the output. * @param e the #engine + * @param dump_task_threshold Fraction of the step time above whic any task + * triggers a call to task_dump_all(). * @param header whether to write a header include file. * @param allranks do the statistics over all ranks, if not just the current * one, only used if header is false. */ -void task_dump_stats(const char *dumpfile, struct engine *e, int header, - int allranks) { +void task_dump_stats(const char *dumpfile, struct engine *e, + float dump_tasks_threshold, int header, int allranks) { const ticks function_tic = getticks(); @@ -1127,6 +1129,7 @@ void task_dump_stats(const char *dumpfile, struct engine *e, int header, double stepdt = (double)e->toc_step - (double)e->tic_step; double total[1] = {0.0}; + int dumped_plot_data = 0; for (int l = 0; l < e->sched.nr_tasks; l++) { int type = e->sched.tasks[l].type; @@ -1155,10 +1158,21 @@ void task_dump_stats(const char *dumpfile, struct engine *e, int header, total[0] += dt; /* Check if this is a problematic task and make a report. */ - if (e->verbose) - if (dt / stepdt > 0.05) - message("Long running task detected: %s/%s using %.1f%% of step runtime", taskID_names[type], - subtaskID_names[subtype], dt / stepdt * 100.0); + if (dump_tasks_threshold > 0. && dt / stepdt > dump_tasks_threshold) { + + if (e->verbose) + message( + "Long running task detected: %s/%s using %.1f%% of step runtime", + taskID_names[type], subtaskID_names[subtype], + dt / stepdt * 100.0); + + if (!dumped_plot_data) { +#ifdef SWIFT_DEBUG_TASKS + task_dump_all(e, e->step + 1); +#endif + dumped_plot_data = 1; + } + } } } diff --git a/src/task.h b/src/task.h index a093031c9ffeb8ec8480bc22f0b7bd9b429c0386..97ff8b446bcfbc7068cccd05b053875842d3146a 100644 --- a/src/task.h +++ b/src/task.h @@ -265,8 +265,8 @@ int task_lock(struct task *t); void task_do_rewait(struct task *t); void task_print(const struct task *t); void task_dump_all(struct engine *e, int step); -void task_dump_stats(const char *dumpfile, struct engine *e, int header, - int allranks); +void task_dump_stats(const char *dumpfile, struct engine *e, + float dump_tasks_threshold, int header, int allranks); void task_dump_active(struct engine *e); void task_get_full_name(int type, int subtype, char *name); void task_get_group_name(int type, int subtype, char *cluster);