rrdr.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "rrdr.h"
  3. /*
  4. static void rrdr_dump(RRDR *r)
  5. {
  6. long c, i;
  7. RRDDIM *d;
  8. fprintf(stderr, "\nCHART %s (%s)\n", r->st->id, r->st->name);
  9. for(c = 0, d = r->st->dimensions; d ;c++, d = d->next) {
  10. fprintf(stderr, "DIMENSION %s (%s), %s%s%s%s\n"
  11. , d->id
  12. , d->name
  13. , (r->od[c] & RRDR_EMPTY)?"EMPTY ":""
  14. , (r->od[c] & RRDR_RESET)?"RESET ":""
  15. , (r->od[c] & RRDR_DIMENSION_HIDDEN)?"HIDDEN ":""
  16. , (r->od[c] & RRDR_DIMENSION_NONZERO)?"NONZERO ":""
  17. );
  18. }
  19. if(r->rows <= 0) {
  20. fprintf(stderr, "RRDR does not have any values in it.\n");
  21. return;
  22. }
  23. fprintf(stderr, "RRDR includes %d values in it:\n", r->rows);
  24. // for each line in the array
  25. for(i = 0; i < r->rows ;i++) {
  26. NETDATA_DOUBLE *cn = &r->v[ i * r->d ];
  27. RRDR_DIMENSION_FLAGS *co = &r->o[ i * r->d ];
  28. // print the id and the timestamp of the line
  29. fprintf(stderr, "%ld %ld ", i + 1, r->t[i]);
  30. // for each dimension
  31. for(c = 0, d = r->st->dimensions; d ;c++, d = d->next) {
  32. if(unlikely(r->od[c] & RRDR_DIMENSION_HIDDEN)) continue;
  33. if(unlikely(!(r->od[c] & RRDR_DIMENSION_NONZERO))) continue;
  34. if(co[c] & RRDR_EMPTY)
  35. fprintf(stderr, "null ");
  36. else
  37. fprintf(stderr, NETDATA_DOUBLE_FORMAT " %s%s%s%s "
  38. , cn[c]
  39. , (co[c] & RRDR_EMPTY)?"E":" "
  40. , (co[c] & RRDR_RESET)?"R":" "
  41. , (co[c] & RRDR_DIMENSION_HIDDEN)?"H":" "
  42. , (co[c] & RRDR_DIMENSION_NONZERO)?"N":" "
  43. );
  44. }
  45. fprintf(stderr, "\n");
  46. }
  47. }
  48. */
  49. inline void rrdr_free(ONEWAYALLOC *owa, RRDR *r) {
  50. if(unlikely(!r)) return;
  51. query_target_release(r->internal.qt);
  52. onewayalloc_freez(owa, r->t);
  53. onewayalloc_freez(owa, r->v);
  54. onewayalloc_freez(owa, r->o);
  55. onewayalloc_freez(owa, r->od);
  56. onewayalloc_freez(owa, r->ar);
  57. onewayalloc_freez(owa, r);
  58. }
  59. RRDR *rrdr_create(ONEWAYALLOC *owa, QUERY_TARGET *qt) {
  60. if(unlikely(!qt || !qt->query.used || !qt->window.points))
  61. return NULL;
  62. size_t dimensions = qt->query.used;
  63. size_t points = qt->window.points;
  64. // create the rrdr
  65. RRDR *r = onewayalloc_callocz(owa, 1, sizeof(RRDR));
  66. r->internal.owa = owa;
  67. r->internal.qt = qt;
  68. r->before = qt->window.before;
  69. r->after = qt->window.after;
  70. r->internal.points_wanted = qt->window.points;
  71. r->d = (int)dimensions;
  72. r->n = (int)points;
  73. r->t = onewayalloc_callocz(owa, points, sizeof(time_t));
  74. r->v = onewayalloc_mallocz(owa, points * dimensions * sizeof(NETDATA_DOUBLE));
  75. r->o = onewayalloc_mallocz(owa, points * dimensions * sizeof(RRDR_VALUE_FLAGS));
  76. r->ar = onewayalloc_mallocz(owa, points * dimensions * sizeof(NETDATA_DOUBLE));
  77. r->od = onewayalloc_mallocz(owa, dimensions * sizeof(RRDR_DIMENSION_FLAGS));
  78. r->group = 1;
  79. r->update_every = 1;
  80. return r;
  81. }