_info 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "config.h"
  4. /**
  5. * jset - set of pointers (based on libJudy)
  6. *
  7. * This provides a convenient wrapper for using Judy bitsets; using
  8. * pointers (or unsigned longs) as the index, Judy arrays provide an
  9. * efficient bit array or bit map of variable size.
  10. *
  11. * jset.h contains typesafe wrappers for this usage.
  12. *
  13. * Example:
  14. * // Simple analysis of one-byte mallocs.
  15. * #include <ccan/jset/jset.h>
  16. * #include <stdlib.h>
  17. * #include <stdio.h>
  18. * #include <err.h>
  19. *
  20. * struct jset_char {
  21. * JSET_MEMBERS(char *);
  22. * };
  23. *
  24. * int main(int argc, char *argv[])
  25. * {
  26. * unsigned int i, runs, reuse;
  27. * size_t mindist = -1;
  28. * struct jset_char *set = jset_new(struct jset_char);
  29. * char *p, *prev;
  30. *
  31. * runs = (argc == 1 ? 1000 : atoi(argv[1]));
  32. * if (!runs)
  33. * errx(1, "Invalid number of allocations '%s'", argv[1]);
  34. *
  35. * for (i = 0; i < runs; i++)
  36. * if (!jset_set(set, malloc(1)))
  37. * errx(1, "same pointer allocated twice!");
  38. *
  39. * // Calculate minimum distance
  40. * prev = jset_first(set)+1;
  41. * for (p = jset_first(set); p; prev = p, p = jset_next(set,p))
  42. * if (p - prev < mindist)
  43. * mindist = p - prev;
  44. *
  45. * // Free them all, see how many we reallocate.
  46. * for (p = jset_first(set); p; p = jset_next(set, p))
  47. * free(p);
  48. * for (reuse = 0, i = 0; i < runs; i++)
  49. * reuse += jset_test(set, malloc(1));
  50. *
  51. * printf("Allocation density (bytes): %zu\n"
  52. * "Minimum inter-pointer distance: %zu\n"
  53. * "Reuse rate: %.0f%%\n",
  54. * (jset_last(set) - jset_first(set)) / runs,
  55. * mindist,
  56. * 100.0 * reuse / runs);
  57. * return 0;
  58. * }
  59. *
  60. * License: LGPL (v2.1 or any later version)
  61. * Author: Rusty Russell <rusty@rustcorp.com.au>
  62. */
  63. int main(int argc, char *argv[])
  64. {
  65. if (argc != 2)
  66. return 1;
  67. if (strcmp(argv[1], "depends") == 0) {
  68. printf("ccan/build_assert\n");
  69. printf("ccan/compiler\n");
  70. printf("ccan/tcon\n");
  71. printf("Judy\n");
  72. return 0;
  73. }
  74. if (strcmp(argv[1], "libs") == 0) {
  75. printf("Judy\n");
  76. return 0;
  77. }
  78. return 1;
  79. }