forked from SchedMD/slurm
/
sh5util.c
1785 lines (1546 loc) · 44.9 KB
/
sh5util.c
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************\
* sh5util.c - slurm profile accounting plugin for io and energy using hdf5.
* - Utility to merge node-step files into a job file
* - or extract data from an job file
*****************************************************************************
* Copyright (C) 2013 Bull S. A. S.
* Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois.
*
* Copyright (C) 2013 SchedMD LLC
*
* Initially written by Rod Schultz <rod.schultz@bull.com> @ Bull
* and Danny Auble <da@schedmd.com> @ SchedMD.
* Adapted by Yoann Blein <yoann.blein@bull.net> @ Bull.
*
* This file is part of SLURM, a resource management program.
* For details, see <http://slurm.schedmd.com>.
* Please also read the included file: DISCLAIMER.
*
* SLURM is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* In addition, as a special exception, the copyright holders give permission
* to link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and
* distribute linked combinations including the two. You must obey the GNU
* General Public License in all respects for all of the code used other than
* OpenSSL. If you modify file(s) with this exception, you may extend this
* exception to your version of the file(s), but you are not obligated to do
* so. If you do not wish to do so, delete this exception statement from your
* version. If you delete this exception statement from all source files in
* the program, then also delete it here.
*
* SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with SLURM; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
\*****************************************************************************/
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#if HAVE_GETOPT_H
# include <getopt.h>
#else
# include "src/common/getopt.h"
#endif
#include <dirent.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include "src/common/uid.h"
#include "src/common/read_config.h"
#include "src/common/proc_args.h"
#include "src/common/xstring.h"
#include "src/common/slurm_acct_gather_profile.h"
#include "../hdf5_api.h"
#include "sh5util.h"
#include "libsh5util_old/sh5util_old.h"
#define MAX_PROFILE_PATH 1024
// #define MAX_ATTR_NAME 64
#define MAX_GROUP_NAME 64
// #define MAX_DATASET_NAME 64
// #define ATTR_NODENAME "Node Name"
// #define ATTR_STARTTIME "Start Time"
#define ATTR_NSTEPS "Number of Steps"
#define ATTR_NNODES "Number of Nodes"
// #define ATTR_NTASKS "Number of Tasks"
// #define ATTR_TASKID "Task Id"
// #define ATTR_CPUPERTASK "CPUs per Task"
// #define ATTR_DATATYPE "Data Type"
// #define ATTR_SUBDATATYPE "Subdata Type"
// #define ATTR_STARTTIME "Start Time"
// #define ATTR_STARTSEC "Start Second"
// #define SUBDATA_DATA "Data"
// #define SUBDATA_NODE "Node"
// #define SUBDATA_SAMPLE "Sample"
// #define SUBDATA_SERIES "Series"
// #define SUBDATA_TOTAL "Total"
// #define SUBDATA_SUMMARY "Summary"
#define GRP_ENERGY "Energy"
#define GRP_LUSTRE "Lustre"
// #define GRP_STEP "Step"
#define GRP_STEPS "Steps"
#define GRP_NODES "Nodes"
// #define GRP_NODE "Node"
#define GRP_NETWORK "Network"
// #define GRP_SAMPLES "Time Series"
// #define GRP_SAMPLE "Sample"
// #define GRP_TASKS "Tasks"
#define GRP_TASK "Task"
// #define GRP_TOTALS "Totals"
// Data types supported by all HDF5 plugins of this type
sh5util_opts_t params;
typedef struct table {
const char *step;
const char *node;
const char *group;
const char *name;
} table_t;
static FILE* output_file;
static bool group_mode = false;
static const char *current_step;
static const char *current_node;
static void _cleanup(void);
static int _set_options(const int argc, char **argv);
static int _merge_step_files(void);
static int _extract_series(void);
static int _extract_item(void);
static int _check_params(void);
static void _free_options(void);
static void _remove_empty_output(void);
static int _list_items(void);
static int _fields_intersection(hid_t fid_job, List tables, List fields);
static bool _has_batch_step(char *, char *);
static void _help_msg(void)
{
printf("\
Usage sh5util [<OPTION>] -j <job[.stepid]>\n"
"\n"
"Valid <OPTION> values are:\n"
" -L, --list Print the items of a series contained in a job file.\n"
" -i, --input merged file to extract from (default ./job_$jobid.h5)\n"
" -s, --series Name of series:\n"
" Energy | Lustre | Network | Tasks\n"
" -E, --extract Extract data series from job file.\n"
" -i, --input merged file to extract from (default ./job_$jobid.h5)\n"
" -N, --node Node name to extract (default is all)\n"
" -l, --level Level to which series is attached\n"
" [Node:Totals|Node:TimeSeries] (default Node:Totals)\n"
" -s, --series Name of series:\n"
" Energy | Lustre | Network | Tasks | Task_#\n"
" 'Tasks' is all tasks, Task_# is task_id (default is all)\n"
" -I, --item-extract Extract data item from one series from \n"
" all samples on all nodes from thejob file.\n"
" -i, --input merged file to extract from (default ./job_$jobid.h5)\n"
" -s, --series Name of series:\n"
" Energy | Lustre | Network | Task\n"
" -d, --data Name of data item in series (see man page) \n"
" -j, --jobs Format is <job(.step)>. Merge this job/step.\n"
" or comma-separated list of job steps. This option is\n"
" required. Not specifying a step will result in all\n"
" steps found to be processed.\n"
" -h, --help Print this description of use.\n"
" -o, --output Path to a file into which to write.\n"
" Default for merge is ./job_$jobid.h5\n"
" Default for extract is ./extract_$jobid.csv\n"
" -p, --profiledir Profile directory location where node-step files exist\n"
" default is what is set in acct_gather.conf\n"
" -S, --savefiles Don't remove node-step files after merging them \n"
" --user User who profiled job. (Handy for root user, defaults to \n"
" user running this command.)\n"
" --usage Display brief usage message\n");
}
int
main(int argc, char **argv)
{
int cc;
cc = _set_options(argc, argv);
if (cc < 0)
goto ouch;
cc = _check_params();
if (cc < 0)
goto ouch;
switch (params.mode) {
case SH5UTIL_MODE_MERGE:
info("Merging node-step files into %s",
params.output);
cc = _merge_step_files();
break;
case SH5UTIL_MODE_EXTRACT:
info("Extracting job data from %s into %s",
params.input, params.output);
cc = _extract_series();
break;
case SH5UTIL_MODE_ITEM_EXTRACT:
info("Extracting '%s' from '%s' data from %s into %s",
params.data_item, params.series,
params.input, params.output);
cc = _extract_item();
break;
case SH5UTIL_MODE_ITEM_LIST:
info("Listing items from %s", params.input);
cc = _list_items();
break;
default:
error("Unknown type %d", params.mode);
break;
}
if (cc == SLURM_PROTOCOL_VERSION_ERROR)
cc = run_old(argc, argv);
ouch:
_cleanup();
return cc;
}
static void _cleanup(void)
{
_remove_empty_output();
_free_options();
log_fini();
slurm_conf_destroy();
jobacct_gather_fini();
acct_gather_profile_fini();
acct_gather_conf_destroy();
}
/* _free_options()
*/
static void
_free_options(void)
{
xfree(params.dir);
xfree(params.input);
xfree(params.node);
xfree(params.output);
xfree(params.series);
xfree(params.data_item);
xfree(params.user);
}
static void _void_free(void *str)
{
xfree(str);
}
static int _str_cmp(void *str1, void *str2)
{
return !xstrcmp((const char *)str1, (const char *)str2);
}
static void _remove_empty_output(void)
{
struct stat sb;
if (stat(params.output, &sb) == -1) {
/* Ignore the error as the file may have
* not been created yet.
*/
return;
}
/* Remove the file if 0 size which means
* the program failed somewhere along the
* way and the file is just left hanging...
*/
if (sb.st_size == 0)
remove(params.output);
}
static void _init_opts(void)
{
memset(¶ms, 0, sizeof(sh5util_opts_t));
params.job_id = -1;
params.mode = SH5UTIL_MODE_MERGE;
params.step_id = -1;
}
static int _set_options(const int argc, char **argv)
{
int option_index = 0;
int cc;
log_options_t logopt = LOG_OPTS_STDERR_ONLY;
char *next_str = NULL;
uid_t u;
static struct option long_options[] = {
{"extract", no_argument, 0, 'E'},
{"item-extract", no_argument, 0, 'I'},
{"data", required_argument, 0, 'd'},
{"help", no_argument, 0, 'h'},
{"jobs", required_argument, 0, 'j'},
{"input", required_argument, 0, 'i'},
{"level", required_argument, 0, 'l'},
{"list", no_argument, 0, 'L'},
{"node", required_argument, 0, 'N'},
{"output", required_argument, 0, 'o'},
{"profiledir", required_argument, 0, 'p'},
{"series", required_argument, 0, 's'},
{"savefiles", no_argument, 0, 'S'},
{"usage", no_argument, 0, 'U'},
{"user", required_argument, 0, 'u'},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
{0, 0, 0, 0}};
log_init(xbasename(argv[0]), logopt, 0, NULL);
#if DEBUG
/* Move HDF5 trace printing to log file instead of stderr */
H5Eset_auto(H5E_DEFAULT, (herr_t (*)(hid_t, void *))H5Eprint,
log_fp());
#else
/* Silent HDF5 errors */
H5Eset_auto(H5E_DEFAULT, NULL, NULL);
#endif
_init_opts();
while ((cc = getopt_long(argc, argv, "d:Ehi:Ij:l:LN:o:p:s:Su:UvV",
long_options, &option_index)) != EOF) {
switch (cc) {
case 'd':
params.data_item = xstrdup(optarg);
/* params.data_item =
xstrtolower(params.data_item); */
break;
case 'E':
params.mode = SH5UTIL_MODE_EXTRACT;
break;
case 'I':
params.mode = SH5UTIL_MODE_ITEM_EXTRACT;
break;
case 'L':
params.mode = SH5UTIL_MODE_ITEM_LIST;
break;
case 'h':
_help_msg();
return -1;
break;
case 'i':
params.input = xstrdup(optarg);
break;
case 'j':
params.job_id = strtol(optarg, &next_str, 10);
if (next_str[0] == '.')
params.step_id =
strtol(next_str + 1, NULL, 10);
break;
case 'l':
params.level = xstrdup(optarg);
break;
case 'N':
params.node = xstrdup(optarg);
break;
case 'o':
params.output = xstrdup(optarg);
break;
case 'p':
params.dir = xstrdup(optarg);
break;
case 's':
if (strcmp(optarg, GRP_ENERGY)
&& strcmp(optarg, GRP_LUSTRE)
&& strcmp(optarg, GRP_NETWORK)
&& strncmp(optarg,GRP_TASK,
strlen(GRP_TASK))) {
error("Bad value for --series=\"%s\"",
optarg);
return -1;
}
params.series = xstrdup(optarg);
break;
case 'S':
params.keepfiles = 1;
break;
case 'u':
if (uid_from_string(optarg, &u) < 0) {
error("No such user --uid=\"%s\"",
optarg);
return -1;
}
params.user = uid_to_string(u);
break;
case 'U':
_help_msg();
return -1;
break;
case 'v':
params.verbose++;
break;
case 'V':
print_slurm_version();
return -1;
break;
case ':':
case '?': /* getopt() has explained it */
return -1;
}
}
if (params.verbose) {
logopt.stderr_level += params.verbose;
log_alter(logopt, SYSLOG_FACILITY_USER, NULL);
}
return 0;
}
/* _check_params()
*/
static int
_check_params(void)
{
if (params.job_id == -1) {
error("JobID must be specified.");
return -1;
}
if (params.user == NULL)
params.user = uid_to_string(getuid());
if (!params.dir)
acct_gather_profile_g_get(ACCT_GATHER_PROFILE_DIR, ¶ms.dir);
if (!params.dir) {
error("Cannot read/parse acct_gather.conf");
return -1;
}
if (params.mode == SH5UTIL_MODE_EXTRACT) {
if (!params.level)
params.level = xstrdup("Node:Totals");
if (!params.input)
params.input = xstrdup_printf(
"./job_%d.h5", params.job_id);
if (!params.output)
params.output = xstrdup_printf(
"./extract_%d.csv", params.job_id);
if (!params.series)
fatal("Must specify series option --series");
}
if (params.mode == SH5UTIL_MODE_ITEM_EXTRACT) {
if (!params.data_item)
fatal("Must specify data option --data ");
if (!params.series)
fatal("Must specify series option --series");
if (!params.input)
params.input = xstrdup_printf("./job_%d.h5", params.job_id);
if (!params.output)
params.output = xstrdup_printf("./%s_%s_%d.csv",
params.series,
params.data_item,
params.job_id);
}
if (params.mode == SH5UTIL_MODE_ITEM_LIST) {
if (!params.input)
params.input = xstrdup_printf(
"./job_%d.h5", params.job_id);
if (!params.series)
fatal("Must specify series option --series");
}
if (!params.output)
params.output = xstrdup_printf("./job_%d.h5", params.job_id);
return 0;
}
/* Copy the group "/{NodeName}" of the hdf5 file file_name into the location
* jgid_nodes */
static int _merge_node_step_data(char* file_name, char* node_name,
hid_t jgid_nodes, hid_t jgid_tasks)
{
hid_t fid_nodestep;
char group_name[MAX_GROUP_NAME+1];
fid_nodestep = H5Fopen(file_name, H5F_ACC_RDONLY, H5P_DEFAULT);
if (fid_nodestep < 0) {
error("Failed to open %s",file_name);
return SLURM_ERROR;
}
sprintf(group_name, "/%s", node_name);
hid_t ocpypl_id = H5Pcreate(H5P_OBJECT_COPY); /* default copy */
hid_t lcpl_id = H5Pcreate(H5P_LINK_CREATE); /* parameters */
if (H5Ocopy(fid_nodestep, group_name, jgid_nodes, node_name,
ocpypl_id, lcpl_id) < 0) {
debug("Failed to copy node step data of %s into the job file, "
"trying with old method",
node_name);
return SLURM_PROTOCOL_VERSION_ERROR;
}
H5Fclose(fid_nodestep);
if (!params.keepfiles)
remove(file_name);
return SLURM_SUCCESS;
}
/* Look for step and node files and merge them together into one job file */
static int _merge_step_files(void)
{
hid_t fid_job = -1;
hid_t jgid_steps = -1;
hid_t jgid_step = -1;
hid_t jgid_nodes = -1;
hid_t jgid_tasks = -1;
DIR *dir;
struct dirent *de;
char file_name[MAX_PROFILE_PATH+1];
char step_dir[MAX_PROFILE_PATH+1];
char step_path[MAX_PROFILE_PATH+1];
char jgrp_step_name[MAX_GROUP_NAME+1];
char jgrp_nodes_name[MAX_GROUP_NAME+1];
char *step_node;
char *pos_char;
char *stepno;
int stepx = 0;
int num_steps = 0;
int nodex = -1;
int max_step = -1;
int jobid, stepid;
bool found_files = false;
int rc = SLURM_SUCCESS;
char batch_step[PATH_MAX];
char batch_node[MAXHOSTNAMELEN];
int has_batch;
sprintf(step_dir, "%s/%s", params.dir, params.user);
batch_step[0] = 0;
has_batch = 0;
if (_has_batch_step(batch_step, batch_node))
has_batch = 1;
while (max_step == -1 || stepx <= max_step) {
if (!(dir = opendir(step_dir))) {
error("Cannot open %s job profile directory: %m", step_dir);
return -1;
}
nodex = 0;
while ((de = readdir(dir))) {
strcpy(file_name, de->d_name);
if (file_name[0] == '.')
continue;
pos_char = strstr(file_name,".h5");
if (!pos_char)
continue;
*pos_char = 0;
pos_char = strchr(file_name,'_');
if (!pos_char)
continue;
*pos_char = 0;
jobid = strtol(file_name, NULL, 10);
if (jobid != params.job_id)
continue;
stepno = pos_char + 1;
pos_char = strchr(stepno,'_');
if (!pos_char) {
continue;
}
*pos_char = 0;
if (strcmp(stepno, "batch") == 0) {
continue;
}
stepid = strtol(stepno, NULL, 10);
if (stepid > max_step)
max_step = stepid;
if (stepid != stepx)
continue;
step_node = pos_char + 1;
if (!found_files) {
fid_job = H5Fcreate(params.output,
H5F_ACC_TRUNC,
H5P_DEFAULT,
H5P_DEFAULT);
if (fid_job < 0) {
error("Failed create HDF5 file %s", params.output);
return -1;
}
found_files = true;
jgid_steps = make_group(fid_job, GRP_STEPS);
if (jgid_steps < 0) {
error("Failed to create group %s", GRP_STEPS);
continue;
}
if (has_batch) {
sprintf(jgrp_step_name, "/%s/batch", GRP_STEPS);
jgid_step = make_group(fid_job, jgrp_step_name);
if (jgid_step < 0) {
error("Failed to create %s", jgrp_step_name);
continue;
}
sprintf(jgrp_nodes_name,"%s/%s",
jgrp_step_name,
GRP_NODES);
jgid_nodes = make_group(jgid_step,
jgrp_nodes_name);
if (jgid_nodes < 0) {
error("Failed to create %s", jgrp_nodes_name);
continue;
}
sprintf(step_path, "%s/%s", step_dir, batch_step);
rc = _merge_node_step_data(step_path,
batch_node,
jgid_nodes,
jgid_tasks);
H5Gclose(jgid_tasks);
H5Gclose(jgid_nodes);
H5Gclose(jgid_step);
has_batch = 0;
}
}
if (nodex == 0) {
num_steps++;
sprintf(jgrp_step_name, "/%s/%d", GRP_STEPS,
stepx);
jgid_step = make_group(fid_job, jgrp_step_name);
if (jgid_step < 0) {
error("Failed to create %s", jgrp_step_name);
continue;
}
sprintf(jgrp_nodes_name,"%s/%s",
jgrp_step_name,
GRP_NODES);
jgid_nodes = make_group(jgid_step,
jgrp_nodes_name);
if (jgid_nodes < 0) {
error("Failed to create %s", jgrp_nodes_name);
continue;
}
/*
sprintf(jgrp_tasks_name,"%s/%s",
jgrp_step_name,
GRP_TASKS);
jgid_tasks = make_group(jgid_step,
jgrp_tasks_name);
if (jgid_tasks < 0) {
error("Failed to create %s", jgrp_tasks_name);
continue;
}
*/
}
sprintf(step_path, "%s/%s", step_dir, de->d_name);
debug("Adding %s to the job file", step_path);
rc = _merge_node_step_data(step_path, step_node,
jgid_nodes, jgid_tasks);
nodex++;
}
closedir(dir);
if (nodex > 0) {
put_int_attribute(jgid_step, ATTR_NNODES, nodex);
H5Gclose(jgid_tasks);
H5Gclose(jgid_nodes);
H5Gclose(jgid_step);
}
/* If we did not find the step 0
* bail out.
*/
if (stepx == 0
&& !found_files)
break;
stepx++;
}
if (!found_files)
info("No node-step files found for jobid %d", params.job_id);
else
put_int_attribute(fid_job, ATTR_NSTEPS, num_steps);
if (jgid_steps != -1)
H5Gclose(jgid_steps);
if (fid_job != -1)
H5Fclose(fid_job);
return rc;
}
/* ============================================================================
* ============================================================================
* Functions for data extraction
* ============================================================================
* ========================================================================= */
static void _table_free(void *table)
{
table_t *t = (table_t *)table;
xfree(t->step);
xfree(t->node);
xfree(t->group);
xfree(t->name);
xfree(table);
}
static void _table_path(table_t *t, char *path)
{
snprintf(path, MAX_PROFILE_PATH,
"/"GRP_STEPS"/%s/"GRP_NODES"/%s/%s/%s",
t->step, t->node, t->group, t->name);
}
static herr_t _collect_tables_group(hid_t g_id, const char *name,
const H5L_info_t *link_info, void *op_data)
{
List tables = (List)op_data;
hid_t table_id = -1;
/* open the dataset. */
if ((table_id = H5Dopen(g_id, name, H5P_DEFAULT)) < 0) {
error("Failed to open the dataset %s", name);
return -1;
}
H5Dclose(table_id);
group_mode = true;
table_t *t = xmalloc(sizeof(table_t));
t->step = xstrdup(current_step);
t->node = xstrdup(current_node);
t->group = xstrdup(params.series);
t->name = xstrdup(name);
list_append(tables, t);
return 0;
}
static herr_t _collect_tables_node(hid_t g_id, const char *name,
const H5L_info_t *link_info, void *op_data)
{
char object_path[MAX_PROFILE_PATH+1];
List tables = (List)op_data;
hid_t object_id = -1;
herr_t err;
/* node filter */
if (params.node
&& strcmp(params.node, "*") != 0
&& strcmp(params.node, name) != 0)
return 0;
snprintf(object_path, MAX_PROFILE_PATH+1, "%s/%s", name, params.series);
current_node = name;
/* open the dataset. */
if ((object_id = H5Oopen(g_id, object_path, H5P_DEFAULT)) < 0) {
error("Series %s not found", params.series);
return -1;
}
if (H5Iget_type(object_id) == H5I_DATASET) {
table_t *t = xmalloc(sizeof(table_t));
t->step = xstrdup(current_step);
t->node = xstrdup(name);
t->group = xstrdup("");
t->name = xstrdup(params.series);
list_append(tables, t);
} else if (H5Iget_type(object_id) == H5I_GROUP) {
err = H5Literate(object_id, H5_INDEX_NAME, H5_ITER_INC, NULL,
_collect_tables_group, op_data);
if (err < 0) {
debug("2 Failed to iterate through group %s", object_path);
return SLURM_PROTOCOL_VERSION_ERROR;
}
} else {
error("Object of unknown type: %s", object_path);
H5Oclose(object_id);
return -1;
}
H5Oclose(object_id);
return 0;
}
static herr_t _collect_tables_step(hid_t g_id, const char *name,
const H5L_info_t *link_info, void *op_data)
{
char nodes_path[MAX_PROFILE_PATH];
herr_t err;
/* step filter */
if ((params.step_id != -1) && (atoi(name) != params.step_id))
return 0;
snprintf(nodes_path, MAX_PROFILE_PATH, "%s/"GRP_NODES, name);
current_step = name;
err = H5Literate_by_name(g_id, nodes_path, H5_INDEX_NAME,
H5_ITER_INC, NULL, _collect_tables_node,
op_data, H5P_DEFAULT);
if (err < 0) {
debug("3 Failed to iterate through group /"GRP_STEPS"/%s",
nodes_path);
return err;
}
return 0;
}
static int _tables_list(hid_t fid_job, List tables)
{
herr_t err;
ListIterator it;
table_t *t;
/* Find the list of tables to be extracted */
err = H5Literate_by_name(fid_job, "/"GRP_STEPS, H5_INDEX_NAME,
H5_ITER_INC, NULL, _collect_tables_step,
(void *)tables, H5P_DEFAULT);
if (err < 0) {
debug("4 Failed to iterate through group /" GRP_STEPS);
return SLURM_PROTOCOL_VERSION_ERROR;
}
debug("tables found (group mode: %d):", group_mode);
it = list_iterator_create(tables);
while ((t = list_next(it))) {
debug(" /"GRP_STEPS"/%s/"GRP_NODES"/%s/%s/%s",
t->step, t->node, t->group, t->name);
}
list_iterator_destroy(it);
return SLURM_SUCCESS;
}
/**
* Print the total values of a table to the output file
*
* @param nb_fields Number of fields in the dataset
* @param offsets Offset of each field
* @param types Type of each field
* @param type_size Size of of a record in the dataset
* @param table_id ID of the table to extract from
* @param state State of the current extraction
* @param node_name Name of the node containing this table
* @param output output file
*/
static void _extract_totals(size_t nb_fields, size_t *offsets, hid_t *types,
hsize_t type_size, hid_t table_id,
table_t *table, FILE *output)
{
hsize_t nrecords;
size_t i, j;
uint8_t *data;
/* allocate space for aggregate values: 4 values (min, max,
* sum, avg) on 8 bytes (uint64_t/double) for each field */
uint64_t *agg_i;
double *agg_d;
data = xmalloc(type_size);
agg_i = xmalloc(nb_fields * 4 * sizeof(uint64_t));
agg_d = (double *)agg_i;
H5PTget_num_packets(table_id, &nrecords);
/* compute min/max/sum */
for (i = 0; i < nrecords; ++i) {
H5PTget_next(table_id, 1, data);
for (j = 0; j < nb_fields; ++j) {
if (H5Tequal(types[j], H5T_NATIVE_UINT64)) {
uint64_t v = *(uint64_t *)(data + offsets[j]);
uint64_t *a = agg_i + j * 4;
if (i == 0 || v < a[0]) /* min */
a[0] = v;
if (v > a[1]) /* max */
a[1] = v;
a[2] += v; /* sum */
} else if (H5Tequal(types[j], H5T_NATIVE_DOUBLE)) {
double v = *(double *)(data + offsets[j]);
double *a = agg_d + j * 4;
if (i == 0 || v < a[0]) /* min */
a[0] = v;
if (v > a[1]) /* max */
a[1] = v;
a[2] += v; /* sum */
}
}
}
/* compute avg */
if (nrecords) {
for (j = 0; j < nb_fields; ++j) {
if (H5Tequal(types[j], H5T_NATIVE_UINT64)) {
agg_d[j*4+3] = (double)agg_i[j*4+2] / nrecords;
} else if (H5Tequal(types[j], H5T_NATIVE_DOUBLE)) {
agg_d[j*4+3] = (double)agg_d[j*4+2] / nrecords;
}
}
}
/* step, node */
fprintf(output, "%s,%s", table->step, table->node);
if (group_mode)
fprintf(output, ",%s", table->name);
/* elapsed time (first field in the last record) */
fprintf(output, ",%"PRIu64, *(uint64_t *)data);
/* aggregate values */
for (j = 0; j < nb_fields; ++j) {
if (H5Tequal(types[j], H5T_NATIVE_UINT64)) {
fprintf(output, ",%"PRIu64",%"PRIu64",%"PRIu64",%lf",
agg_i[j * 4 + 0],
agg_i[j * 4 + 1],
agg_i[j * 4 + 2],
agg_d[j * 4 + 3]);
} else if (H5Tequal(types[j], H5T_NATIVE_DOUBLE)) {
fprintf(output, ",%lf,%lf,%lf,%lf",
agg_d[j * 4 + 0],
agg_d[j * 4 + 1],
agg_d[j * 4 + 2],
agg_d[j * 4 + 3]);
}
}
fputc('\n', output);
xfree(agg_i);
xfree(data);
}
/**
* Extract the content of a table within a node. This function first discovers
* the content of the table and then handles both timeseries and totals levels.
*/
static int _extract_series_table(hid_t fid_job, table_t *table, List fields,
FILE *output, bool level_total)
{
char path[MAX_PROFILE_PATH];
size_t i, j;
size_t max_fields = list_count(fields);
size_t nb_fields = 0;
size_t offsets[max_fields];
hid_t types[max_fields];
hid_t did = -1; /* dataset id */
hid_t tid = -1; /* file type ID */
hid_t n_tid = -1; /* native type ID */
hid_t m_tid = -1; /* member type ID */
hid_t nm_tid = -1; /* native member ID */
hid_t table_id = -1;
hsize_t nmembers;
hsize_t type_size;
hsize_t nrecords;
char *m_name;
_table_path(table, path);
debug("Extracting from table %s", path);
/* open the dataset. */
if ((did = H5Dopen(fid_job, path, H5P_DEFAULT)) < 0) {