define starpu-print-job
  set language c
  set $job = (struct starpu_job_s *)$arg0

  printf "StarPU Job (%p)\n", $job
  printf "\ttask:\t\t\t\t<%p>\n", $job->task
  printf "\tsubmitted:\t\t\t<%d>\n", $job->submitted
  printf "\tterminated:\t\t\t<%d>\n", $job->terminated
  printf "\tjob_id:\t\t\t\t<%d>\n", $job->job_id
  printf "\tmodel_name:\t\t\t<%s>\n", $job->model_name
end

document starpu-print-job
Prints a StarPU job
end

define starpu-print-task
  set language c
  set $task = (struct starpu_task *)$arg0
  set $job = (struct starpu_job_s *)$task->starpu_private
  if $task->status == 0
    set $status="STARPU_TASK_INVALID"
  end
  if $task->status == 1
    set $status="STARPU_TASK_BLOCKED"
  end
  if $task->status == 2
    set $status="STARPU_TASK_READY"
  end
  if $task->status == 3
    set $status="STARPU_TASK_RUNNING"
  end
  if $task->status == 4
    set $status="STARPU_TASK_FINISHED"
  end
  if $task->status == 5
    set $status="STARPU_TASK_BLOCKED_ON_TAG"
  end
  if $task->status == 6
    set $status="STARPU_TASK_BLOCKED_ON_TASK"
  end
  if $task->status == 7
    set $status="STARPU_TASK_BLOCKED_ON_JOB"
  end

  printf "StarPU Task (%p)\n", $task
  printf "\tcodelet:\t\t\t<%p>\n", $task->cl
  printf "\tcallback:\t\t\t<%p>\n", $task->callback_func
  printf "\tsynchronous:\t\t\t<%d>\n", $task->synchronous
  printf "\texecute_on_a_specific_worker:\t<%d>\n", $task->execute_on_a_specific_worker
  printf "\tworkerid:\t\t\t<%d>\n", $task->workerid
  printf "\tdetach:\t\t\t\t<%d>\n", $task->detach
  printf "\tdestroy:\t\t\t<%d>\n", $task->destroy
  printf "\tregenerate:\t\t\t<%d>\n", $task->regenerate
  printf "\tstatus:\t\t\t\t<%s>\n", $status
  printf "\tjob:\t\t\t\t<%p>\n", $job
end

document starpu-print-task
Prints a StarPU task
end

define starpu-jobs-on-worker
  set language c
  set $worker=config->workers[$arg0]
  set $job=$worker->local_jobs->_head
  printf "Jobs\n"
  printf "Submitted Terminated\n"
  while $job != 0x0
    printf "%9d %10d\n", $job->submitted, $job->terminated
    set $job=$job->_next
  end
end

document starpu-jobs-on-worker
Prints a list of the jobs running on the given worker
end

define starpu-workers
  set language c
  set $num=0
  printf "[Id] Arch Mask Devid Bindid Workerid Isrunning Isinitialized\n"
  while $num<config->topology->nworkers
    set $worker=config->workers[$num]
    printf "[%d] %4d %4d %5d %6d %8d %9d %13d\n", $num, $worker->arch, $worker->worker_mask, \
          $worker->devid, $worker->bindid, $worker->workerid, $worker->worker_is_running, $worker->worker_is_initialized
    set $num = $num + 1
  end
end

document starpu-workers
Prints a list of the StarPU workers
end

define starpu
  printf "Here I am...\n"
end

document starpu
List of StarPU-specific gdb functions:
starpu-workers		prints a list of the StarPU workers
starpu-jobs-on-worker   prints a list of the jobs running on the given worker
starpu-print-job        prints a StarPU job
starpu-print-task       prints a StarPU task
end
