| 1 |
|
/* |
| 2 |
< |
* i-scream central monitoring system |
| 2 |
> |
* i-scream libstatgrab |
| 3 |
|
* http://www.i-scream.org |
| 4 |
|
* Copyright (C) 2000-2004 i-scream |
| 5 |
|
* |
| 33 |
|
|
| 34 |
|
typedef enum { |
| 35 |
|
LONG_LONG = 0, |
| 36 |
+ |
BYTES, |
| 37 |
|
TIME_T, |
| 38 |
|
FLOAT, |
| 39 |
|
DOUBLE, |
| 72 |
|
int repeat_time = 1; |
| 73 |
|
int use_cpu_percent = 0; |
| 74 |
|
int use_diffs = 0; |
| 75 |
+ |
long float_scale_factor = 0; |
| 76 |
+ |
long long bytes_scale_factor = 0; |
| 77 |
|
|
| 78 |
|
/* Exit with an error message. */ |
| 79 |
|
void die(const char *s) { |
| 169 |
|
|
| 170 |
|
void populate_cpu() { |
| 171 |
|
if (use_cpu_percent) { |
| 172 |
< |
cpu_percent_t *cpu_p = cpu_percent_usage(); |
| 172 |
> |
sg_cpu_percents *cpu_p = sg_get_cpu_percents(); |
| 173 |
|
|
| 174 |
|
if (cpu_p != NULL) { |
| 175 |
|
add_stat(FLOAT, &cpu_p->user, |
| 176 |
< |
"cpu", "user", NULL); |
| 176 |
> |
"cpu", "user", NULL); |
| 177 |
|
add_stat(FLOAT, &cpu_p->kernel, |
| 178 |
< |
"cpu", "kernel", NULL); |
| 178 |
> |
"cpu", "kernel", NULL); |
| 179 |
|
add_stat(FLOAT, &cpu_p->idle, |
| 180 |
< |
"cpu", "idle", NULL); |
| 180 |
> |
"cpu", "idle", NULL); |
| 181 |
|
add_stat(FLOAT, &cpu_p->iowait, |
| 182 |
< |
"cpu", "iowait", NULL); |
| 182 |
> |
"cpu", "iowait", NULL); |
| 183 |
|
add_stat(FLOAT, &cpu_p->swap, |
| 184 |
< |
"cpu", "swap", NULL); |
| 184 |
> |
"cpu", "swap", NULL); |
| 185 |
|
add_stat(FLOAT, &cpu_p->nice, |
| 186 |
< |
"cpu", "nice", NULL); |
| 186 |
> |
"cpu", "nice", NULL); |
| 187 |
|
add_stat(TIME_T, &cpu_p->time_taken, |
| 188 |
< |
"cpu", "time_taken", NULL); |
| 188 |
> |
"cpu", "time_taken", NULL); |
| 189 |
|
} |
| 190 |
|
} else { |
| 191 |
< |
cpu_states_t *cpu_s; |
| 191 |
> |
sg_cpu_stats *cpu_s; |
| 192 |
|
|
| 193 |
< |
cpu_s = use_diffs ? get_cpu_diff() : get_cpu_totals(); |
| 193 |
> |
cpu_s = use_diffs ? sg_get_cpu_stats_diff() |
| 194 |
> |
: sg_get_cpu_stats(); |
| 195 |
|
if (cpu_s != NULL) { |
| 196 |
|
add_stat(LONG_LONG, &cpu_s->user, |
| 197 |
< |
"cpu", "user", NULL); |
| 197 |
> |
"cpu", "user", NULL); |
| 198 |
|
add_stat(LONG_LONG, &cpu_s->kernel, |
| 199 |
< |
"cpu", "kernel", NULL); |
| 199 |
> |
"cpu", "kernel", NULL); |
| 200 |
|
add_stat(LONG_LONG, &cpu_s->idle, |
| 201 |
< |
"cpu", "idle", NULL); |
| 201 |
> |
"cpu", "idle", NULL); |
| 202 |
|
add_stat(LONG_LONG, &cpu_s->iowait, |
| 203 |
< |
"cpu", "iowait", NULL); |
| 203 |
> |
"cpu", "iowait", NULL); |
| 204 |
|
add_stat(LONG_LONG, &cpu_s->swap, |
| 205 |
< |
"cpu", "swap", NULL); |
| 205 |
> |
"cpu", "swap", NULL); |
| 206 |
|
add_stat(LONG_LONG, &cpu_s->nice, |
| 207 |
< |
"cpu", "nice", NULL); |
| 207 |
> |
"cpu", "nice", NULL); |
| 208 |
|
add_stat(LONG_LONG, &cpu_s->total, |
| 209 |
< |
"cpu", "total", NULL); |
| 209 |
> |
"cpu", "total", NULL); |
| 210 |
|
add_stat(TIME_T, &cpu_s->systime, |
| 211 |
< |
"cpu", "systime", NULL); |
| 211 |
> |
"cpu", "systime", NULL); |
| 212 |
|
} |
| 213 |
|
} |
| 214 |
|
} |
| 215 |
|
|
| 216 |
|
void populate_mem() { |
| 217 |
< |
mem_stat_t *mem = get_memory_stats(); |
| 217 |
> |
sg_mem_stats *mem = sg_get_mem_stats(); |
| 218 |
|
|
| 219 |
|
if (mem != NULL) { |
| 220 |
< |
add_stat(LONG_LONG, &mem->total, "mem", "total", NULL); |
| 221 |
< |
add_stat(LONG_LONG, &mem->free, "mem", "free", NULL); |
| 222 |
< |
add_stat(LONG_LONG, &mem->used, "mem", "used", NULL); |
| 223 |
< |
add_stat(LONG_LONG, &mem->cache, "mem", "cache", NULL); |
| 220 |
> |
add_stat(BYTES, &mem->total, "mem", "total", NULL); |
| 221 |
> |
add_stat(BYTES, &mem->free, "mem", "free", NULL); |
| 222 |
> |
add_stat(BYTES, &mem->used, "mem", "used", NULL); |
| 223 |
> |
add_stat(BYTES, &mem->cache, "mem", "cache", NULL); |
| 224 |
|
} |
| 225 |
|
} |
| 226 |
|
|
| 227 |
|
void populate_load() { |
| 228 |
< |
load_stat_t *load = get_load_stats(); |
| 228 |
> |
sg_load_stats *load = sg_get_load_stats(); |
| 229 |
|
|
| 230 |
|
if (load != NULL) { |
| 231 |
|
add_stat(DOUBLE, &load->min1, "load", "min1", NULL); |
| 235 |
|
} |
| 236 |
|
|
| 237 |
|
void populate_user() { |
| 238 |
< |
user_stat_t *user = get_user_stats(); |
| 238 |
> |
sg_user_stats *user = sg_get_user_stats(); |
| 239 |
|
|
| 240 |
|
if (user != NULL) { |
| 241 |
|
add_stat(INT, &user->num_entries, "user", "num", NULL); |
| 244 |
|
} |
| 245 |
|
|
| 246 |
|
void populate_swap() { |
| 247 |
< |
swap_stat_t *swap = get_swap_stats(); |
| 247 |
> |
sg_swap_stats *swap = sg_get_swap_stats(); |
| 248 |
|
|
| 249 |
|
if (swap != NULL) { |
| 250 |
< |
add_stat(LONG_LONG, &swap->total, "swap", "total", NULL); |
| 251 |
< |
add_stat(LONG_LONG, &swap->used, "swap", "used", NULL); |
| 252 |
< |
add_stat(LONG_LONG, &swap->free, "swap", "free", NULL); |
| 250 |
> |
add_stat(BYTES, &swap->total, "swap", "total", NULL); |
| 251 |
> |
add_stat(BYTES, &swap->used, "swap", "used", NULL); |
| 252 |
> |
add_stat(BYTES, &swap->free, "swap", "free", NULL); |
| 253 |
|
} |
| 254 |
|
} |
| 255 |
|
|
| 256 |
|
void populate_general() { |
| 257 |
< |
general_stat_t *gen = get_general_stats(); |
| 257 |
> |
/* FIXME this should be renamed to host. */ |
| 258 |
> |
sg_host_info *host = sg_get_host_info(); |
| 259 |
|
|
| 260 |
< |
if (gen != NULL) { |
| 261 |
< |
add_stat(STRING, &gen->os_name, |
| 262 |
< |
"general", "os_name", NULL); |
| 263 |
< |
add_stat(STRING, &gen->os_release, |
| 264 |
< |
"general", "os_release", NULL); |
| 265 |
< |
add_stat(STRING, &gen->os_version, |
| 266 |
< |
"general", "os_version", NULL); |
| 267 |
< |
add_stat(STRING, &gen->platform, "general", "platform", NULL); |
| 268 |
< |
add_stat(STRING, &gen->hostname, "general", "hostname", NULL); |
| 269 |
< |
add_stat(TIME_T, &gen->uptime, "general", "uptime", NULL); |
| 260 |
> |
if (host != NULL) { |
| 261 |
> |
add_stat(STRING, &host->os_name, |
| 262 |
> |
"general", "os_name", NULL); |
| 263 |
> |
add_stat(STRING, &host->os_release, |
| 264 |
> |
"general", "os_release", NULL); |
| 265 |
> |
add_stat(STRING, &host->os_version, |
| 266 |
> |
"general", "os_version", NULL); |
| 267 |
> |
add_stat(STRING, &host->platform, "general", "platform", NULL); |
| 268 |
> |
add_stat(STRING, &host->hostname, "general", "hostname", NULL); |
| 269 |
> |
add_stat(TIME_T, &host->uptime, "general", "uptime", NULL); |
| 270 |
|
} |
| 271 |
|
} |
| 272 |
|
|
| 273 |
|
void populate_fs() { |
| 274 |
|
int n, i; |
| 275 |
< |
disk_stat_t *disk = get_disk_stats(&n); |
| 275 |
> |
sg_fs_stats *disk = sg_get_fs_stats(&n); |
| 276 |
|
|
| 277 |
|
if (disk != NULL) { |
| 278 |
|
for (i = 0; i < n; i++) { |
| 296 |
|
*p = '_'; |
| 297 |
|
|
| 298 |
|
add_stat(STRING, &disk[i].device_name, |
| 299 |
< |
"fs", name, "device_name", NULL); |
| 299 |
> |
"fs", name, "device_name", NULL); |
| 300 |
|
add_stat(STRING, &disk[i].fs_type, |
| 301 |
< |
"fs", name, "fs_type", NULL); |
| 301 |
> |
"fs", name, "fs_type", NULL); |
| 302 |
|
add_stat(STRING, &disk[i].mnt_point, |
| 303 |
< |
"fs", name, "mnt_point", NULL); |
| 304 |
< |
add_stat(LONG_LONG, &disk[i].size, |
| 305 |
< |
"fs", name, "size", NULL); |
| 306 |
< |
add_stat(LONG_LONG, &disk[i].used, |
| 307 |
< |
"fs", name, "used", NULL); |
| 308 |
< |
add_stat(LONG_LONG, &disk[i].avail, |
| 309 |
< |
"fs", name, "avail", NULL); |
| 303 |
> |
"fs", name, "mnt_point", NULL); |
| 304 |
> |
add_stat(BYTES, &disk[i].size, |
| 305 |
> |
"fs", name, "size", NULL); |
| 306 |
> |
add_stat(BYTES, &disk[i].used, |
| 307 |
> |
"fs", name, "used", NULL); |
| 308 |
> |
add_stat(BYTES, &disk[i].avail, |
| 309 |
> |
"fs", name, "avail", NULL); |
| 310 |
|
add_stat(LONG_LONG, &disk[i].total_inodes, |
| 311 |
< |
"fs", name, "total_inodes", NULL); |
| 311 |
> |
"fs", name, "total_inodes", NULL); |
| 312 |
|
add_stat(LONG_LONG, &disk[i].used_inodes, |
| 313 |
< |
"fs", name, "used_inodes", NULL); |
| 313 |
> |
"fs", name, "used_inodes", NULL); |
| 314 |
|
add_stat(LONG_LONG, &disk[i].free_inodes, |
| 315 |
< |
"fs", name, "free_inodes", NULL); |
| 315 |
> |
"fs", name, "free_inodes", NULL); |
| 316 |
|
|
| 317 |
|
free(buf); |
| 318 |
|
} |
| 321 |
|
|
| 322 |
|
void populate_disk() { |
| 323 |
|
int n, i; |
| 324 |
< |
diskio_stat_t *diskio; |
| 324 |
> |
sg_disk_io_stats *diskio; |
| 325 |
|
|
| 326 |
< |
diskio = use_diffs ? get_diskio_stats_diff(&n) : get_diskio_stats(&n); |
| 326 |
> |
diskio = use_diffs ? sg_get_disk_io_stats_diff(&n) |
| 327 |
> |
: sg_get_disk_io_stats(&n); |
| 328 |
|
if (diskio != NULL) { |
| 329 |
|
for (i = 0; i < n; i++) { |
| 330 |
|
const char *name = diskio[i].disk_name; |
| 331 |
|
|
| 332 |
|
add_stat(STRING, &diskio[i].disk_name, |
| 333 |
< |
"disk", name, "disk_name", NULL); |
| 334 |
< |
add_stat(LONG_LONG, &diskio[i].read_bytes, |
| 335 |
< |
"disk", name, "read_bytes", NULL); |
| 336 |
< |
add_stat(LONG_LONG, &diskio[i].write_bytes, |
| 337 |
< |
"disk", name, "write_bytes", NULL); |
| 333 |
> |
"disk", name, "disk_name", NULL); |
| 334 |
> |
add_stat(BYTES, &diskio[i].read_bytes, |
| 335 |
> |
"disk", name, "read_bytes", NULL); |
| 336 |
> |
add_stat(BYTES, &diskio[i].write_bytes, |
| 337 |
> |
"disk", name, "write_bytes", NULL); |
| 338 |
|
add_stat(TIME_T, &diskio[i].systime, |
| 339 |
< |
"disk", name, "systime", NULL); |
| 339 |
> |
"disk", name, "systime", NULL); |
| 340 |
|
} |
| 341 |
|
} |
| 342 |
|
} |
| 343 |
|
|
| 344 |
|
void populate_proc() { |
| 345 |
< |
process_stat_t *proc = get_process_stats(); |
| 345 |
> |
/* FIXME expose individual process info too */ |
| 346 |
> |
sg_process_count *proc = sg_get_process_count(); |
| 347 |
|
|
| 348 |
|
if (proc != NULL) { |
| 349 |
|
add_stat(INT, &proc->total, "proc", "total", NULL); |
| 355 |
|
} |
| 356 |
|
|
| 357 |
|
void populate_net() { |
| 358 |
< |
int n, i; |
| 359 |
< |
network_stat_t *net; |
| 360 |
< |
network_iface_stat_t *iface; |
| 358 |
> |
int num_io, num_iface, i; |
| 359 |
> |
sg_network_io_stats *io; |
| 360 |
> |
sg_network_iface_stats *iface; |
| 361 |
|
|
| 362 |
< |
net = use_diffs ? get_network_stats_diff(&n) : get_network_stats(&n); |
| 363 |
< |
if (net != NULL) { |
| 364 |
< |
for (i = 0; i < n; i++) { |
| 365 |
< |
const char *name = net[i].interface_name; |
| 362 |
> |
io = use_diffs ? sg_get_network_io_stats_diff(&num_io) |
| 363 |
> |
: sg_get_network_io_stats(&num_io); |
| 364 |
> |
if (io != NULL) { |
| 365 |
> |
for (i = 0; i < num_io; i++) { |
| 366 |
> |
const char *name = io[i].interface_name; |
| 367 |
|
|
| 368 |
< |
add_stat(STRING, &net[i].interface_name, |
| 369 |
< |
"net", name, "interface_name", NULL); |
| 370 |
< |
add_stat(LONG_LONG, &net[i].tx, |
| 371 |
< |
"net", name, "tx", NULL); |
| 372 |
< |
add_stat(LONG_LONG, &net[i].rx, |
| 373 |
< |
"net", name, "rx", NULL); |
| 374 |
< |
add_stat(LONG_LONG, &net[i].ipackets, |
| 375 |
< |
"net", name, "ipackets", NULL); |
| 376 |
< |
add_stat(LONG_LONG, &net[i].opackets, |
| 377 |
< |
"net", name, "opackets", NULL); |
| 378 |
< |
add_stat(LONG_LONG, &net[i].ierrors, |
| 379 |
< |
"net", name, "ierrors", NULL); |
| 380 |
< |
add_stat(LONG_LONG, &net[i].oerrors, |
| 381 |
< |
"net", name, "oerrors", NULL); |
| 382 |
< |
add_stat(LONG_LONG, &net[i].collisions, |
| 383 |
< |
"net", name, "collisions", NULL); |
| 384 |
< |
add_stat(TIME_T, &net[i].systime, |
| 385 |
< |
"net", name, "systime", NULL); |
| 368 |
> |
add_stat(STRING, &io[i].interface_name, |
| 369 |
> |
"net", name, "interface_name", NULL); |
| 370 |
> |
add_stat(BYTES, &io[i].tx, |
| 371 |
> |
"net", name, "tx", NULL); |
| 372 |
> |
add_stat(BYTES, &io[i].rx, |
| 373 |
> |
"net", name, "rx", NULL); |
| 374 |
> |
add_stat(LONG_LONG, &io[i].ipackets, |
| 375 |
> |
"net", name, "ipackets", NULL); |
| 376 |
> |
add_stat(LONG_LONG, &io[i].opackets, |
| 377 |
> |
"net", name, "opackets", NULL); |
| 378 |
> |
add_stat(LONG_LONG, &io[i].ierrors, |
| 379 |
> |
"net", name, "ierrors", NULL); |
| 380 |
> |
add_stat(LONG_LONG, &io[i].oerrors, |
| 381 |
> |
"net", name, "oerrors", NULL); |
| 382 |
> |
add_stat(LONG_LONG, &io[i].collisions, |
| 383 |
> |
"net", name, "collisions", NULL); |
| 384 |
> |
add_stat(TIME_T, &io[i].systime, |
| 385 |
> |
"net", name, "systime", NULL); |
| 386 |
|
} |
| 387 |
|
} |
| 388 |
|
|
| 389 |
< |
iface = get_network_iface_stats(&n); |
| 389 |
> |
iface = sg_get_network_iface_stats(&num_iface); |
| 390 |
|
if (iface != NULL) { |
| 391 |
< |
for (i = 0; i < n; i++) { |
| 391 |
> |
for (i = 0; i < num_iface; i++) { |
| 392 |
|
const char *name = iface[i].interface_name; |
| 393 |
+ |
int had_io = 0, j; |
| 394 |
|
|
| 395 |
+ |
/* If there wasn't a corresponding io stat, |
| 396 |
+ |
add interface_name from here. */ |
| 397 |
+ |
if (io != NULL) { |
| 398 |
+ |
for (j = 0; j < num_io; j++) { |
| 399 |
+ |
if (strcmp(io[j].interface_name, |
| 400 |
+ |
name) == 0) { |
| 401 |
+ |
had_io = 1; |
| 402 |
+ |
break; |
| 403 |
+ |
} |
| 404 |
+ |
} |
| 405 |
+ |
} |
| 406 |
+ |
if (!had_io) { |
| 407 |
+ |
add_stat(STRING, &iface[i].interface_name, |
| 408 |
+ |
"net", name, "interface_name", NULL); |
| 409 |
+ |
} |
| 410 |
+ |
|
| 411 |
|
add_stat(INT, &iface[i].speed, |
| 412 |
< |
"net", name, "speed", NULL); |
| 412 |
> |
"net", name, "speed", NULL); |
| 413 |
|
add_stat(BOOL, &iface[i].up, |
| 414 |
< |
"net", name, "up", NULL); |
| 415 |
< |
add_stat(DUPLEX, &iface[i].dup, |
| 416 |
< |
"net", name, "duplex", NULL); |
| 414 |
> |
"net", name, "up", NULL); |
| 415 |
> |
add_stat(DUPLEX, &iface[i].duplex, |
| 416 |
> |
"net", name, "duplex", NULL); |
| 417 |
|
} |
| 418 |
|
} |
| 419 |
|
} |
| 420 |
|
|
| 421 |
|
void populate_page() { |
| 422 |
< |
page_stat_t *page; |
| 422 |
> |
sg_page_stats *page; |
| 423 |
|
|
| 424 |
< |
page = use_diffs ? get_page_stats_diff() : get_page_stats(); |
| 424 |
> |
page = use_diffs ? sg_get_page_stats_diff() : sg_get_page_stats(); |
| 425 |
|
if (page != NULL) { |
| 426 |
|
add_stat(LONG_LONG, &page->pages_pagein, "page", "in", NULL); |
| 427 |
|
add_stat(LONG_LONG, &page->pages_pageout, "page", "out", NULL); |
| 464 |
|
for (i = 0; i < argc; i++) { |
| 465 |
|
for (t = &toplevels[0]; t->name != NULL; t++) { |
| 466 |
|
if (strncmp(argv[i], t->name, |
| 467 |
< |
strlen(t->name)) == 0) { |
| 467 |
> |
strlen(t->name)) == 0) { |
| 468 |
|
t->interesting = 1; |
| 469 |
|
break; |
| 470 |
|
} |
| 491 |
|
/* Print the value of a stat. */ |
| 492 |
|
void print_stat_value(const stat *s) { |
| 493 |
|
void *v = s->stat; |
| 494 |
< |
long l; |
| 494 |
> |
double fv; |
| 495 |
> |
long lv; |
| 496 |
> |
long long llv; |
| 497 |
|
|
| 498 |
|
switch (s->type) { |
| 499 |
|
case LONG_LONG: |
| 500 |
|
printf("%lld", *(long long *)v); |
| 501 |
|
break; |
| 502 |
+ |
case BYTES: |
| 503 |
+ |
llv = *(long long *)v; |
| 504 |
+ |
if (bytes_scale_factor != 0) { |
| 505 |
+ |
llv /= bytes_scale_factor; |
| 506 |
+ |
} |
| 507 |
+ |
printf("%lld", llv); |
| 508 |
+ |
break; |
| 509 |
|
case TIME_T: |
| 510 |
|
/* FIXME option for formatted time? */ |
| 511 |
< |
l = *(time_t *)v; |
| 512 |
< |
printf("%ld", l); |
| 511 |
> |
lv = *(time_t *)v; |
| 512 |
> |
printf("%ld", lv); |
| 513 |
|
break; |
| 514 |
|
case FLOAT: |
| 481 |
– |
printf("%f", *(float *)v); |
| 482 |
– |
break; |
| 515 |
|
case DOUBLE: |
| 516 |
< |
printf("%f", *(double *)v); |
| 516 |
> |
if (s->type == FLOAT) { |
| 517 |
> |
fv = *(float *)v; |
| 518 |
> |
} else { |
| 519 |
> |
fv = *(double *)v; |
| 520 |
> |
} |
| 521 |
> |
if (float_scale_factor != 0) { |
| 522 |
> |
printf("%ld", (long)(float_scale_factor * fv)); |
| 523 |
> |
} else { |
| 524 |
> |
printf("%f", fv); |
| 525 |
> |
} |
| 526 |
|
break; |
| 527 |
|
case STRING: |
| 528 |
|
/* FIXME escaping? */ |
| 535 |
|
printf("%s", *(int *)v ? "true" : "false"); |
| 536 |
|
break; |
| 537 |
|
case DUPLEX: |
| 538 |
< |
switch (*(statgrab_duplex *) v) { |
| 539 |
< |
case FULL_DUPLEX: |
| 538 |
> |
switch (*(sg_iface_duplex *) v) { |
| 539 |
> |
case SG_IFACE_DUPLEX_FULL: |
| 540 |
|
printf("full"); |
| 541 |
|
break; |
| 542 |
< |
case HALF_DUPLEX: |
| 542 |
> |
case SG_IFACE_DUPLEX_HALF: |
| 543 |
|
printf("half"); |
| 544 |
|
break; |
| 545 |
|
default: |
| 593 |
|
s = NULL; |
| 594 |
|
} else { |
| 595 |
|
s = (const stat *)bsearch(&key, stats, |
| 596 |
< |
num_stats, |
| 597 |
< |
sizeof *stats, |
| 598 |
< |
compare); |
| 596 |
> |
num_stats, |
| 597 |
> |
sizeof *stats, |
| 598 |
> |
compare); |
| 599 |
|
} |
| 600 |
|
|
| 601 |
|
if (s == NULL) { |
| 639 |
|
" -t DELAY When repeating, wait DELAY seconds between updates (default 1)\n" |
| 640 |
|
" -p Display CPU usage differences as percentages rather than\n" |
| 641 |
|
" absolute values\n" |
| 642 |
+ |
" -f FACTOR Display floating-point values as integers scaled by FACTOR\n" |
| 643 |
+ |
" -K Display byte counts in kibibytes\n" |
| 644 |
+ |
" -M Display byte counts in mebibytes\n" |
| 645 |
+ |
" -G Display byte counts in gibibytes\n" |
| 646 |
|
"\n"); |
| 647 |
|
printf("Version %s - report bugs to <%s>.\n", |
| 648 |
|
PACKAGE_VERSION, PACKAGE_BUGREPORT); |
| 652 |
|
int main(int argc, char **argv) { |
| 653 |
|
opterr = 0; |
| 654 |
|
while (1) { |
| 655 |
< |
int c = getopt(argc, argv, "lbmunsot:p"); |
| 655 |
> |
int c = getopt(argc, argv, "lbmunsot:pf:KMG"); |
| 656 |
|
if (c == -1) |
| 657 |
|
break; |
| 658 |
|
switch (c) { |
| 683 |
|
case 'p': |
| 684 |
|
use_cpu_percent = 1; |
| 685 |
|
break; |
| 686 |
+ |
case 'f': |
| 687 |
+ |
float_scale_factor = atol(optarg); |
| 688 |
+ |
break; |
| 689 |
+ |
case 'K': |
| 690 |
+ |
bytes_scale_factor = 1024; |
| 691 |
+ |
break; |
| 692 |
+ |
case 'M': |
| 693 |
+ |
bytes_scale_factor = 1024 * 1024; |
| 694 |
+ |
break; |
| 695 |
+ |
case 'G': |
| 696 |
+ |
bytes_scale_factor = 1024 * 1024 * 1024; |
| 697 |
+ |
break; |
| 698 |
|
default: |
| 699 |
|
usage(); |
| 700 |
|
} |
| 717 |
|
|
| 718 |
|
select_interesting(argc - optind, &argv[optind]); |
| 719 |
|
|
| 720 |
< |
/* We don't care if statgrab_init fails, because we can just display |
| 720 |
> |
/* We don't care if sg_init fails, because we can just display |
| 721 |
|
the statistics that can be read as non-root. */ |
| 722 |
< |
statgrab_init(); |
| 723 |
< |
if (statgrab_drop_privileges() != 0) |
| 722 |
> |
sg_init(); |
| 723 |
> |
if (sg_drop_privileges() != 0) |
| 724 |
|
die("Failed to drop setuid/setgid privileges"); |
| 725 |
|
|
| 726 |
|
switch (repeat_mode) { |