File: showq.c

package info (click to toggle)
gridengine 8.1.9%2Bdfsg-4%2Bdeb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 56,460 kB
  • sloc: ansic: 432,641; java: 87,068; cpp: 31,958; sh: 29,419; jsp: 7,757; perl: 6,336; xml: 5,825; makefile: 4,703; csh: 3,934; ruby: 2,221; tcl: 1,676; lisp: 669; yacc: 519; python: 503; lex: 361
file content (338 lines) | stat: -rw-r--r-- 11,921 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/* ___INFO__MARK_BEGIN__ */
/*************************************************************************
 *
 *  The Contents of this file are made available subject to the terms of
 *  the Sun Industry Standards Source License Version 1.2
 *
 *  Sun Microsystems Inc., March, 2001
 *
 *
 *  Sun Industry Standards Source License Version 1.2
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.2 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *   Copyright: 2009 by Texas Advanced Computing Center
 *
 *   All Rights Reserved.
 *
 ************************************************************************/
/* ___INFO__MARK_END__ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fnmatch.h>
#include <ctype.h>
#include <math.h>

#include "uti/sge_rmon.h"
#include "uti/sge_dstring.h"
#include "uti/sge_log.h"

#include "sgeobj/sge_host.h"
#include "sgeobj/sge_str.h"
#include "sgeobj/sge_job.h"
#include "sgeobj/parse.h"
#include "sgeobj/sge_answer.h"

#include "sched/sge_sched.h"

#include "gdi/sge_gdi.h"

#include "comm/commlib.h"

#include "sge.h"
#include "sig_handlers.h"
#include "showq_cmdline_tacc.h"
#include "showq_support.h"
#include "msg_common.h"

static bool sge_parse_showq_tacc(lList **alpp, lList ** ppcmdline,
                                 lList ** user_list, const char *username,
                                 int *full, bool *binding, lList **, lList **);

static int showq_show_job_tacc(sge_gdi_ctx_class_t * ctx, lList * jid, int full, 
                                 const bool binding, lList *, lList *);

/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
int main(int argc, char **argv)
{
   lList          *alp = NULL;
   lList          *pcmdline = NULL;
   lList          *user_list = NULL;
   lList          *sfa_list = NULL;
   lList          *sfw_list = NULL;
   lList          *ref_list = NULL;
   sge_gdi_ctx_class_t *ctx = NULL;
   int             full = 0;
   bool            binding = false;
   int             ret = 0;

   DENTER_MAIN(TOP_LAYER, "showq");

   /* Set up the program information name */
   sge_setup_sig_handlers(QSTAT);

   log_state_set_log_gui(1);

   if (sge_gdi2_setup(&ctx, QSTAT, MAIN_THREAD, &alp) != AE_OK) {
      answer_list_output(&alp);
      SGE_EXIT((void **) &ctx, 1);
   }

   switch_list_showq_parse_from_cmdline_tacc(&pcmdline, &alp, argv+1);
   if (alp) {
      answer_list_output(&alp); 
      lFreeList(&pcmdline);
      SGE_EXIT((void **) &ctx, 1);
   }

   if (!sge_parse_showq_tacc(&alp, &pcmdline, &user_list, ctx->get_username(ctx), 
                             &full, &binding, &sfa_list, &sfw_list)) {
      answer_list_output(&alp); 
      lFreeList(&pcmdline);
      lFreeList(&ref_list);
      lFreeList(&user_list);
      SGE_EXIT((void **) &ctx, 1);
   }
   ret = showq_show_job_tacc(ctx, user_list, full, binding, sfa_list, sfw_list);

   SGE_EXIT((void **) &ctx, ret);
   DRETURN(ret);
}


/****
 **** sge_parse_qstat (static)
 ****
 **** 'stage 2' parsing of qstat-options. Gets the options from
 **** ppcmdline, sets the full and empry_qs flags and puts the
 **** queue/res/user-arguments into the lists.
 ****/
