📄 xpbs_datadump.c
字号:
l = strlen(e); if ( l > NUML ) { c = e + NUML; *c = '\0'; } strcpy(tot, e); } else if ( strcmp(a->name,ATTR_count) == 0 ) { states(e, que, run, hld, wat, trn, ext, NUML); } else if ( strcmp(a->name,ATTR_status) == 0 ) { l = strlen(e); if ( l > STATUSL ) { c = e + STATUSL; *c = '\0'; } strcpy(stats, e); } else if ( strcmp(a->name,ATTR_rescmax) == 0 ) { if( strcmp(a->resource, "nodect") == 0 || \ strcmp(a->resource, "ncpus") == 0 ) { l = strlen(e); if ( l > NODESL ) { c = e + NODESL; *c = '\0'; } sprintf(nod, "%d/%s", nodesInUse, e); } } } a = a->next; free(e); } printf(format, name, max, tot, que, run, hld, wat, trn, ext, stats, nod, p->name ? p->name: ""); } if ( full ) printf("\n"); p = p->next; } return;}static int getNumNodesInUse(connect)int connect;{ struct batch_status *j_status; struct batch_status *temp; struct attrl *attr; struct attropl *run_list = 0; int nodesInUse = 0; char *errmsg; int nodect; int cpuct; int nodes; set_attrop(&run_list, ATTR_state, (char *)NULL, "R", EQ); j_status = pbs_selstat(connect, run_list, NULL); if ( j_status == NULL ) { if ( pbs_errno != PBSE_NONE ) { errmsg = pbs_geterrmsg(connect); if ( errmsg != NULL ) { fprintf(stderr, "xpbs_datadump: %s\n", errmsg); } else { fprintf(stderr, "xpbs_datadump: Error (%d) selecting running jobs to obtain nodes in use value\n", pbs_errno); } return(-1); } } else { /* got some output */ for(temp=j_status; temp; temp=temp->next) { nodect = 0; /* start with a nodect of 0 */ cpuct = 0; /* start with a cpuct of 0 */ nodes = 0; /* nodes is not set */ for(attr=temp->attribs; attr; attr=attr->next) { if ( strcmp(attr->name,ATTR_l) == 0 ) { if ( strcmp(attr->resource, "nodect") == 0 ) { nodect = atoi(attr->value); } else if ( strcmp(attr->resource, "nodes") == 0 ){ nodes = 1; /* nodes is set */ } else if ( strcmp(attr->resource, "ncpus") == 0 ) { cpuct = atoi(attr->value); } } } if( nodes ) { nodesInUse += nodect; } else { nodesInUse += cpuct; } } pbs_statfree(j_status); } return(nodesInUse);}main(argc, argv) /* qstat */int argc;char **argv;{ int c; int errflg=0; int any_failed=0; char server_out[MAXSERVERNAME]; char full_server_name[MAXSERVERNAME]; char *queue_name_out = NULL; struct batch_status *p_status; char *errmsg;#define MAX_OPTARG_LEN 256#define MAX_RESOURCE_NAME_LEN 256 char optargout[MAX_OPTARG_LEN+1]; char resource_name[MAX_RESOURCE_NAME_LEN+1]; enum batch_op op; enum batch_op *pop = &op; struct attropl *select_list = 0; static char destination[PBS_MAXQUEUENAME+1] = ""; char *server_name_out; char *res_pos; char *pc; int u_cnt, o_cnt, s_cnt, n_cnt; time_t after; char a_value[80]; int do_job_only = FALSE; int do_trackjob_only = FALSE; int timeout_secs = 30; /* # of seconds before timing out waiting */ /* for a connection to the server */ struct sigaction act;#define GETOPT_ARGS "a:A:c:h:l:N:p:q:r:s:u:JTt:" while ((c = getopt(argc, argv, GETOPT_ARGS)) != EOF) switch (c) { case 't': timeout_secs = atoi(optarg); break; case 'T': do_trackjob_only = TRUE; break; case 'J': do_job_only = TRUE; break; case 'a': check_op(optarg, pop, optargout); if ( (after = cvtdate(optargout)) < 0 ) { fprintf(stderr, "xpbs_datadump: illegal -a value\n"); errflg++; break; } sprintf(a_value, "%d", after); set_attrop(&select_list, ATTR_a, (char *)NULL, a_value, op); break; case 'c': check_op(optarg, pop, optargout); pc = optargout; while ( isspace((int)*pc) ) pc++; if ( strlen(pc) == 0 ) { fprintf(stderr, "xpbs_datadump: illegal -c value\n"); errflg++; break; } if ( strcmp(pc, "u") == 0 ) { if ( (op != EQ) && (op != NE) ) { fprintf(stderr, "xpbs_datadump: illegal -c value\n"); errflg++; break; } } else if ( (strcmp(pc, "n") != 0) && (strcmp(pc, "s") != 0) && (strcmp(pc, "c") != 0) ) { if ( strncmp(pc, "c=", 2) != 0 ) { fprintf(stderr, "xpbs_datadump: illegal -c value\n"); errflg++; break; } pc += 2; if ( strlen(pc) == 0 ) { fprintf(stderr, "xpbs_datadump: illegal -c value\n"); errflg++; break; } while ( *pc != '\0' ) { if ( !isdigit((int)*pc) ) { fprintf(stderr, "xpbs_datadump: illegal -c value\n"); errflg++; break; } pc++; } } set_attrop(&select_list, ATTR_c, (char *)NULL, optargout, op); break; case 'h': check_op(optarg, pop, optargout); pc = optargout; while ( isspace((int)*pc) ) pc++; if ( strlen(pc) == 0 ) { fprintf(stderr, "xpbs_datadump: illegal -h value\n"); errflg++; break; } u_cnt = o_cnt = s_cnt = n_cnt = 0; while ( *pc) { if ( *pc == 'u' ) u_cnt++; else if ( *pc == 'o' ) o_cnt++; else if ( *pc == 's' ) s_cnt++; else if ( *pc == 'n' ) n_cnt++; else { fprintf(stderr, "xpbs_datadump: illegal -h value\n"); errflg++; break; } pc++; } if ( n_cnt && (u_cnt + o_cnt + s_cnt) ) { fprintf(stderr, "xpbs_datadump: illegal -h value\n"); errflg++; break; } set_attrop(&select_list, ATTR_h, (char *)NULL, optargout, op); break; case 'l': res_pos = optarg; while ( *res_pos != '\0' ) { if (check_res_op(res_pos, resource_name, pop, optargout, &res_pos) != 0) { errflg++; break; } set_attrop(&select_list, ATTR_l, resource_name, optargout, op); } break; case 'p': check_op(optarg, pop, optargout); set_attrop(&select_list, ATTR_p, (char *)NULL, optargout, op); break; case 'q': strcpy(destination, optarg); check_op(optarg, pop, optargout); set_attrop(&select_list, ATTR_q, (char *)NULL, optargout, op); break; case 'r': op = EQ; pc = optarg; while ( isspace((int)(*pc)) ) pc++; if ( strlen(pc) != 1 ) { fprintf(stderr, "xpbs_datadump: illegal -r value\n"); errflg++; break; } if ( *pc != 'y' && *pc != 'n' ) { fprintf(stderr, "xpbs_datadump: illegal -r value\n"); errflg++; break; } set_attrop(&select_list, ATTR_r, (char *)NULL, pc, op); break; case 's': check_op(optarg, pop, optargout); pc = optargout; while ( isspace((int)(*pc)) ) pc++; if ( strlen(optarg) == 0 ) { fprintf(stderr, "xpbs_datadump: illegal -s value\n"); errflg++; break; } while ( *pc ) { if ( *pc != 'E' && *pc != 'H' && *pc != 'Q' && *pc != 'R' && *pc != 'T' && *pc != 'W' ) { fprintf(stderr, "xpbs_datadump: illegal -s value\n"); errflg++; break; } pc++; } set_attrop(&select_list, ATTR_state, (char *)NULL, optargout, op); break; case 'u': op = EQ; if ( parse_at_list(optarg, FALSE, FALSE) ) { fprintf(stderr, "xpbs_datadump: illegal -u value\n"); errflg++; break; } set_attrop(&select_list, ATTR_u, (char *)NULL, optarg, op); break; case 'A': op = EQ; set_attrop(&select_list, ATTR_A, (char *)NULL, optarg, op); break; case 'N': op = EQ; set_attrop(&select_list, ATTR_N, (char *)NULL, optarg, op); break; default : errflg++; } if (errflg || (optind == argc)) { static char usage[]="usage: xpbs_datadump \[-a [op]date_time] [-A account_string] [-c [op]interval] \n\[-h hold_list] [-l resource_list] [-N name] [-p [op]priority] \n\[-q destination] [-r y|n] [-s states] [-u user_name] [-J] [-T] \n\[-t timeout_secs] server_name..\n"; fprintf(stderr, usage); exit (2); } if ( notNULL(destination) ) { if (parse_destination_id(destination,&queue_name_out,&server_name_out)) { fprintf(stderr, "xpbs_datadump: illegally formed destination: %s\n", destination); exit(2); } else { if ( notNULL(server_name_out) ) { strcpy(server_out, server_name_out); } } } act.sa_handler = no_hang; sigemptyset(&act.sa_mask);#ifdef SA_INTERRUPT act.sa_flags = SA_INTERRUPT;#else act.sa_flags = 0;#endif /* SA_INTERRUPT */ (void)sigaction(SIGALRM, &act, (struct sigaction *)0); for ( ; optind < argc; optind++) { strcpy(server_out, argv[optind]); if (sigsetjmp(env_alrm, 1) == 0) { alarm(timeout_secs); connect = cnt2server(server_out); } alarm(0); if ( connect <= 0 ) { fprintf(stderr, "xpbs_datadump: Can not connect to server %s (%d)\n", server_out, pbs_errno); any_failed = connect; continue; }/* Get server information */ p_status = pbs_statserver(connect, NULL, NULL); if ( p_status == NULL ) { if ( pbs_errno ) { errmsg = pbs_geterrmsg(connect); if ( errmsg != NULL ) { fprintf(stderr, "qstat: %s ", errmsg); } else fprintf(stderr, "xpbs_datadump: Error (%d) getting status of server ", pbs_errno); fprintf(stderr, "%s\n", server_out); any_failed = pbs_errno; } } else { strcpy(full_server_name, p_status->name); if (!do_job_only && !do_trackjob_only) { display_statserver(p_status, TRUE, FALSE, getNumNodesInUse(connect)); } pbs_statfree(p_status); }/* Get the queue information */ p_status = pbs_statque(connect, queue_name_out, NULL, NULL); if ( p_status == NULL ) { if ( pbs_errno ) { errmsg = pbs_geterrmsg(connect); if ( errmsg != NULL ) { fprintf(stderr, "qstat: %s ", errmsg); } else fprintf(stderr, "xpbs_datadump: Error (%d) getting status of queue ", pbs_errno); fprintf(stderr, "%s\n", queue_name_out); any_failed = pbs_errno; } } else { if (!do_job_only && !do_trackjob_only) { display_statque(p_status, TRUE, FALSE, full_server_name); } pbs_statfree(p_status); }/*### Get Jobs summary info information for each of the servers*/ p_status = pbs_selstat(connect, select_list, NULL); if ( p_status == NULL ) { if ( pbs_errno != PBSE_NONE ) { errmsg = pbs_geterrmsg(connect); if ( errmsg != NULL ) { fprintf(stderr, "xpbs_datadump: %s\n", errmsg); } else { fprintf(stderr, "xpbs_datadump: Error (%d) selecting jobs\n", pbs_errno); } any_failed = pbs_errno; } } else { /* got some output */ if (!do_trackjob_only) { display_statjob(p_status, TRUE, FALSE, full_server_name); } else { display_trackstatjob(p_status, full_server_name); } pbs_statfree(p_status); } pbs_disconnect(connect); } exit(any_failed); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -