Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@keichi
Created March 4, 2018 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keichi/01f872dee91c4db3b89d8a8970c130e8 to your computer and use it in GitHub Desktop.
Save keichi/01f872dee91c4db3b89d8a8970c130e8 to your computer and use it in GitHub Desktop.
Slurm plugin to trace SPANK function calls
#include <slurm/spank.h>
SPANK_PLUGIN(trace, 1);
static void trace_spank_call(spank_t spank, const char *func_name)
{
char *ctx;
switch (spank_context()) {
case S_CTX_ERROR:
ctx = "error";
break;
case S_CTX_LOCAL:
ctx = "local";
break;
case S_CTX_REMOTE:
ctx = "remote";
break;
case S_CTX_ALLOCATOR:
ctx = "allocator";
break;
case S_CTX_SLURMD:
ctx = "slurmd";
break;
case S_CTX_JOB_SCRIPT:
ctx = "job_script";
break;
}
int job_id = -1, node_id = -1, task_id = -1;
spank_get_item(spank, S_JOB_ID, &job_id);
spank_get_item(spank, S_JOB_NODEID, &node_id);
spank_get_item(spank, S_TASK_GLOBAL_ID, &task_id);
slurm_info("%s called in %s context (job: %d, node: %d, task: %d)",
func_name, ctx, job_id, node_id, task_id);
}
int slurm_spank_init(spank_t spank, int ac, char *argv[])
{
trace_spank_call(spank, "init");
return ESPANK_SUCCESS;
}
int slurm_spank_slurmd_init(spank_t spank, int ac, char *argv[])
{
trace_spank_call(spank, "slurmd_init");
return ESPANK_SUCCESS;
}
int slurm_spank_job_prolog(spank_t spank, int ac, char *argv[])
{
trace_spank_call(spank, "job_prolog");
return ESPANK_SUCCESS;
}
int slurm_spank_init_post_opt(spank_t spank, int ac, char *argv[])
{
trace_spank_call(spank, "post_opt");
return ESPANK_SUCCESS;
}
int slurm_spank_local_user_init(spank_t spank, int ac, char *argv[])
{
trace_spank_call(spank, "local_user_init");
return ESPANK_SUCCESS;
}
int slurm_spank_user_init(spank_t spank, int ac, char *argv[])
{
trace_spank_call(spank, "user_init");
return ESPANK_SUCCESS;
}
int slurm_spank_task_init_priviliged(spank_t spank, int ac, char *argv[])
{
trace_spank_call(spank, "task_init_priviliged");
return ESPANK_SUCCESS;
}
int slurm_spank_task_init(spank_t spank, int ac, char *argv[])
{
trace_spank_call(spank, "task_init");
return ESPANK_SUCCESS;
}
int slurm_spank_task_post_fork(spank_t spank, int ac, char *argv[])
{
trace_spank_call(spank, "task_post_fork");
return ESPANK_SUCCESS;
}
int slurm_spank_task_exit(spank_t spank, int ac, char *argv[])
{
trace_spank_call(spank, "task_exit");
return ESPANK_SUCCESS;
}
int slurm_spank_job_epilog(spank_t spank, int ac, char *argv[])
{
trace_spank_call(spank, "job_epilog");
return ESPANK_SUCCESS;
}
int slurm_spank_slurmd_exit(spank_t spank, int ac, char *argv[])
{
trace_spank_call(spank, "slurmd_exit");
return ESPANK_SUCCESS;
}
int slurm_spank_exit(spank_t spank, int ac, char *argv[])
{
trace_spank_call(spank, "exit");
return ESPANK_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment