]> git.ipfire.org Git - thirdparty/util-linux.git/blob - misc-utils/lsclocks.c
scriptreplay: fix uninitialized value [coverity scan]
[thirdparty/util-linux.git] / misc-utils / lsclocks.c
1 /*
2 * lsclocks(1) - display system clocks
3 *
4 * Copyright (C) 2023 Thomas Weißschuh <thomas@t-8ch.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it would be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include <stdio.h>
22 #include <stdbool.h>
23 #include <time.h>
24 #include <inttypes.h>
25 #include <getopt.h>
26 #include <glob.h>
27 #include <sys/ioctl.h>
28
29 #include <libsmartcols.h>
30
31 #include <linux/rtc.h>
32
33 #include "c.h"
34 #include "nls.h"
35 #include "strutils.h"
36 #include "timeutils.h"
37 #include "closestream.h"
38 #include "xalloc.h"
39 #include "pathnames.h"
40 #include "all-io.h"
41 #include "list.h"
42
43 #ifndef CLOCK_REALTIME
44 #define CLOCK_REALTIME 0
45 #endif
46
47 #ifndef CLOCK_MONOTONIC
48 #define CLOCK_MONOTONIC 1
49 #endif
50
51 #ifndef CLOCK_MONOTONIC_RAW
52 #define CLOCK_MONOTONIC_RAW 4
53 #endif
54
55 #ifndef CLOCK_REALTIME_COARSE
56 #define CLOCK_REALTIME_COARSE 5
57 #endif
58
59 #ifndef CLOCK_MONOTONIC_COARSE
60 #define CLOCK_MONOTONIC_COARSE 6
61 #endif
62
63 #ifndef CLOCK_BOOTTIME
64 #define CLOCK_BOOTTIME 7
65 #endif
66
67 #ifndef CLOCK_REALTIME_ALARM
68 #define CLOCK_REALTIME_ALARM 8
69 #endif
70
71 #ifndef CLOCK_BOOTTIME_ALARM
72 #define CLOCK_BOOTTIME_ALARM 9
73 #endif
74
75 #ifndef CLOCK_TAI
76 #define CLOCK_TAI 11
77 #endif
78
79 enum CLOCK_TYPE {
80 CT_SYS,
81 CT_PTP,
82 CT_CPU,
83 CT_RTC,
84 };
85
86 static const char *clock_type_name(enum CLOCK_TYPE type)
87 {
88 switch (type) {
89 case CT_SYS:
90 return "sys";
91 case CT_PTP:
92 return "ptp";
93 case CT_CPU:
94 return "cpu";
95 case CT_RTC:
96 return "rtc";
97 }
98 errx(EXIT_FAILURE, _("Unknown clock type %d"), type);
99 }
100
101 struct clockinfo {
102 enum CLOCK_TYPE type;
103 clockid_t id;
104 const char * const id_name;
105 const char * const name;
106 const char * const ns_offset_name;
107 bool no_id;
108 };
109
110 static const struct clockinfo clocks[] = {
111 { CT_SYS, CLOCK_REALTIME, "CLOCK_REALTIME", "realtime" },
112 { CT_SYS, CLOCK_MONOTONIC, "CLOCK_MONOTONIC", "monotonic",
113 .ns_offset_name = "monotonic" },
114 { CT_SYS, CLOCK_MONOTONIC_RAW, "CLOCK_MONOTONIC_RAW", "monotonic-raw" },
115 { CT_SYS, CLOCK_REALTIME_COARSE, "CLOCK_REALTIME_COARSE", "realtime-coarse" },
116 { CT_SYS, CLOCK_MONOTONIC_COARSE, "CLOCK_MONOTONIC_COARSE", "monotonic-coarse" },
117 { CT_SYS, CLOCK_BOOTTIME, "CLOCK_BOOTTIME", "boottime",
118 .ns_offset_name = "boottime" },
119 { CT_SYS, CLOCK_REALTIME_ALARM, "CLOCK_REALTIME_ALARM", "realtime-alarm" },
120 { CT_SYS, CLOCK_BOOTTIME_ALARM, "CLOCK_BOOTTIME_ALARM", "boottime-alarm" },
121 { CT_SYS, CLOCK_TAI, "CLOCK_TAI", "tai" },
122 };
123
124 /* column IDs */
125 enum {
126 COL_TYPE,
127 COL_ID,
128 COL_CLOCK,
129 COL_NAME,
130 COL_TIME,
131 COL_ISO_TIME,
132 COL_RESOL,
133 COL_RESOL_RAW,
134 COL_REL_TIME,
135 COL_NS_OFFSET,
136 };
137
138 /* column names */
139 struct colinfo {
140 const char * const name; /* header */
141 double whint; /* width hint (N < 1 is in percent of termwidth) */
142 int flags; /* SCOLS_FL_* */
143 int json_type; /* SCOLS_JSON_* */
144 const char * const help;
145 };
146
147 /* columns descriptions */
148 static const struct colinfo infos[] = {
149 [COL_TYPE] = { "TYPE", 1, 0, SCOLS_JSON_STRING, N_("type") },
150 [COL_ID] = { "ID", 1, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("numeric id") },
151 [COL_CLOCK] = { "CLOCK", 1, 0, SCOLS_JSON_STRING, N_("symbolic name") },
152 [COL_NAME] = { "NAME", 1, 0, SCOLS_JSON_STRING, N_("readable name") },
153 [COL_TIME] = { "TIME", 1, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("numeric time") },
154 [COL_ISO_TIME] = { "ISO_TIME", 1, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, N_("human readable ISO time") },
155 [COL_RESOL] = { "RESOL", 1, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, N_("human readable resolution") },
156 [COL_RESOL_RAW] = { "RESOL_RAW", 1, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("resolution") },
157 [COL_REL_TIME] = { "REL_TIME", 1, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, N_("human readable relative time") },
158 [COL_NS_OFFSET] = { "NS_OFFSET", 1, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("namespace offset") },
159 };
160
161 static int column_name_to_id(const char *name, size_t namesz)
162 {
163 size_t i;
164
165 for (i = 0; i < ARRAY_SIZE(infos); i++) {
166 const char *cn = infos[i].name;
167
168 if (!strncasecmp(name, cn, namesz) && !*(cn + namesz))
169 return i;
170 }
171 warnx(_("unknown column: %s"), name);
172
173 return -1;
174 }
175
176 static void __attribute__((__noreturn__)) usage(void)
177 {
178 FILE *out = stdout;
179 size_t i;
180
181 fputs(USAGE_HEADER, out);
182 fprintf(out, _(" %s [options]\n"), program_invocation_short_name);
183
184 fputs(USAGE_OPTIONS, out);
185 fputs(_(" -J, --json use JSON output format\n"), out);
186 fputs(_(" -n, --noheadings don't print headings\n"), out);
187 fputs(_(" -o, --output <list> output columns\n"), out);
188 fputs(_(" --output-all output all columns\n"), out);
189 fputs(_(" -r, --raw use raw output format\n"), out);
190 fputs(_(" -t, --time <clock> show current time of single clock\n"), out);
191 fputs(_(" --no-discover-dynamic do not try to discover dynamic clocks\n"), out);
192 fputs(_(" -d, --dynamic-clock <path> also display specified dynamic clock\n"), out);
193 fputs(_(" -c, --cpu-clock <pid> also display CPU clock of specified process\n"), out);
194
195 fputs(USAGE_SEPARATOR, out);
196 fprintf(out, USAGE_HELP_OPTIONS(29));
197
198 fputs(USAGE_COLUMNS, out);
199
200 for (i = 0; i < ARRAY_SIZE(infos); i++)
201 fprintf(out, " %16s %-10s%s\n", infos[i].name,
202 infos[i].json_type == SCOLS_JSON_STRING? "<string>":
203 infos[i].json_type == SCOLS_JSON_ARRAY_STRING? "<string>":
204 infos[i].json_type == SCOLS_JSON_ARRAY_NUMBER? "<string>":
205 infos[i].json_type == SCOLS_JSON_NUMBER? "<number>":
206 "<boolean>",
207 _(infos[i].help));
208
209 fprintf(out, USAGE_MAN_TAIL("lsclocks(1)"));
210
211 exit(EXIT_SUCCESS);
212 }
213
214 __attribute__ ((__format__ (__printf__, 3, 4)))
215 static void scols_line_asprintf(struct libscols_line *ln, size_t n, const char *format, ...)
216 {
217 char *data;
218 va_list args;
219
220 va_start(args, format);
221 xvasprintf(&data, format, args);
222 va_end(args);
223
224 scols_line_refer_data(ln, n, data);
225 }
226
227 static void scols_line_format_timespec(struct libscols_line *ln, size_t n, const struct timespec *ts)
228 {
229 scols_line_asprintf(ln, n, "%ju.%09" PRId32, (uintmax_t) ts->tv_sec, (uint32_t) ts->tv_nsec);
230 }
231
232 static clockid_t parse_clock(const char *name)
233 {
234 size_t i;
235 uint32_t id = -1;
236 int rc;
237
238 rc = ul_strtou32(name, &id, 10);
239
240 for (i = 0; i < ARRAY_SIZE(clocks); i++) {
241 if (!strcmp(name, clocks[i].id_name)
242 || !strcmp(name, clocks[i].name))
243 return clocks[i].id;
244 if (rc == 0 && (clockid_t) id == clocks[i].id)
245 return id;
246 }
247
248 errx(EXIT_FAILURE, _("Unknown clock: %s"), name);
249 }
250
251 static int64_t get_namespace_offset(const char *name)
252 {
253 char *tokstr, *buf, *saveptr, *line, *space;
254 uint64_t ret;
255 int fd;
256
257 fd = open(_PATH_PROC_TIMENS_OFF, O_RDONLY);
258 if (fd == -1)
259 err(EXIT_FAILURE, _("Could not open %s"), _PATH_PROC_TIMENS_OFF);
260
261 read_all_alloc(fd, &buf);
262
263 for (tokstr = buf; ; tokstr = NULL) {
264 line = strtok_r(tokstr, "\n", &saveptr);
265 if (!line)
266 continue;
267 line = (char *) startswith(line, name);
268 if (!line || line[0] != ' ')
269 continue;
270
271 line = (char *) skip_blank(line);
272 space = strchr(line, ' ');
273 if (space)
274 *space = '\0';
275 ret = strtos64_or_err(line, _("Invalid offset"));
276 break;
277 }
278
279 free(buf);
280 close(fd);
281 return ret;
282 }
283
284 static void add_clock_line(struct libscols_table *tb, const int *columns,
285 size_t ncolumns, const struct clockinfo *clockinfo,
286 const struct timespec *now, const struct timespec *resolution)
287 {
288 char buf[FORMAT_TIMESTAMP_MAX];
289 struct libscols_line *ln;
290 size_t i;
291 int rc;
292
293 ln = scols_table_new_line(tb, NULL);
294 if (!ln)
295 errx(EXIT_FAILURE, _("failed to allocate output line"));
296
297 for (i = 0; i < ncolumns; i++) {
298 switch (columns[i]) {
299 case COL_TYPE:
300 scols_line_set_data(ln, i, clock_type_name(clockinfo->type));
301 break;
302 case COL_ID:
303 if (!clockinfo->no_id)
304 scols_line_asprintf(ln, i, "%ju", (uintmax_t) clockinfo->id);
305 break;
306 case COL_CLOCK:
307 scols_line_set_data(ln, i, clockinfo->id_name);
308 break;
309 case COL_NAME:
310 scols_line_set_data(ln, i, clockinfo->name);
311 break;
312 case COL_TIME:
313 if (now->tv_nsec == -1)
314 break;
315
316 scols_line_format_timespec(ln, i, now);
317 break;
318 case COL_ISO_TIME:
319 if (now->tv_nsec == -1)
320 break;
321
322 rc = strtimespec_iso(now,
323 ISO_GMTIME | ISO_DATE | ISO_TIME | ISO_T | ISO_DOTNSEC | ISO_TIMEZONE,
324 buf, sizeof(buf));
325 if (rc)
326 errx(EXIT_FAILURE, _("failed to format iso time"));
327 scols_line_set_data(ln, i, buf);
328 break;
329 case COL_RESOL:
330 if (resolution->tv_nsec == -1)
331 break;
332
333 rc = strtimespec_relative(resolution, buf, sizeof(buf));
334 if (rc)
335 errx(EXIT_FAILURE, _("failed to format relative time"));
336 scols_line_set_data(ln, i, buf);
337 break;
338 case COL_RESOL_RAW:
339 if (resolution->tv_nsec == -1)
340 break;
341 scols_line_format_timespec(ln, i, resolution);
342 break;
343 case COL_REL_TIME:
344 if (now->tv_nsec == -1)
345 break;
346 rc = strtimespec_relative(now, buf, sizeof(buf));
347 if (rc)
348 errx(EXIT_FAILURE, _("failed to format relative time"));
349 scols_line_set_data(ln, i, buf);
350 break;
351 case COL_NS_OFFSET:
352 if (clockinfo->ns_offset_name)
353 scols_line_asprintf(ln, i, "%"PRId64,
354 get_namespace_offset(clockinfo->ns_offset_name));
355 break;
356 }
357 }
358 }
359
360 static void add_posix_clock_line(struct libscols_table *tb, const int *columns,
361 size_t ncolumns, const struct clockinfo *clockinfo)
362 {
363 struct timespec resolution, now;
364 int rc;
365
366 rc = clock_gettime(clockinfo->id, &now);
367 if (rc)
368 now.tv_nsec = -1;
369
370 rc = clock_getres(clockinfo->id, &resolution);
371 if (rc)
372 resolution.tv_nsec = -1;
373
374 add_clock_line(tb, columns, ncolumns, clockinfo, &now, &resolution);
375 }
376
377 struct path_clock {
378 struct list_head head;
379 const char * path;
380 };
381
382 static void add_dynamic_clock_from_path(struct libscols_table *tb,
383 const int *columns, size_t ncolumns,
384 const char *path, bool explicit)
385 {
386 int fd = open(path, O_RDONLY);
387 if (fd == -1) {
388 if (explicit)
389 err(EXIT_FAILURE, _("Could not open %s"), path);
390 else
391 return;
392 }
393
394 struct clockinfo clockinfo = {
395 .type = CT_PTP,
396 .no_id = true,
397 .id_name = path,
398 .name = path,
399 };
400 add_posix_clock_line(tb, columns, ncolumns, &clockinfo);
401 close(fd);
402 }
403
404 static void add_dynamic_clocks_from_discovery(struct libscols_table *tb,
405 const int *columns, size_t ncolumns)
406 {
407 int rc;
408 size_t i;
409 glob_t state;
410
411 rc = glob("/dev/ptp*", 0, NULL, &state);
412 if (rc == GLOB_NOMATCH)
413 return;
414 else if (rc)
415 errx(EXIT_FAILURE, _("Could not glob: %d"), rc);
416
417 for (i = 0; i < state.gl_pathc; i++)
418 add_dynamic_clock_from_path(tb, columns, ncolumns,
419 state.gl_pathv[i], false);
420
421 globfree(&state);
422 }
423
424 static void add_rtc_clock_from_path(struct libscols_table *tb,
425 const int *columns, size_t ncolumns,
426 const char *path, bool explicit)
427 {
428 int fd, rc;
429 struct rtc_time rtc_time;
430 struct tm tm = { 0 };
431 struct timespec now = { 0 }, resolution = { .tv_nsec = -1 };
432
433 fd = open(path, O_RDONLY);
434 if (fd == -1) {
435 if (explicit)
436 err(EXIT_FAILURE, _("Could not open %s"), path);
437 else
438 return;
439 }
440
441 rc = ioctl(fd, RTC_RD_TIME, &rtc_time);
442 if (rc)
443 err(EXIT_FAILURE,
444 _("ioctl(RTC_RD_NAME) to %s to read the time failed"), path);
445
446 tm.tm_sec = rtc_time.tm_sec;
447 tm.tm_min = rtc_time.tm_min;
448 tm.tm_hour = rtc_time.tm_hour;
449 tm.tm_mday = rtc_time.tm_mday;
450 tm.tm_mon = rtc_time.tm_mon;
451 tm.tm_year = rtc_time.tm_year;
452 tm.tm_wday = rtc_time.tm_wday;
453 tm.tm_yday = rtc_time.tm_yday;
454
455 now.tv_sec = mktime(&tm);
456
457 struct clockinfo clockinfo = {
458 .type = CT_RTC,
459 .no_id = true,
460 .id_name = path,
461 .name = path,
462 };
463 add_clock_line(tb, columns, ncolumns, &clockinfo, &now, &resolution);
464
465 close(fd);
466 }
467
468 static void add_rtc_clocks_from_discovery(struct libscols_table *tb,
469 const int *columns, size_t ncolumns)
470 {
471 int rc;
472 size_t i;
473 glob_t state;
474
475 rc = glob("/dev/rtc*", 0, NULL, &state);
476 if (rc == GLOB_NOMATCH)
477 return;
478 if (rc)
479 errx(EXIT_FAILURE, _("Could not glob: %d"), rc);
480
481 for (i = 0; i < state.gl_pathc; i++)
482 add_rtc_clock_from_path(tb, columns, ncolumns,
483 state.gl_pathv[i], false);
484
485 globfree(&state);
486 }
487
488 struct cpu_clock {
489 struct list_head head;
490 pid_t pid;
491 char name[sizeof(stringify_value(SINT_MAX(pid_t)))];
492 };
493
494 static void add_cpu_clock(struct libscols_table *tb,
495 const int *columns, size_t ncolumns,
496 pid_t pid, const char *name)
497 {
498 int rc;
499 clockid_t clockid;
500
501 rc = clock_getcpuclockid(pid, &clockid);
502 if (rc)
503 errx(EXIT_FAILURE, _("Could not get CPU clock of process %jd: %s"),
504 (intmax_t) pid, strerror(rc));
505
506 struct clockinfo clockinfo = {
507 .type = CT_CPU,
508 .id = clockid,
509 .name = name,
510 .no_id = true,
511 };
512 add_posix_clock_line(tb, columns, ncolumns, &clockinfo);
513 }
514
515
516 int main(int argc, char **argv)
517 {
518 size_t i;
519 int c, rc;
520 const struct colinfo *colinfo;
521
522 struct libscols_table *tb;
523 struct libscols_column *col;
524
525 bool noheadings = false, raw = false, json = false,
526 disc_dynamic = true, disc_rtc = true;
527 const char *outarg = NULL;
528 int columns[ARRAY_SIZE(infos) * 2];
529 size_t ncolumns = 0;
530 clockid_t clock = -1;
531 struct path_clock *path_clock;
532 struct cpu_clock *cpu_clock;
533 struct list_head *current_path_clock, *current_cpu_clock;
534 struct list_head dynamic_clocks, cpu_clocks, rtc_clocks;
535
536 struct timespec now;
537
538 enum {
539 OPT_OUTPUT_ALL = CHAR_MAX + 1,
540 OPT_NO_DISC_DYN,
541 OPT_NO_DISC_RTC,
542 };
543 static const struct option longopts[] = {
544 { "noheadings", no_argument, NULL, 'n' },
545 { "output", required_argument, NULL, 'o' },
546 { "output-all", no_argument, NULL, OPT_OUTPUT_ALL },
547 { "version", no_argument, NULL, 'V' },
548 { "help", no_argument, NULL, 'h' },
549 { "json", no_argument, NULL, 'J' },
550 { "raw", no_argument, NULL, 'r' },
551 { "time", required_argument, NULL, 't' },
552 { "no-discover-dynamic", no_argument, NULL, OPT_NO_DISC_DYN },
553 { "dynamic-clock", required_argument, NULL, 'd' },
554 { "cpu-clock", required_argument, NULL, 'c' },
555 { "no-discover-rtc", no_argument, NULL, OPT_NO_DISC_RTC },
556 { "rtc", required_argument, NULL, 'x' },
557 { 0 }
558 };
559
560 setlocale(LC_ALL, "");
561 bindtextdomain(PACKAGE, LOCALEDIR);
562 textdomain(PACKAGE);
563 close_stdout_atexit();
564
565 INIT_LIST_HEAD(&dynamic_clocks);
566 INIT_LIST_HEAD(&cpu_clocks);
567 INIT_LIST_HEAD(&rtc_clocks);
568
569 while ((c = getopt_long(argc, argv, "no:Jrt:d:c:x:Vh", longopts, NULL)) != -1) {
570 switch (c) {
571 case 'n':
572 noheadings = true;
573 break;
574 case 'o':
575 outarg = optarg;
576 break;
577 case OPT_OUTPUT_ALL:
578 for (ncolumns = 0; ncolumns < ARRAY_SIZE(infos); ncolumns++)
579 columns[ncolumns] = ncolumns;
580 break;
581 case 'J':
582 json = true;
583 break;
584 case 'r':
585 raw = true;
586 break;
587 case 't':
588 clock = parse_clock(optarg);
589 break;
590 case 'd':
591 path_clock = xmalloc(sizeof(*path_clock));
592 path_clock->path = optarg;
593 list_add(&path_clock->head, &dynamic_clocks);
594 break;
595 case OPT_NO_DISC_DYN:
596 disc_dynamic = false;
597 break;
598 case 'c':
599 cpu_clock = xmalloc(sizeof(*cpu_clock));
600 cpu_clock->pid = strtopid_or_err(optarg, _("failed to parse pid"));
601 snprintf(cpu_clock->name, sizeof(cpu_clock->name),
602 "%jd", (intmax_t) cpu_clock->pid);
603 list_add(&cpu_clock->head, &cpu_clocks);
604 break;
605 case 'x':
606 path_clock = xmalloc(sizeof(*path_clock));
607 path_clock->path = optarg;
608 list_add(&path_clock->head, &rtc_clocks);
609 break;
610 case OPT_NO_DISC_RTC:
611 disc_rtc = false;
612 break;
613 case 'V':
614 print_version(EXIT_SUCCESS);
615 case 'h':
616 usage();
617 default:
618 errtryhelp(EXIT_FAILURE);
619 }
620 }
621
622 if (argv[optind])
623 errtryhelp(EXIT_FAILURE);
624
625 if (clock != -1) {
626 rc = clock_gettime(clock, &now);
627 if (rc)
628 err(EXIT_FAILURE, _("failed to get time"));
629 printf("%ju.%09"PRId32"\n", (uintmax_t) now.tv_sec, (uint32_t) now.tv_nsec);
630 return EXIT_SUCCESS;
631 }
632
633 if (!ncolumns) {
634 columns[ncolumns++] = COL_ID;
635 columns[ncolumns++] = COL_NAME;
636 columns[ncolumns++] = COL_TYPE;
637 columns[ncolumns++] = COL_TIME;
638 columns[ncolumns++] = COL_RESOL;
639 columns[ncolumns++] = COL_ISO_TIME;
640 }
641
642 if (outarg && string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
643 &ncolumns, column_name_to_id) < 0)
644 return EXIT_FAILURE;
645
646 scols_init_debug(0);
647
648 tb = scols_new_table();
649 if (!tb)
650 errx(EXIT_FAILURE, _("failed to allocate output table"));
651 scols_table_set_name(tb, "clocks");
652
653 for (i = 0; i < ncolumns; i++) {
654 colinfo = &infos[columns[i]];
655
656 col = scols_table_new_column(tb, colinfo->name, colinfo->whint, colinfo->flags);
657 if (!col)
658 errx(EXIT_FAILURE, _("failed to allocate output column"));
659
660 scols_column_set_json_type(col, colinfo->json_type);
661 }
662
663 for (i = 0; i < ARRAY_SIZE(clocks); i++)
664 add_posix_clock_line(tb, columns, ncolumns, &clocks[i]);
665
666 if (disc_dynamic)
667 add_dynamic_clocks_from_discovery(tb, columns, ncolumns);
668
669 list_for_each(current_path_clock, &dynamic_clocks) {
670 path_clock = list_entry(current_path_clock, struct path_clock, head);
671 add_dynamic_clock_from_path(tb, columns, ncolumns, path_clock->path, true);
672 }
673
674 list_free(&dynamic_clocks, struct path_clock, head, free);
675
676 if (disc_rtc)
677 add_rtc_clocks_from_discovery(tb, columns, ncolumns);
678
679 list_for_each(current_path_clock, &rtc_clocks) {
680 path_clock = list_entry(current_path_clock, struct path_clock, head);
681 add_rtc_clock_from_path(tb, columns, ncolumns, path_clock->path, true);
682 }
683
684 list_free(&rtc_clocks, struct path_clock, head, free);
685
686 list_for_each(current_cpu_clock, &cpu_clocks) {
687 cpu_clock = list_entry(current_cpu_clock, struct cpu_clock, head);
688 add_cpu_clock(tb, columns, ncolumns, cpu_clock->pid, cpu_clock->name);
689 }
690
691 list_free(&cpu_clocks, struct cpu_clock, head, free);
692
693 scols_table_enable_json(tb, json);
694 scols_table_enable_raw(tb, raw);
695 scols_table_enable_noheadings(tb, noheadings);
696 scols_print_table(tb);
697 scols_unref_table(tb);
698 }