|
| File utc.patch,
7.1 KB
(added by human, 2 years ago) |
|
Add --utc option to rrd graph
|
-
|
|
|
|
| 26 | 26 | #endif |
| 27 | 27 | |
| 28 | 28 | #include <time.h> |
| | 29 | #define LOCALTIME_R(a,b,c) (c ? gmtime_r(a,b) : localtime_r(a,b)) |
| | 30 | #define MKTIME(a,b) (b ? timegm(a) : mktime(a)) |
| 29 | 31 | |
| 30 | 32 | #include <locale.h> |
| 31 | 33 | |
| … |
… |
|
| 1381 | 1383 | time_t find_first_time( |
| 1382 | 1384 | time_t start, /* what is the initial time */ |
| 1383 | 1385 | enum tmt_en baseint, /* what is the basic interval */ |
| 1384 | | long basestep /* how many if these do we jump a time */ |
| | 1386 | long basestep, /* how many of these do we jump a time */ |
| | 1387 | int utc |
| 1385 | 1388 | ) |
| 1386 | 1389 | { |
| 1387 | 1390 | struct tm tm; |
| 1388 | 1391 | |
| 1389 | | localtime_r(&start, &tm); |
| | 1392 | LOCALTIME_R(&start, &tm, utc); |
| 1390 | 1393 | |
| 1391 | 1394 | switch (baseint) { |
| 1392 | 1395 | case TMT_SECOND: |
| … |
… |
|
| 1441 | 1444 | tm.tm_year + 1900) %basestep; |
| 1442 | 1445 | |
| 1443 | 1446 | } |
| 1444 | | return mktime(&tm); |
| | 1447 | return MKTIME(&tm, utc); |
| 1445 | 1448 | } |
| 1446 | 1449 | |
| 1447 | 1450 | /* identify the point where the next gridline, label ... gets placed */ |
| 1448 | 1451 | time_t find_next_time( |
| 1449 | 1452 | time_t current, /* what is the initial time */ |
| 1450 | 1453 | enum tmt_en baseint, /* what is the basic interval */ |
| 1451 | | long basestep /* how many if these do we jump a time */ |
| | 1454 | long basestep, /* how many of these do we jump a time */ |
| | 1455 | int utc |
| 1452 | 1456 | ) |
| 1453 | 1457 | { |
| 1454 | 1458 | struct tm tm; |
| 1455 | 1459 | time_t madetime; |
| 1456 | 1460 | |
| 1457 | | localtime_r(¤t, &tm); |
| | 1461 | LOCALTIME_R(¤t, &tm, utc); |
| 1458 | 1462 | |
| 1459 | 1463 | do { |
| 1460 | 1464 | switch (baseint) { |
| … |
… |
|
| 1485 | 1489 | case TMT_YEAR: |
| 1486 | 1490 | tm. tm_year += basestep; |
| 1487 | 1491 | } |
| 1488 | | madetime = mktime(&tm); |
| | 1492 | madetime = MKTIME(&tm, utc); |
| 1489 | 1493 | } while (madetime == -1); /* this is necessary to skip impssible times |
| 1490 | 1494 | like the daylight saving time skips */ |
| 1491 | 1495 | return madetime; |
| … |
… |
|
| 1512 | 1516 | /* wow initializing tmvdef is quite a task :-) */ |
| 1513 | 1517 | time_t now = time(NULL); |
| 1514 | 1518 | |
| 1515 | | localtime_r(&now, &tmvdef); |
| | 1519 | LOCALTIME_R(&now, &tmvdef, im->extra_flags & FORCE_UTC_TIME); |
| 1516 | 1520 | for (i = 0; i < im->gdes_c; i++) { |
| 1517 | 1521 | vidx = im->gdes[i].vidx; |
| 1518 | 1522 | switch (im->gdes[i].gf) { |
| … |
… |
|
| 1524 | 1528 | */ |
| 1525 | 1529 | if (im->gdes[vidx].gf == GF_VDEF) { /* simply use vals */ |
| 1526 | 1530 | printval = im->gdes[vidx].vf.val; |
| 1527 | | localtime_r(&im->gdes[vidx].vf.when, &tmvdef); |
| | 1531 | LOCALTIME_R(&im->gdes[vidx].vf.when, &tmvdef, im->extra_flags & FORCE_UTC_TIME); |
| 1528 | 1532 | } else { /* need to calculate max,min,avg etcetera */ |
| 1529 | 1533 | max_ii = ((im->gdes[vidx].end - im->gdes[vidx].start) |
| 1530 | 1534 | / im->gdes[vidx].step * im->gdes[vidx].ds_cnt); |
| … |
… |
|
| 2476 | 2480 | gridtm, |
| 2477 | 2481 | im-> |
| 2478 | 2482 | xlab_user. |
| 2479 | | gridst), |
| | 2483 | gridst, |
| | 2484 | im->extra_flags & FORCE_UTC_TIME), |
| 2480 | 2485 | timajor = |
| 2481 | 2486 | find_first_time(im->start, |
| 2482 | 2487 | im->xlab_user. |
| 2483 | 2488 | mgridtm, |
| 2484 | 2489 | im->xlab_user. |
| 2485 | | mgridst); |
| | 2490 | mgridst, |
| | 2491 | im->extra_flags & FORCE_UTC_TIME); |
| 2486 | 2492 | ti < im->end; |
| 2487 | 2493 | ti = |
| 2488 | | find_next_time(ti, im->xlab_user.gridtm, im->xlab_user.gridst) |
| | 2494 | find_next_time(ti, im->xlab_user.gridtm, im->xlab_user.gridst, im->extra_flags & FORCE_UTC_TIME) |
| 2489 | 2495 | ) { |
| 2490 | 2496 | /* are we inside the graph ? */ |
| 2491 | 2497 | if (ti < im->start || ti > im->end) |
| … |
… |
|
| 2494 | 2500 | timajor = find_next_time(timajor, |
| 2495 | 2501 | im-> |
| 2496 | 2502 | xlab_user. |
| 2497 | | mgridtm, im->xlab_user.mgridst); |
| | 2503 | mgridtm, im->xlab_user.mgridst, |
| | 2504 | im->extra_flags & FORCE_UTC_TIME); |
| 2498 | 2505 | } |
| 2499 | 2506 | if (ti == timajor) |
| 2500 | 2507 | continue; /* skip as falls on major grid line */ |
| … |
… |
|
| 2518 | 2525 | mgridtm, |
| 2519 | 2526 | im-> |
| 2520 | 2527 | xlab_user. |
| 2521 | | mgridst); |
| | 2528 | mgridst, |
| | 2529 | im->extra_flags & FORCE_UTC_TIME); |
| 2522 | 2530 | ti < im->end; |
| 2523 | | ti = find_next_time(ti, im->xlab_user.mgridtm, im->xlab_user.mgridst) |
| | 2531 | ti = find_next_time(ti, im->xlab_user.mgridtm, im->xlab_user.mgridst, im->extra_flags & FORCE_UTC_TIME) |
| 2524 | 2532 | ) { |
| 2525 | 2533 | /* are we inside the graph ? */ |
| 2526 | 2534 | if (ti < im->start || ti > im->end) |
| … |
… |
|
| 2544 | 2552 | im->xlab_user. |
| 2545 | 2553 | labtm, |
| 2546 | 2554 | im->xlab_user. |
| 2547 | | labst); |
| | 2555 | labst, |
| | 2556 | im->extra_flags & FORCE_UTC_TIME); |
| 2548 | 2557 | ti <= |
| 2549 | 2558 | im->end - |
| 2550 | 2559 | im->xlab_user.precis / 2; |
| 2551 | | ti = find_next_time(ti, im->xlab_user.labtm, im->xlab_user.labst) |
| | 2560 | ti = find_next_time(ti, im->xlab_user.labtm, im->xlab_user.labst, im->extra_flags & FORCE_UTC_TIME) |
| 2552 | 2561 | ) { |
| 2553 | 2562 | tilab = ti + im->xlab_user.precis / 2; /* correct time for the label */ |
| 2554 | 2563 | /* are we inside the graph ? */ |
| 2555 | 2564 | if (tilab < im->start || tilab > im->end) |
| 2556 | 2565 | continue; |
| 2557 | 2566 | #if HAVE_STRFTIME |
| 2558 | | localtime_r(&tilab, &tm); |
| | 2567 | LOCALTIME_R(&tilab, &tm, im->extra_flags & FORCE_UTC_TIME); |
| 2559 | 2568 | strftime(graph_label, 99, im->xlab_user.stst, &tm); |
| 2560 | 2569 | #else |
| 2561 | 2570 | # error "your libc has no strftime I guess we'll abort the exercise here." |
| … |
… |
|
| 4202 | 4211 | { "border", required_argument, 0, 1007}, |
| 4203 | 4212 | { "grid-dash", required_argument, 0, 1008}, |
| 4204 | 4213 | { "dynamic-labels", no_argument, 0, 1009}, |
| | 4214 | { "utc", no_argument, 0, 1010}, |
| 4205 | 4215 | { 0, 0, 0, 0} |
| 4206 | 4216 | }; |
| 4207 | 4217 | /* *INDENT-ON* */ |
| … |
… |
|
| 4272 | 4282 | case 1001: |
| 4273 | 4283 | im->extra_flags |= NO_RRDTOOL_TAG; |
| 4274 | 4284 | break; |
| | 4285 | case 1010: |
| | 4286 | im->extra_flags |= FORCE_UTC_TIME; |
| | 4287 | break; |
| 4275 | 4288 | case LONGOPT_UNITS_SI: |
| 4276 | 4289 | if (im->extra_flags & FORCE_UNITS) { |
| 4277 | 4290 | rrd_set_error("--units can only be used once!"); |
-
|
|
|
|
| 39 | 39 | |
| 40 | 40 | #define FULL_SIZE_MODE 0x200 /* -width and -height indicate the total size of the image */ |
| 41 | 41 | #define NO_RRDTOOL_TAG 0x400 /* disable the rrdtool tag */ |
| | 42 | #define FORCE_UTC_TIME 0x800 /* Work in UTC timezone instead of localtimg */ |
| 42 | 43 | |
| 43 | 44 | enum tmt_en { TMT_SECOND = 0, TMT_MINUTE, TMT_HOUR, TMT_DAY, |
| 44 | 45 | TMT_WEEK, TMT_MONTH, TMT_YEAR |
| … |
… |
|
| 334 | 335 | time_t find_first_time( |
| 335 | 336 | time_t, |
| 336 | 337 | enum tmt_en, |
| 337 | | long); |
| | 338 | long, |
| | 339 | int); |
| 338 | 340 | time_t find_next_time( |
| 339 | 341 | time_t, |
| 340 | 342 | enum tmt_en, |
| 341 | | long); |
| | 343 | long, |
| | 344 | int); |
| 342 | 345 | int print_calc( |
| 343 | 346 | image_desc_t *); |
| 344 | 347 | int leg_place( |
Download in other formats:
|