Last active
December 3, 2019 16:28
-
-
Save cinek810/9e893aa103f70fcb40ac1d71af9fc988 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gdb | |
#rewrite slurm_msg_type to array num->str | |
slurm_msg_type = gdb.lookup_type("slurm_msg_type_t") | |
rpc_num2str=dict() | |
for name,field in slurm_msg_type.items(): | |
rpc_num2str[field.enumval]=name | |
class sdiag(gdb.Command): | |
def __init__(self): | |
super(sdiag, self).__init__("sdiag", gdb.COMMAND_DATA) | |
def invoke(self, arg, from_tty): | |
self._print_rpc_stats() | |
def _print_rpc_stats(self): | |
self._print_rpc_by("type") | |
self._print_rpc_by("user") | |
def _print_rpc_by(self,by_what): | |
slurm_msg_type = gdb.lookup_type("slurm_msg_type_t") | |
print("RPC BY "+by_what); | |
for i in range(0,gdb.parse_and_eval("rpc_"+by_what+"_size")): | |
rpc_id = gdb.parse_and_eval("rpc_"+by_what+"_id["+str(i)+"]") | |
rpc_cnt = gdb.parse_and_eval("rpc_"+by_what+"_cnt["+str(i)+"]") | |
rpc_time = gdb.parse_and_eval("rpc_"+by_what+"_time["+str(i)+"]") | |
if rpc_cnt == 0: | |
break | |
if by_what == "type": | |
print("%s \t (%s) \t count: %d \t ave_time:%d \t time:%d" %(rpc_num2str[int(rpc_id)],rpc_id,rpc_cnt,rpc_time/rpc_cnt,rpc_time)) | |
else: | |
print("%s \t count: %d \t ave_time:%d \t time:%d" %(rpc_id,rpc_cnt,rpc_time/rpc_cnt,rpc_time)) | |
class squeue(gdb.Command): | |
def __init__(self): | |
super(squeue, self).__init__("squeue", gdb.COMMAND_DATA) | |
def invoke(self, arg, from_tty): | |
self._print_all_jobs() | |
def _print_all_jobs(self): | |
struct_job_record_p = gdb.lookup_type("struct job_record").pointer() | |
job_ptr = gdb.parse_and_eval("job_list->head") | |
job_count = gdb.parse_and_eval("job_list->count") | |
print("Job list has %d items" %(job_count)) | |
for i in range(0,job_count): | |
job_data = job_ptr["data"].cast(struct_job_record_p) | |
self._print_job(job_data) | |
job_ptr = job_ptr["next"] | |
def _print_job(self,job_rec): | |
print("%d|%s|%s|%s|%s|%s"%(job_rec["job_id"],job_rec["partition"],job_rec["user_name"],job_rec["name"],job_rec["nodes"],job_rec["state_desc"])) | |
# Register commands: | |
sdiag() | |
squeue() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment