Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: /
Date: Thu, 28 Feb 2019 18:37:21
Message-Id: 1551378953.9dcbcdfd0c90d76ddbb4b4dcdd41a981441f53e2.grobian@gentoo
1 commit: 9dcbcdfd0c90d76ddbb4b4dcdd41a981441f53e2
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Thu Feb 28 18:35:53 2019 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Thu Feb 28 18:35:53 2019 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=9dcbcdfd
7
8 qlop: introduce machine elapsed time and standard time
9
10 Report elapsed time in short notation by default, use elaborate notation
11 using -H, print just seconds (previous behaviour) using -M.
12
13 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
14
15 qlop.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++------------------
16 1 file changed, 54 insertions(+), 20 deletions(-)
17
18 diff --git a/qlop.c b/qlop.c
19 index 08ea479..d5c2548 100644
20 --- a/qlop.c
21 +++ b/qlop.c
22 @@ -11,12 +11,13 @@
23
24 #define QLOP_DEFAULT_LOGFILE "emerge.log"
25
26 -#define QLOP_FLAGS "ctaHmuUserd:f:w:" COMMON_FLAGS
27 +#define QLOP_FLAGS "ctaHMmuUserd:f:w:" COMMON_FLAGS
28 static struct option const qlop_long_opts[] = {
29 {"summary", no_argument, NULL, 'c'},
30 {"time", no_argument, NULL, 't'},
31 {"average", no_argument, NULL, 'a'},
32 {"human", no_argument, NULL, 'H'},
33 + {"machine", no_argument, NULL, 'M'},
34 {"merge", no_argument, NULL, 'm'},
35 {"unmerge", no_argument, NULL, 'u'},
36 {"autoclean", no_argument, NULL, 'U'},
37 @@ -33,6 +34,7 @@ static const char * const qlop_opts_help[] = {
38 "Print time taken to complete action",
39 "Print average time taken to complete action",
40 "Print elapsed time in human readable format (use with -t or -a)",
41 + "Print elapsed time as seconds with no formatting",
42 "Show merge history",
43 "Show unmerge history",
44 "Show autoclean unmerge history",
45 @@ -63,6 +65,7 @@ struct qlop_mode {
46 char do_average:1;
47 char do_summary:1;
48 char do_human:1;
49 + char do_machine:1;
50 char do_endtime:1;
51 };
52
53 @@ -181,21 +184,28 @@ static char *fmt_date(struct qlop_mode *flags, time_t ts, time_t te)
54 static char _elapsed_buf[256];
55 static char *fmt_elapsedtime(struct qlop_mode *flags, time_t e)
56 {
57 - if (flags->do_human) {
58 - time_t dd;
59 - time_t hh;
60 - time_t mm;
61 - time_t ss;
62 - size_t bufpos = 0;
63 -
64 - ss = e % 60;
65 - e /= 60;
66 - mm = e % 60;
67 - e /= 60;
68 - hh = e % 24;
69 - e /= 24;
70 - dd = e;
71 + time_t dd;
72 + time_t hh;
73 + time_t mm;
74 + time_t ss;
75 + size_t bufpos = 0;
76 +
77 + if (flags->do_machine) {
78 + snprintf(_elapsed_buf, sizeof(_elapsed_buf),
79 + "%s%zd%s",
80 + GREEN, (size_t)e, NORM);
81 + return _elapsed_buf;
82 + }
83
84 + ss = e % 60;
85 + e /= 60;
86 + mm = e % 60;
87 + e /= 60;
88 + hh = e % 24;
89 + e /= 24;
90 + dd = e;
91 +
92 + if (flags->do_human) {
93 if (dd > 0)
94 bufpos += snprintf(_elapsed_buf + bufpos,
95 sizeof(_elapsed_buf) - bufpos,
96 @@ -220,8 +230,23 @@ static char *fmt_elapsedtime(struct qlop_mode *flags, time_t e)
97 bufpos == 0 ? "" : ", ",
98 GREEN, (size_t)ss, NORM, ss == 1 ? "" : "s");
99 } else {
100 - snprintf(_elapsed_buf, sizeof(_elapsed_buf), "%s%zd%s seconds",
101 - GREEN, (size_t)e, NORM);
102 + hh += 24 * dd;
103 + if (hh > 0) {
104 + snprintf(_elapsed_buf, sizeof(_elapsed_buf),
105 + "%s%zd%s:%s%02zd%s:%s%02zd%s",
106 + GREEN, (size_t)hh, NORM,
107 + GREEN, (size_t)mm, NORM,
108 + GREEN, (size_t)ss, NORM);
109 + } else if (mm > 0) {
110 + snprintf(_elapsed_buf, sizeof(_elapsed_buf),
111 + "%s%zd%s′%s%02zd%s″",
112 + GREEN, (size_t)mm, NORM,
113 + GREEN, (size_t)ss, NORM);
114 + } else {
115 + snprintf(_elapsed_buf, sizeof(_elapsed_buf),
116 + "%s%zd%ss",
117 + GREEN, (size_t)ss, NORM);
118 + }
119 }
120
121 return _elapsed_buf;
122 @@ -461,7 +486,8 @@ static int do_emerge_log(
123 if (flags->do_time) {
124 printf("%s *** %s%s%s: %s\n",
125 fmt_date(flags, sync_start, tstart),
126 - GREEN, p, NORM, fmt_elapsedtime(flags, elapsed));
127 + GREEN, p, NORM,
128 + fmt_elapsedtime(flags, elapsed));
129 } else {
130 printf("%s *** %s%s%s\n",
131 fmt_date(flags, sync_start, tstart),
132 @@ -846,6 +872,7 @@ int qlop_main(int argc, char **argv)
133 m.do_average = 0;
134 m.do_summary = 0;
135 m.do_human = 0;
136 + m.do_machine = 0;
137 m.do_endtime = 0;
138
139 while ((ret = GETOPT_LONG(QLOP, qlop, "")) != -1) {
140 @@ -861,6 +888,7 @@ int qlop_main(int argc, char **argv)
141 case 'a': m.do_average = 1; break;
142 case 'c': m.do_summary = 1; break;
143 case 'H': m.do_human = 1; break;
144 + case 'M': m.do_machine = 1; break;
145 case 'e': m.do_endtime = 1; break;
146 case 'd':
147 if (start_time == 0) {
148 @@ -924,8 +952,7 @@ int qlop_main(int argc, char **argv)
149 m.do_sync == 0 &&
150 m.do_running == 0 &&
151 m.do_average == 0 &&
152 - m.do_summary == 0 &&
153 - m.do_human == 0
154 + m.do_summary == 0
155 )
156 {
157 m.do_merge = 1;
158 @@ -951,6 +978,13 @@ int qlop_main(int argc, char **argv)
159 m.do_average = 0;
160 }
161
162 + /* handle -H / -M conflict */
163 + if (m.do_human && m.do_machine) {
164 + warn("-H and -M cannot be used together, dropping -M: "
165 + "only humans make mistakes");
166 + m.do_machine = 0;
167 + }
168 +
169 if (m.do_sync && array_cnt(atoms) > 0) {
170 warn("-s cannot be used when specifying atoms, dropping -s");
171 m.do_sync = 0;