static bool sge_parse_showq_tacc(lList **alpp, lList **ppcmdline, lList **user_list,
                  const char *username, int *full, bool *binding, lList **sfa_list,
                  lList **sfw_list)
{
   bool ret = true;
   bool usageshowed = false;
   u_long32 helpflag;
   u_long32 full_sge = 0;
   u_long32 add_me = 0;
   u_long32 bnd = 0;

   DENTER(TOP_LAYER, "sge_parse_showq_tacc");

   /*
    * Loop over all options. Only valid options can be in the ppcmdline list.
    */
   while (lGetNumberOfElem(*ppcmdline)) {
      if (parse_flag(ppcmdline, "--help", alpp, &helpflag)) {
         usageshowed = showq_usage(stdout);
         ret = false;
         break;
      }
      while (parse_flag(ppcmdline, "-l", alpp, &full_sge)) {
         if (full_sge) {
            *full = 1;
         }
         continue;
      }

      while (parse_flag(ppcmdline, "-cb", alpp, &bnd)) {
         if (bnd) {
            *binding = true;
         }
         continue;
      }

      while (parse_flag(ppcmdline, "-u", alpp, &add_me)) {
         if (add_me) {
            /* add my user name to the user list */
            lAddElemStr(user_list, ST_name, username, ST_Type);
            add_me = 0;
         }
         continue;
      }


      while (parse_multi_stringlist(ppcmdline, "-U", alpp, user_list, ST_Type, ST_name)) {
         continue;
      }

      while (parse_multi_stringlist(ppcmdline, "-sfa", alpp, sfa_list, ST_Type, ST_name)) {
         continue;
      }

      while (parse_multi_stringlist(ppcmdline, "-sfw", alpp, sfw_list, ST_Type, ST_name)) {
         continue;
      }
   }

   if (lGetNumberOfElem(*ppcmdline) && !usageshowed) {
      showq_usage(stderr);
      answer_list_add_sprintf(alpp, STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR, MSG_PARSE_TOOMANYOPTIONS);
      ret = false;
   }
   DRETURN(ret);
}


/*
 * * showq_show_job * displays information about a given job * to be extended *
 * 
 * returns 0 on success, non-zero on failure
 */
