]>
git.proxmox.com Git - mirror_qemu.git/blob - cmd.c
2 * Copyright (c) 2003-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 #include "block/aio.h"
28 #include "qemu/main-loop.h"
30 #define _(x) x /* not gettext support yet */
32 /* from libxcmd/command.c */
34 #define EXABYTES(x) ((long long)(x) << 60)
35 #define PETABYTES(x) ((long long)(x) << 50)
36 #define TERABYTES(x) ((long long)(x) << 40)
37 #define GIGABYTES(x) ((long long)(x) << 30)
38 #define MEGABYTES(x) ((long long)(x) << 20)
39 #define KILOBYTES(x) ((long long)(x) << 10)
41 #define TO_EXABYTES(x) ((x) / EXABYTES(1))
42 #define TO_PETABYTES(x) ((x) / PETABYTES(1))
43 #define TO_TERABYTES(x) ((x) / TERABYTES(1))
44 #define TO_GIGABYTES(x) ((x) / GIGABYTES(1))
45 #define TO_MEGABYTES(x) ((x) / MEGABYTES(1))
46 #define TO_KILOBYTES(x) ((x) / KILOBYTES(1))
57 if (value
>= EXABYTES(1)) {
59 snprintf(str
, size
- 4, "%.3f", TO_EXABYTES(value
));
60 } else if (value
>= PETABYTES(1)) {
62 snprintf(str
, size
- 4, "%.3f", TO_PETABYTES(value
));
63 } else if (value
>= TERABYTES(1)) {
65 snprintf(str
, size
- 4, "%.3f", TO_TERABYTES(value
));
66 } else if (value
>= GIGABYTES(1)) {
68 snprintf(str
, size
- 4, "%.3f", TO_GIGABYTES(value
));
69 } else if (value
>= MEGABYTES(1)) {
71 snprintf(str
, size
- 4, "%.3f", TO_MEGABYTES(value
));
72 } else if (value
>= KILOBYTES(1)) {
74 snprintf(str
, size
- 4, "%.3f", TO_KILOBYTES(value
));
77 snprintf(str
, size
- 6, "%f", value
);
80 trim
= strstr(str
, ".000");
89 tsub(struct timeval t1
, struct timeval t2
)
91 t1
.tv_usec
-= t2
.tv_usec
;
93 t1
.tv_usec
+= 1000000;
96 t1
.tv_sec
-= t2
.tv_sec
;
101 tdiv(double value
, struct timeval tv
)
103 return value
/ ((double)tv
.tv_sec
+ ((double)tv
.tv_usec
/ 1000000.0));
106 #define HOURS(sec) ((sec) / (60 * 60))
107 #define MINUTES(sec) (((sec) % (60 * 60)) / 60)
108 #define SECONDS(sec) ((sec) % 60)
117 double usec
= (double)tv
->tv_usec
/ 1000000.0;
119 if (format
& TERSE_FIXED_TIME
) {
120 if (!HOURS(tv
->tv_sec
)) {
121 snprintf(ts
, size
, "%u:%02u.%02u",
122 (unsigned int) MINUTES(tv
->tv_sec
),
123 (unsigned int) SECONDS(tv
->tv_sec
),
124 (unsigned int) (usec
* 100));
127 format
|= VERBOSE_FIXED_TIME
; /* fallback if hours needed */
130 if ((format
& VERBOSE_FIXED_TIME
) || tv
->tv_sec
) {
131 snprintf(ts
, size
, "%u:%02u:%02u.%02u",
132 (unsigned int) HOURS(tv
->tv_sec
),
133 (unsigned int) MINUTES(tv
->tv_sec
),
134 (unsigned int) SECONDS(tv
->tv_sec
),
135 (unsigned int) (usec
* 100));
137 snprintf(ts
, size
, "0.%04u sec", (unsigned int) (usec
* 10000));