4
0

logsysbench.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright (c) 2008, 2009 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <config.h>
  35. #include <stdio.h>
  36. #include <stdint.h>
  37. #include <string.h>
  38. #include <sys/time.h>
  39. #include <time.h>
  40. #include <corosync/engine/logsys.h>
  41. LOGSYS_DECLARE_SYSTEM ("logtest_rec",
  42. LOGSYS_MODE_OUTPUT_STDERR | LOGSYS_MODE_THREADED,
  43. 0, /* debug */
  44. NULL,
  45. LOGSYS_LEVEL_INFO, /* logfile_priority */
  46. LOG_DAEMON, /* syslog facility */
  47. LOGSYS_LEVEL_INFO, /* syslog level */
  48. NULL, /* use default format */
  49. 1000000); /* flight recorder size */
  50. #define LOGREC_ID_CHECKPOINT_CREATE 2
  51. #define LOGREC_ARGS_CHECKPOINT_CREATE 2
  52. #define ITERATIONS 1000000
  53. static struct timeval tv1, tv2, tv_elapsed;
  54. #ifndef timersub
  55. #define timersub(a, b, result) \
  56. do { \
  57. (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
  58. (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
  59. if ((result)->tv_usec < 0) { \
  60. --(result)->tv_sec; \
  61. (result)->tv_usec += 1000000; \
  62. } \
  63. } while (0)
  64. #endif
  65. static void bm_start (void)
  66. {
  67. gettimeofday (&tv1, NULL);
  68. }
  69. static void bm_finish (const char *operation)
  70. {
  71. gettimeofday (&tv2, NULL);
  72. timersub (&tv2, &tv1, &tv_elapsed);
  73. if (strlen (operation) > 22) {
  74. printf ("%s\t\t", operation);
  75. } else {
  76. printf ("%s\t\t\t", operation);
  77. }
  78. printf ("%9.3f operations/sec\n",
  79. ((float)ITERATIONS) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  80. }
  81. static char buffer[256];
  82. int main (void)
  83. {
  84. int i;
  85. char buf[1024];
  86. printf ("heating up cache with logrec functionality\n");
  87. for (i = 0; i < ITERATIONS; i++) {
  88. log_rec (LOGREC_ID_CHECKPOINT_CREATE,
  89. "recordA", 8, "recordB", 8, LOGSYS_REC_END);
  90. }
  91. bm_start();
  92. for (i = 0; i < ITERATIONS; i++) {
  93. log_rec (LOGREC_ID_CHECKPOINT_CREATE,
  94. buffer, 7, LOGSYS_REC_END);
  95. }
  96. bm_finish ("log_rec 1 arguments:");
  97. bm_start();
  98. for (i = 0; i < ITERATIONS; i++) {
  99. log_rec (LOGREC_ID_CHECKPOINT_CREATE,
  100. "recordA", 8, LOGSYS_REC_END);
  101. }
  102. bm_finish ("log_rec 2 arguments:");
  103. bm_start();
  104. for (i = 0; i < 10; i++) {
  105. log_rec (LOGREC_ID_CHECKPOINT_CREATE,
  106. "recordA", 8, "recordB", 8, LOGSYS_REC_END);
  107. }
  108. bm_start();
  109. for (i = 0; i < ITERATIONS; i++) {
  110. log_rec (LOGREC_ID_CHECKPOINT_CREATE,
  111. "recordA", 8, "recordB", 8, "recordC", 8, LOGSYS_REC_END);
  112. }
  113. bm_finish ("log_rec 3 arguments:");
  114. bm_start();
  115. for (i = 0; i < ITERATIONS; i++) {
  116. log_rec (LOGREC_ID_CHECKPOINT_CREATE,
  117. "recordA", 8, "recordB", 8, "recordC", 8, "recordD", 8, LOGSYS_REC_END);
  118. }
  119. bm_finish ("log_rec 4 arguments:");
  120. /*
  121. * sprintf testing
  122. */
  123. printf ("heating up cache with sprintf functionality\n");
  124. for (i = 0; i < ITERATIONS; i++) {
  125. snprintf (buf, sizeof(buf), "Some logging information %s", "recordA");
  126. }
  127. bm_start();
  128. for (i = 0; i < ITERATIONS; i++) {
  129. snprintf (buf, sizeof(buf), "Some logging information %s", "recordA");
  130. }
  131. bm_finish ("sprintf 1 argument:");
  132. bm_start();
  133. for (i = 0; i < ITERATIONS; i++) {
  134. sprintf (buf, "Some logging information %s %s", "recordA", "recordB");
  135. }
  136. bm_finish ("sprintf 2 arguments:");
  137. bm_start();
  138. for (i = 0; i < ITERATIONS; i++) {
  139. sprintf (buf, "Some logging information %s %s %s", "recordA", "recordB", "recordC");
  140. }
  141. bm_finish ("sprintf 3 arguments:");
  142. bm_start();
  143. for (i = 0; i < ITERATIONS; i++) {
  144. sprintf (buf, "Some logging information %s %s %s %s", "recordA", "recordB", "recordC", "recordD");
  145. }
  146. bm_finish ("sprintf 4 arguments:");
  147. bm_start();
  148. for (i = 0; i < ITERATIONS; i++) {
  149. sprintf (buf, "Some logging information %s %s %s %d", "recordA", "recordB", "recordC", i);
  150. }
  151. bm_finish ("sprintf 4 arguments (1 int):");
  152. logsys_log_rec_store ("fdata");
  153. /* TODO
  154. currently fails under some circumstances
  155. bm_start();
  156. for (i = 0; i < ITERATIONS; i++) {
  157. log_printf (LOGSYS_LEVEL_NOTICE, "test %d", i);
  158. }
  159. bm_finish("log_printf");
  160. */
  161. return (0);
  162. }