static int showq_show_job_tacc(sge_gdi_ctx_class_t * ctx, lList * user_list, int full, const bool binding,
                               lList * sfa_list, lList * sfw_list)
{
   lListElem      *j_elem = 0;
   lList          *jlp = NULL;
   lList          *ilp = NULL;
   lCondition     *where = NULL, *newcp = NULL;
   lEnumeration   *what = NULL;
   lList          *alp = NULL;
   int            total_slot_count;
   int            active_slot_count;
   int            active_job_count;
   int            total_job_count;
   int            unsched_job_count;
   int            dep_waiting_job_count;
   int            waiting_job_count;
   lList          *active_dj_list = NULL;
   lList          *waiting_dj_list = NULL;
   lList          *dep_waiting_dj_list = NULL;
   lList          *unsched_dj_list = NULL;

   DENTER(TOP_LAYER, "qstat_show_job_tacc");

   /* if the user_list is empty, display all users' jobs */
   if (lGetNumberOfElem(user_list) != 0) {
      for_each(j_elem, user_list) {
         newcp = lWhere("%T(%I p= %s)", JB_Type, JB_owner, lGetString(j_elem, ST_name));
         if (newcp != NULL) {
            if (where == NULL) {
               where = newcp;
            } else {
               where = lOrWhere(where, newcp);
            } 
         }
      }
   }

   /* get job data */
   what = lWhat("%T(ALL)", JB_Type);
   alp = ctx->gdi(ctx, SGE_JB_LIST, SGE_GDI_GET, &jlp, where, what, false);
   if (alp != NULL) {
      answer_list_output(&alp);
   }
   lFreeWhere(&where);
   lFreeWhat(&what);

   extract_dj_lists(jlp, &active_dj_list, &waiting_dj_list, &dep_waiting_dj_list, &unsched_dj_list);

   active_job_count = lGetNumberOfElem(active_dj_list);

   active_slot_count = sum_slots(active_dj_list);
   waiting_job_count = lGetNumberOfElem(waiting_dj_list);
   dep_waiting_job_count = lGetNumberOfElem(dep_waiting_dj_list);
   unsched_job_count = lGetNumberOfElem(unsched_dj_list);

   /* apply active job sort */
   sort_dj_list(active_dj_list, sfa_list, false);

   /* apply waiting job sort */
   sort_dj_list(waiting_dj_list, sfw_list, true);
   sort_dj_list(dep_waiting_dj_list, sfw_list, true);
   sort_dj_list(unsched_dj_list, sfw_list, true);


   printf("ACTIVE JOBS--------------------------\n");
   if (full) {
      if (binding == false) {
         printf("JOBID     JOBNAME    USERNAME      STATE   CORE  HOST  QUEUE        REMAINING  STARTTIME\n");
         printf("==================================================================================================\n");
      } else {
         printf("JOBID     JOBNAME    USERNAME      STATE   CORE  HOST  QUEUE        REMAINING  STARTTIME           CORE_BINDING\n");
         printf("===============================================================================================================\n");
      }
   } else {
      if (binding == false) {
         printf("JOBID     JOBNAME    USERNAME      STATE   CORE  REMAINING  STARTTIME\n");
         printf("================================================================================\n");
      } else {
         printf("JOBID     JOBNAME    USERNAME      STATE   CORE  REMAINING  STARTTIME           CORE_BINDING\n");
         printf("============================================================================================\n");
      }
   }

   /* print running jobs */
   show_active_jobs(active_dj_list, full, binding);

   printf("\n");
   total_slot_count = 82 * 4 * 12 * 16;
   printf("%6d active jobs : %4d of %4d hosts (%6.2f %%)\n", active_job_count, (int) ceil(active_slot_count / 16.0), (int) ceil(total_slot_count / 16.0),
          100 * active_slot_count / (float) total_slot_count);
   printf("\n");

   printf("WAITING JOBS------------------------\n");
   if (full) {
      printf("JOBID     JOBNAME    USERNAME      STATE   CORE  HOST  QUEUE        WCLIMIT    QUEUETIME\n");
      printf("==================================================================================================\n");
   } else {
      printf("JOBID     JOBNAME    USERNAME      STATE   CORE  WCLIMIT    QUEUETIME\n");
      printf("================================================================================\n");
   }

   show_waiting_jobs(waiting_dj_list, full);
   printf("\n");

   printf("WAITING JOBS WITH JOB DEPENDENCIES---\n");
   if (full) {
      printf("JOBID     JOBNAME    USERNAME      STATE   CORE  HOST  QUEUE        WCLIMIT    QUEUETIME\n");
      printf("==================================================================================================\n");
   } else {
      printf("JOBID     JOBNAME    USERNAME      STATE   CORE  WCLIMIT    QUEUETIME\n");
      printf("================================================================================\n");
   }

   show_waiting_jobs(dep_waiting_dj_list, full);
   printf("\n");
   printf("UNSCHEDULED JOBS---------------------\n");
   if (full) {
      printf("JOBID     JOBNAME    USERNAME      STATE   CORE  HOST  QUEUE        WCLIMIT    QUEUETIME\n");
      printf("==================================================================================================\n");
   } else {
      printf("JOBID     JOBNAME    USERNAME      STATE   CORE  WCLIMIT    QUEUETIME\n");
      printf("================================================================================\n");
   }
   /* print unscheduled jobs */

   show_waiting_jobs(unsched_dj_list, full);
   printf("\n");

   total_job_count = active_job_count + waiting_job_count + dep_waiting_job_count + unsched_job_count;
   printf("Total jobs: %-5d Active Jobs: %-5d Waiting Jobs: %-5d Dep/Unsched Jobs: %-5d\n",
          total_job_count, active_job_count, waiting_job_count, dep_waiting_job_count + unsched_job_count);

   lFreeList(&active_dj_list);
   lFreeList(&waiting_dj_list);
   lFreeList(&dep_waiting_dj_list);
   lFreeList(&unsched_dj_list);

   lFreeList(&ilp);
   lFreeList(&jlp);
   DRETURN(0);
}