~ubuntu-branches/ubuntu/precise/slurm-llnl/precise

« back to all changes in this revision

Viewing changes to src/sreport/common.c

  • Committer: Bazaar Package Importer
  • Author(s): Gennaro Oliva
  • Date: 2011-04-08 11:21:17 UTC
  • mfrom: (3.3.16 sid)
  • Revision ID: james.westby@ubuntu.com-20110408112117-nfnyq9dtm55hqoaw
Tags: 2.2.4-1
* New upstream releases 
* Cleaning spare file and directories, not belonging to the sources
  generated by the building process and not removed by distclean.
  Added debian/clean with spare files and rm -rf inside debian/rules
  for directories.
* Added new packages libslurm-perl, libslurmdb-perl, slurm-llnl-torque
  (Closes: #575822) thanks to Julien Blache

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
 
41
41
#include "sreport.h"
42
42
 
43
 
extern void sreport_print_time(print_field_t *field,
44
 
                               uint64_t value, uint64_t total_time, int last)
 
43
extern void slurmdb_report_print_time(print_field_t *field, uint64_t value,
 
44
                                      uint64_t total_time, int last)
45
45
{
46
46
        int abs_len = abs(field->len);
47
47
 
64
64
                double temp_d = (double)value;
65
65
 
66
66
                switch(time_format) {
67
 
                case SREPORT_TIME_SECS:
68
 
                        output = xstrdup_printf("%llu", value);
 
67
                case SLURMDB_REPORT_TIME_SECS:
 
68
                        output = xstrdup_printf("%"PRIu64"", value);
69
69
                        break;
70
 
                case SREPORT_TIME_MINS:
 
70
                case SLURMDB_REPORT_TIME_MINS:
71
71
                        temp_d /= 60;
72
72
                        output = xstrdup_printf("%.0lf", temp_d);
73
73
                        break;
74
 
                case SREPORT_TIME_HOURS:
 
74
                case SLURMDB_REPORT_TIME_HOURS:
75
75
                        temp_d /= 3600;
76
76
                        output = xstrdup_printf("%.0lf", temp_d);
77
77
                        break;
78
 
                case SREPORT_TIME_PERCENT:
 
78
                case SLURMDB_REPORT_TIME_PERCENT:
79
79
                        percent /= total_time;
80
80
                        percent *= 100;
81
81
                        output = xstrdup_printf("%.2lf%%", percent);
82
82
                        break;
83
 
                case SREPORT_TIME_SECS_PER:
 
83
                case SLURMDB_REPORT_TIME_SECS_PER:
84
84
                        percent /= total_time;
85
85
                        percent *= 100;
86
 
                        output = xstrdup_printf("%llu(%.2lf%%)",
 
86
                        output = xstrdup_printf("%"PRIu64"(%.2lf%%)",
87
87
                                                value, percent);
88
88
                        break;
89
 
                case SREPORT_TIME_MINS_PER:
 
89
                case SLURMDB_REPORT_TIME_MINS_PER:
90
90
                        percent /= total_time;
91
91
                        percent *= 100;
92
92
                        temp_d /= 60;
93
93
                        output = xstrdup_printf("%.0lf(%.2lf%%)",
94
94
                                                temp_d, percent);
95
95
                        break;
96
 
                case SREPORT_TIME_HOURS_PER:
 
96
                case SLURMDB_REPORT_TIME_HOURS_PER:
97
97
                        percent /= total_time;
98
98
                        percent *= 100;
99
99
                        temp_d /= 3600;
226
226
        list_iterator_destroy(itr);
227
227
}
228
228
 
229
 
extern int set_start_end_time(time_t *start, time_t *end)
230
 
{
231
 
        time_t my_time = time(NULL);
232
 
        time_t temp_time;
233
 
        struct tm start_tm;
234
 
        struct tm end_tm;
235
 
        int sent_start = (*start), sent_end = (*end);
236
 
 
237
 
//      info("now got %d and %d sent", (*start), (*end));
238
 
        /* Default is going to be the last day */
239
 
        if(!sent_end) {
240
 
                if(!localtime_r(&my_time, &end_tm)) {
241
 
                        error("Couldn't get localtime from end %d",
242
 
                              my_time);
243
 
                        return SLURM_ERROR;
244
 
                }
245
 
                end_tm.tm_hour = 0;
246
 
                //(*end) = mktime(&end_tm);
247
 
        } else {
248
 
                temp_time = sent_end;
249
 
                if(!localtime_r(&temp_time, &end_tm)) {
250
 
                        error("Couldn't get localtime from user end %d",
251
 
                              my_time);
252
 
                        return SLURM_ERROR;
253
 
                }
254
 
                if(end_tm.tm_sec >= 30)
255
 
                        end_tm.tm_min++;
256
 
                if(end_tm.tm_min >= 30)
257
 
                        end_tm.tm_hour++;
258
 
        }
259
 
 
260
 
        end_tm.tm_sec = 0;
261
 
        end_tm.tm_min = 0;
262
 
        end_tm.tm_isdst = -1;
263
 
        (*end) = mktime(&end_tm);
264
 
 
265
 
        if(!sent_start) {
266
 
                if(!localtime_r(&my_time, &start_tm)) {
267
 
                        error("Couldn't get localtime from start %d",
268
 
                              my_time);
269
 
                        return SLURM_ERROR;
270
 
                }
271
 
                start_tm.tm_hour = 0;
272
 
                start_tm.tm_mday--;
273
 
                //(*start) = mktime(&start_tm);
274
 
        } else {
275
 
                temp_time = sent_start;
276
 
                if(!localtime_r(&temp_time, &start_tm)) {
277
 
                        error("Couldn't get localtime from user start %d",
278
 
                              my_time);
279
 
                        return SLURM_ERROR;
280
 
                }
281
 
                if(start_tm.tm_sec >= 30)
282
 
                        start_tm.tm_min++;
283
 
                if(start_tm.tm_min >= 30)
284
 
                        start_tm.tm_hour++;
285
 
        }
286
 
        start_tm.tm_sec = 0;
287
 
        start_tm.tm_min = 0;
288
 
        start_tm.tm_isdst = -1;
289
 
        (*start) = mktime(&start_tm);
290
 
 
291
 
        if((*end)-(*start) < 3600)
292
 
                (*end) = (*start) + 3600;
293
 
/*      info("now got %d and %d sent", (*start), (*end)); */
294
 
/*      char start_char[20]; */
295
 
/*      char end_char[20]; */
296
 
/*      time_t my_start = (*start); */
297
 
/*      time_t my_end = (*end); */
298
 
 
299
 
/*      slurm_make_time_str(&my_start,  */
300
 
/*                          start_char, sizeof(start_char)); */
301
 
/*      slurm_make_time_str(&my_end, */
302
 
/*                          end_char, sizeof(end_char)); */
303
 
/*      info("which is %s - %s", start_char, end_char); */
304
 
        return SLURM_SUCCESS;
305
 
}
306
 
 
307
 
extern void destroy_sreport_assoc_rec(void *object)
308
 
{
309
 
        sreport_assoc_rec_t *sreport_assoc = (sreport_assoc_rec_t *)object;
310
 
        if(sreport_assoc) {
311
 
                xfree(sreport_assoc->acct);
312
 
                xfree(sreport_assoc->cluster);
313
 
                xfree(sreport_assoc->parent_acct);
314
 
                xfree(sreport_assoc->user);
315
 
                xfree(sreport_assoc);
316
 
        }
317
 
}
318
 
 
319
 
extern void destroy_sreport_user_rec(void *object)
320
 
{
321
 
        sreport_user_rec_t *sreport_user = (sreport_user_rec_t *)object;
322
 
        if(sreport_user) {
323
 
                xfree(sreport_user->acct);
324
 
                if(sreport_user->acct_list)
325
 
                        list_destroy(sreport_user->acct_list);
326
 
                xfree(sreport_user->name);
327
 
                xfree(sreport_user);
328
 
        }
329
 
}
330
 
 
331
 
extern void destroy_sreport_cluster_rec(void *object)
332
 
{
333
 
        sreport_cluster_rec_t *sreport_cluster =
334
 
                (sreport_cluster_rec_t *)object;
335
 
        if(sreport_cluster) {
336
 
                if(sreport_cluster->assoc_list)
337
 
                        list_destroy(sreport_cluster->assoc_list);
338
 
                xfree(sreport_cluster->name);
339
 
                if(sreport_cluster->user_list)
340
 
                        list_destroy(sreport_cluster->user_list);
341
 
                xfree(sreport_cluster);
342
 
        }
343
 
}
344
 
 
345
229
/*
346
230
 * Comparator used for sorting users largest cpu to smallest cpu
347
231
 *
348
232
 * returns: 1: user_a > user_b   0: user_a == user_b   -1: user_a < user_b
349
233
 *
350
234
 */
351
 
extern int sort_user_dec(sreport_user_rec_t *user_a, sreport_user_rec_t *user_b)
 
235
extern int sort_user_dec(slurmdb_report_user_rec_t *user_a,
 
236
                         slurmdb_report_user_rec_t *user_b)
352
237
{
353
238
        int diff = 0;
354
239
 
355
 
        if(sort_flag == SREPORT_SORT_TIME) {
 
240
        if(sort_flag == SLURMDB_REPORT_SORT_TIME) {
356
241
                if (user_a->cpu_secs > user_b->cpu_secs)
357
242
                        return -1;
358
243
                else if (user_a->cpu_secs < user_b->cpu_secs)
380
265
 *           -1: cluster_a < cluster_b
381
266
 *
382
267
 */
383
 
extern int sort_cluster_dec(sreport_cluster_rec_t *cluster_a,
384
 
                            sreport_cluster_rec_t *cluster_b)
 
268
extern int sort_cluster_dec(slurmdb_report_cluster_rec_t *cluster_a,
 
269
                            slurmdb_report_cluster_rec_t *cluster_b)
385
270
{
386
271
        int diff = 0;
387
272
 
408
293
 *           1: assoc_a < assoc_b
409
294
 *
410
295
 */
411
 
extern int sort_assoc_dec(sreport_assoc_rec_t *assoc_a,
412
 
                          sreport_assoc_rec_t *assoc_b)
 
296
extern int sort_assoc_dec(slurmdb_report_assoc_rec_t *assoc_a,
 
297
                          slurmdb_report_assoc_rec_t *assoc_b)
413
298
{
414
299
        int diff = 0;
415
300
 
445
330
 * returns: 1: resv_a > resv_b   0: resv_a == resv_b   -1: resv_a < resv_b
446
331
 *
447
332
 */
448
 
extern int sort_reservations_dec(acct_reservation_rec_t *resv_a,
449
 
                                 acct_reservation_rec_t *resv_b)
 
333
extern int sort_reservations_dec(slurmdb_reservation_rec_t *resv_a,
 
334
                                 slurmdb_reservation_rec_t *resv_b)
450
335
{
451
336
        int diff = 0;
452
337