static int _sort_step_by_user_name(void *void1, void *void2) { int diff; job_step_info_t *step1; job_step_info_t *step2; char *name1, *name2; _get_step_info_from_void(&step1, &step2, void1, void2); name1 = uid_to_string_cached((uid_t) step1->user_id); name2 = uid_to_string_cached((uid_t) step2->user_id); diff = strcmp(name1, name2); if (reverse_order) diff = -diff; return diff; }
static int _sort_job_by_user_name(void *void1, void *void2) { int diff; job_info_t *job1; job_info_t *job2; char *name1, *name2; _get_job_info_from_void(&job1, &job2, void1, void2); name1 = uid_to_string_cached((uid_t) job1->user_id); name2 = uid_to_string_cached((uid_t) job2->user_id); diff = xstrcmp(name1, name2); if (reverse_order) diff = -diff; return diff; }
int _print_job_user_name(priority_factors_object_t * job, int width, bool right, char* suffix) { if (job == NULL) /* Print the Header instead */ _print_str("USER", width, right, true); else if (job == (priority_factors_object_t *) -1) _print_str("", width, right, true); else { char *uname = uid_to_string_cached((uid_t) job->user_id); _print_str(uname, width, right, true); } if (suffix) printf("%s", suffix); return SLURM_SUCCESS; }
extern int sacctmgr_dump_cluster (int argc, char **argv) { slurmdb_user_cond_t user_cond; slurmdb_user_rec_t *user = NULL; slurmdb_hierarchical_rec_t *slurmdb_hierarchical_rec = NULL; slurmdb_assoc_rec_t *assoc = NULL; slurmdb_assoc_cond_t assoc_cond; List assoc_list = NULL; List acct_list = NULL; List user_list = NULL; List slurmdb_hierarchical_rec_list = NULL; char *cluster_name = NULL; char *file_name = NULL; char *user_name = NULL; char *line = NULL; int i, command_len = 0; FILE *fd = NULL; char *class_str = NULL; for (i = 0; i < argc; i++) { int end = parse_option_end(argv[i]); if (!end) command_len = strlen(argv[i]); else { command_len = end - 1; if (argv[i][end] == '=') { end++; } } if (!end || !strncasecmp(argv[i], "Cluster", MAX(command_len, 1))) { if (cluster_name) { exit_code = 1; fprintf(stderr, " Can only do one cluster at a time. " "Already doing %s\n", cluster_name); continue; } cluster_name = xstrdup(argv[i]+end); } else if (!strncasecmp(argv[i], "File", MAX(command_len, 1))) { if (file_name) { exit_code = 1; fprintf(stderr, " File name already set to %s\n", file_name); continue; } file_name = xstrdup(argv[i]+end); } else { exit_code = 1; fprintf(stderr, " Unknown option: %s\n", argv[i]); } } if (!cluster_name) { exit_code = 1; fprintf(stderr, " We need a cluster to dump.\n"); xfree(file_name); return SLURM_ERROR; } else { List temp_list = NULL; slurmdb_cluster_cond_t cluster_cond; slurmdb_cluster_rec_t *cluster_rec = NULL; slurmdb_init_cluster_cond(&cluster_cond, 0); cluster_cond.cluster_list = list_create(NULL); list_push(cluster_cond.cluster_list, cluster_name); temp_list = acct_storage_g_get_clusters(db_conn, my_uid, &cluster_cond); FREE_NULL_LIST(cluster_cond.cluster_list); if (!temp_list) { exit_code = 1; fprintf(stderr, " Problem getting clusters from database. " "Contact your admin.\n"); xfree(cluster_name); xfree(file_name); return SLURM_ERROR; } cluster_rec = list_peek(temp_list); if (!cluster_rec) { exit_code = 1; fprintf(stderr, " Cluster %s doesn't exist.\n", cluster_name); xfree(cluster_name); xfree(file_name); FREE_NULL_LIST(temp_list); return SLURM_ERROR; } class_str = get_classification_str(cluster_rec->classification); FREE_NULL_LIST(temp_list); } if (!file_name) { file_name = xstrdup_printf("./%s.cfg", cluster_name); printf(" No filename given, using %s.\n", file_name); } memset(&user_cond, 0, sizeof(slurmdb_user_cond_t)); user_cond.with_coords = 1; user_cond.with_wckeys = 1; user_cond.with_assocs = 1; memset(&assoc_cond, 0, sizeof(slurmdb_assoc_cond_t)); assoc_cond.without_parent_limits = 1; assoc_cond.with_raw_qos = 1; assoc_cond.cluster_list = list_create(NULL); list_append(assoc_cond.cluster_list, cluster_name); /* this is needed for getting the correct wckeys */ user_cond.assoc_cond = &assoc_cond; user_list = acct_storage_g_get_users(db_conn, my_uid, &user_cond); /* If not running with the DBD assoc_cond.user_list can be set, * which will mess other things up. */ if (assoc_cond.user_list) { FREE_NULL_LIST(assoc_cond.user_list); assoc_cond.user_list = NULL; } /* make sure this person running is an admin */ user_name = uid_to_string_cached(my_uid); if (!(user = sacctmgr_find_user_from_list(user_list, user_name))) { exit_code = 1; fprintf(stderr, " Your uid (%u) is not in the " "accounting system, can't dump cluster.\n", my_uid); FREE_NULL_LIST(assoc_cond.cluster_list); xfree(cluster_name); xfree(file_name); FREE_NULL_LIST(user_list); return SLURM_ERROR; } else { if (my_uid != slurm_get_slurm_user_id() && my_uid != 0 && user->admin_level < SLURMDB_ADMIN_SUPER_USER) { exit_code = 1; fprintf(stderr, " Your user does not have sufficient " "privileges to dump clusters.\n"); FREE_NULL_LIST(assoc_cond.cluster_list); xfree(cluster_name); xfree(file_name); FREE_NULL_LIST(user_list); return SLURM_ERROR; } } xfree(user_name); /* assoc_cond is set up above */ assoc_list = acct_storage_g_get_assocs(db_conn, my_uid, &assoc_cond); FREE_NULL_LIST(assoc_cond.cluster_list); if (!assoc_list) { exit_code = 1; fprintf(stderr, " Problem with query.\n"); xfree(cluster_name); xfree(file_name); return SLURM_ERROR; } else if (!list_count(assoc_list)) { exit_code = 1; fprintf(stderr, " Cluster %s returned nothing.\n", cluster_name); FREE_NULL_LIST(assoc_list); xfree(cluster_name); xfree(file_name); return SLURM_ERROR; } slurmdb_hierarchical_rec_list = slurmdb_get_acct_hierarchical_rec_list( assoc_list); acct_list = acct_storage_g_get_accounts(db_conn, my_uid, NULL); if ((fd = fopen(file_name,"w")) == NULL) { fprintf(stderr, "Can't open file %s, %s\n", file_name, slurm_strerror(errno)); FREE_NULL_LIST(acct_list); FREE_NULL_LIST(assoc_list); xfree(cluster_name); xfree(file_name); FREE_NULL_LIST(slurmdb_hierarchical_rec_list); return SLURM_ERROR; } /* Add header */ if (fprintf(fd, "# To edit this file start with a cluster line " "for the new cluster\n" "# Cluster - 'cluster_name':MaxNodesPerJob=50\n" "# Followed by Accounts you want in this fashion " "(root is created by default)...\n" "# Parent - 'root'\n" "# Account - 'cs':MaxNodesPerJob=5:MaxJobs=4:" "MaxTRESMins=cpu=20:FairShare=399:" "MaxWallDuration=40:Description='Computer Science':" "Organization='LC'\n" "# Any of the options after a ':' can be left out and " "they can be in any order.\n" "# If you want to add any sub accounts just list the " "Parent THAT HAS ALREADY \n" "# BEEN CREATED before the account line in this " "fashion...\n" "# Parent - 'cs'\n" "# Account - 'test':MaxNodesPerJob=1:MaxJobs=1:" "MaxTRESMins=cpu=1:FairShare=1:" "MaxWallDuration=1:" "Description='Test Account':Organization='Test'\n" "# To add users to a account add a line like this after a " "Parent - 'line'\n" "# User - 'lipari':MaxNodesPerJob=2:MaxJobs=3:" "MaxTRESMins=cpu=4:FairShare=1:" "MaxWallDurationPerJob=1\n") < 0) { exit_code = 1; fprintf(stderr, "Can't write to file"); FREE_NULL_LIST(acct_list); FREE_NULL_LIST(assoc_list); xfree(cluster_name); xfree(file_name); FREE_NULL_LIST(slurmdb_hierarchical_rec_list); return SLURM_ERROR; } line = xstrdup_printf("Cluster - '%s'", cluster_name); if (class_str) xstrfmtcat(line, ":Classification='%s'", class_str); slurmdb_hierarchical_rec = list_peek(slurmdb_hierarchical_rec_list); assoc = slurmdb_hierarchical_rec->assoc; if (xstrcmp(assoc->acct, "root")) { fprintf(stderr, "Root association not on the top it was %s\n", assoc->acct); } else print_file_add_limits_to_line(&line, assoc); if (fprintf(fd, "%s\n", line) < 0) { exit_code = 1; fprintf(stderr, " Can't write to file"); FREE_NULL_LIST(acct_list); FREE_NULL_LIST(assoc_list); xfree(cluster_name); xfree(file_name); xfree(line); FREE_NULL_LIST(slurmdb_hierarchical_rec_list); return SLURM_ERROR; } info("%s", line); xfree(line); print_file_slurmdb_hierarchical_rec_list( fd, slurmdb_hierarchical_rec_list, user_list, acct_list); FREE_NULL_LIST(acct_list); FREE_NULL_LIST(assoc_list); xfree(cluster_name); xfree(file_name); FREE_NULL_LIST(slurmdb_hierarchical_rec_list); fclose(fd); return SLURM_SUCCESS; }
static int _print_stats(void) { int i; if (!buf) { printf("No data available. Probably slurmctld is not working\n"); return -1; } printf("*******************************************************\n"); printf("sdiag output at %s", slurm_ctime(&buf->req_time)); printf("Data since %s", slurm_ctime(&buf->req_time_start)); printf("*******************************************************\n"); printf("Server thread count: %d\n", buf->server_thread_count); printf("Agent queue size: %d\n\n", buf->agent_queue_size); printf("Jobs submitted: %d\n", buf->jobs_submitted); printf("Jobs started: %d\n", buf->jobs_started); printf("Jobs completed: %d\n", buf->jobs_completed); printf("Jobs canceled: %d\n", buf->jobs_canceled); printf("Jobs failed: %d\n", buf->jobs_failed); printf("\nMain schedule statistics (microseconds):\n"); printf("\tLast cycle: %u\n", buf->schedule_cycle_last); printf("\tMax cycle: %u\n", buf->schedule_cycle_max); printf("\tTotal cycles: %u\n", buf->schedule_cycle_counter); if (buf->schedule_cycle_counter > 0) { printf("\tMean cycle: %u\n", buf->schedule_cycle_sum / buf->schedule_cycle_counter); printf("\tMean depth cycle: %u\n", buf->schedule_cycle_depth / buf->schedule_cycle_counter); } if ((buf->req_time - buf->req_time_start) > 60) { printf("\tCycles per minute: %u\n", (uint32_t) (buf->schedule_cycle_counter / ((buf->req_time - buf->req_time_start) / 60))); } printf("\tLast queue length: %u\n", buf->schedule_queue_len); if (buf->bf_active) { printf("\nBackfilling stats (WARNING: data obtained" " in the middle of backfilling execution.)\n"); } else printf("\nBackfilling stats\n"); printf("\tTotal backfilled jobs (since last slurm start): %u\n", buf->bf_backfilled_jobs); printf("\tTotal backfilled jobs (since last stats cycle start): %u\n", buf->bf_last_backfilled_jobs); printf("\tTotal cycles: %u\n", buf->bf_cycle_counter); printf("\tLast cycle when: %s", slurm_ctime(&buf->bf_when_last_cycle)); printf("\tLast cycle: %u\n", buf->bf_cycle_last); printf("\tMax cycle: %u\n", buf->bf_cycle_max); if (buf->bf_cycle_counter > 0) { printf("\tMean cycle: %"PRIu64"\n", buf->bf_cycle_sum / buf->bf_cycle_counter); } printf("\tLast depth cycle: %u\n", buf->bf_last_depth); printf("\tLast depth cycle (try sched): %u\n", buf->bf_last_depth_try); if (buf->bf_cycle_counter > 0) { printf("\tDepth Mean: %u\n", buf->bf_depth_sum / buf->bf_cycle_counter); printf("\tDepth Mean (try depth): %u\n", buf->bf_depth_try_sum / buf->bf_cycle_counter); } printf("\tLast queue length: %u\n", buf->bf_queue_len); if (buf->bf_cycle_counter > 0) { printf("\tQueue length mean: %u\n", buf->bf_queue_len_sum / buf->bf_cycle_counter); } printf("\nRemote Procedure Call statistics by message type\n"); for (i = 0; i < buf->rpc_type_size; i++) { printf("\t%-40s(%5u) count:%-6u " "ave_time:%-6u total_time:%"PRIu64"\n", rpc_num2string(buf->rpc_type_id[i]), buf->rpc_type_id[i], buf->rpc_type_cnt[i], rpc_type_ave_time[i], buf->rpc_type_time[i]); } printf("\nRemote Procedure Call statistics by user\n"); for (i = 0; i < buf->rpc_user_size; i++) { printf("\t%-16s(%8u) count:%-6u " "ave_time:%-6u total_time:%"PRIu64"\n", uid_to_string_cached((uid_t)buf->rpc_user_id[i]), buf->rpc_user_id[i], buf->rpc_user_cnt[i], rpc_user_ave_time[i], buf->rpc_user_time[i]); } return 0; }
static int _print_text_job(job_info_t * job_ptr) { time_t time_diff; int printed = 0; int tempxcord; int prefixlen = 0; int i = 0; int width = 0; char time_buf[20]; char tmp_cnt[8]; uint32_t node_cnt = 0; char *uname; node_cnt = job_ptr->num_nodes; if ((node_cnt == 0) || (node_cnt == NO_VAL)) node_cnt = job_ptr->num_nodes; snprintf(tmp_cnt, sizeof(tmp_cnt), "%d", node_cnt); if (!params.commandline) { mvwprintw(text_win, main_ycord, main_xcord, "%c", job_ptr->num_cpus); main_xcord += 3; if (job_ptr->array_task_str) { mvwprintw(text_win, main_ycord, main_xcord, "%u_[%s]", job_ptr->array_job_id, job_ptr->array_task_str); } else if (job_ptr->array_task_id != NO_VAL) { mvwprintw(text_win, main_ycord, main_xcord, "%u_%u (%u)", job_ptr->array_job_id, job_ptr->array_task_id, job_ptr->job_id); } else if (job_ptr->pack_job_id) { mvwprintw(text_win, main_ycord, main_xcord, "%u+%u ", job_ptr->pack_job_id, job_ptr->pack_job_offset); } else { mvwprintw(text_win, main_ycord, main_xcord, "%u", job_ptr->job_id); } main_xcord += 19; mvwprintw(text_win, main_ycord, main_xcord, "%.10s", job_ptr->partition); main_xcord += 10; if (params.cluster_flags & CLUSTER_FLAG_CRAY_A) { mvwprintw(text_win, main_ycord, main_xcord, "%.16s", select_g_select_jobinfo_sprint( job_ptr->select_jobinfo, time_buf, sizeof(time_buf), SELECT_PRINT_DATA)); main_xcord += 18; } uname = uid_to_string_cached((uid_t) job_ptr->user_id); mvwprintw(text_win, main_ycord, main_xcord, "%.8s", uname); main_xcord += 9; mvwprintw(text_win, main_ycord, main_xcord, "%.9s", job_ptr->name); main_xcord += 10; mvwprintw(text_win, main_ycord, main_xcord, "%.2s", job_state_string_compact(job_ptr->job_state)); main_xcord += 2; if (!xstrcasecmp(job_ptr->nodes,"waiting...")) { sprintf(time_buf,"00:00:00"); } else { time_diff = (time_t) _job_time_used(job_ptr); secs2time_str(time_diff, time_buf, sizeof(time_buf)); } width = strlen(time_buf); mvwprintw(text_win, main_ycord, main_xcord + (10 - width), "%s", time_buf); main_xcord += 11; mvwprintw(text_win, main_ycord, main_xcord, "%5s", tmp_cnt); main_xcord += 6; tempxcord = main_xcord; i=0; while (job_ptr->nodes[i] != '\0') { if ((printed = mvwaddch(text_win, main_ycord, main_xcord, job_ptr->nodes[i])) < 0) { return printed; } main_xcord++; width = getmaxx(text_win) - 1 - main_xcord; if (job_ptr->nodes[i] == '[') prefixlen = i + 1; else if (job_ptr->nodes[i] == ',' && (width - 9) <= 0) { main_ycord++; main_xcord = tempxcord + prefixlen; } i++; } main_xcord = 1; main_ycord++; } else { if (job_ptr->pack_job_id) { printf("%8u+%u ", job_ptr->pack_job_id, job_ptr->pack_job_offset); } else printf("%8u ", job_ptr->job_id); printf("%9.9s ", job_ptr->partition); if (params.cluster_flags & CLUSTER_FLAG_CRAY_A) printf("%16.16s ", select_g_select_jobinfo_sprint( job_ptr->select_jobinfo, time_buf, sizeof(time_buf), SELECT_PRINT_DATA)); uname = uid_to_string_cached((uid_t) job_ptr->user_id); printf("%8.8s ", uname); printf("%6.6s ", job_ptr->name); printf("%2.2s ", job_state_string_compact(job_ptr->job_state)); if (!xstrcasecmp(job_ptr->nodes,"waiting...")) { sprintf(time_buf,"00:00:00"); } else { time_diff = (time_t) _job_time_used(job_ptr); secs2time_str(time_diff, time_buf, sizeof(time_buf)); } printf("%10.10s ", time_buf); printf("%5s ", tmp_cnt); printf("%s", job_ptr->nodes); printf("\n"); } return printed; }