logsysbench.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. 0, /* tags */
  49. NULL, /* use default format */
  50. 1000000); /* flight recorder size */
  51. #define LOGREC_ID_CHECKPOINT_CREATE 2
  52. #define LOGREC_ARGS_CHECKPOINT_CREATE 2
  53. #define ITERATIONS 1000000
  54. static struct timeval tv1, tv2, tv_elapsed;
  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. static void bm_start (void)
  65. {
  66. gettimeofday (&tv1, NULL);
  67. }
  68. static void bm_finish (const char *operation)
  69. {
  70. gettimeofday (&tv2, NULL);
  71. timersub (&tv2, &tv1, &tv_elapsed);
  72. if (strlen (operation) > 22) {
  73. printf ("%s\t\t", operation);
  74. } else {
  75. printf ("%s\t\t\t", operation);
  76. }
  77. printf ("%9.3f operations/sec\n",
  78. ((float)ITERATIONS) / (tv_elapsed.tv_sec + (tv_elapsed.tv_usec / 1000000.0)));
  79. }
  80. static char buffer[256];
  81. int main (void)
  82. {
  83. int i;
  84. char buf[1024];
  85. printf ("heating up cache with logrec functionality\n");
  86. for (i = 0; i < ITERATIONS; i++) {
  87. log_rec (LOGREC_ID_CHECKPOINT_CREATE,
  88. "recordA", 8, "recordB", 8, LOGSYS_REC_END);
  89. }
  90. bm_start();
  91. for (i = 0; i < ITERATIONS; i++) {
  92. log_rec (LOGREC_ID_CHECKPOINT_CREATE,
  93. buffer, 7, LOGSYS_REC_END);
  94. }
  95. bm_finish ("log_rec 1 arguments:");
  96. bm_start();
  97. for (i = 0; i < ITERATIONS; i++) {
  98. log_rec (LOGREC_ID_CHECKPOINT_CREATE,
  99. "recordA", 8, LOGSYS_REC_END);
  100. }
  101. bm_finish ("log_rec 2 arguments:");
  102. bm_start();
  103. for (i = 0; i < 10; i++) {
  104. log_rec (LOGREC_ID_CHECKPOINT_CREATE,
  105. "recordA", 8, "recordB", 8, LOGSYS_REC_END);
  106. }
  107. bm_start();
  108. for (i = 0; i < ITERATIONS; i++) {
  109. log_rec (LOGREC_ID_CHECKPOINT_CREATE,
  110. "recordA", 8, "recordB", 8, "recordC", 8, LOGSYS_REC_END);
  111. }
  112. bm_finish ("log_rec 3 arguments:");
  113. bm_start();
  114. for (i = 0; i < ITERATIONS; i++) {
  115. log_rec (LOGREC_ID_CHECKPOINT_CREATE,
  116. "recordA", 8, "recordB", 8, "recordC", 8, "recordD", 8, LOGSYS_REC_END);
  117. }
  118. bm_finish ("log_rec 4 arguments:");
  119. /*
  120. * sprintf testing
  121. */
  122. printf ("heating up cache with sprintf functionality\n");
  123. for (i = 0; i < ITERATIONS; i++) {
  124. snprintf (buf, sizeof(buf), "Some logging information %s", "recordA");
  125. }
  126. bm_start();
  127. for (i = 0; i < ITERATIONS; i++) {
  128. snprintf (buf, sizeof(buf), "Some logging information %s", "recordA");
  129. }
  130. bm_finish ("sprintf 1 argument:");
  131. bm_start();
  132. for (i = 0; i < ITERATIONS; i++) {
  133. sprintf (buf, "Some logging information %s %s", "recordA", "recordB");
  134. }
  135. bm_finish ("sprintf 2 arguments:");
  136. bm_start();
  137. for (i = 0; i < ITERATIONS; i++) {
  138. sprintf (buf, "Some logging information %s %s %s", "recordA", "recordB", "recordC");
  139. }
  140. bm_finish ("sprintf 3 arguments:");
  141. bm_start();
  142. for (i = 0; i < ITERATIONS; i++) {
  143. sprintf (buf, "Some logging information %s %s %s %s", "recordA", "recordB", "recordC", "recordD");
  144. }
  145. bm_finish ("sprintf 4 arguments:");
  146. bm_start();
  147. for (i = 0; i < ITERATIONS; i++) {
  148. sprintf (buf, "Some logging information %s %s %s %d", "recordA", "recordB", "recordC", i);
  149. }
  150. bm_finish ("sprintf 4 arguments (1 int):");
  151. logsys_log_rec_store ("fdata");
  152. /* TODO
  153. currently fails under some circumstances
  154. bm_start();
  155. for (i = 0; i < ITERATIONS; i++) {
  156. log_printf (LOGSYS_LEVEL_NOTICE, "test %d", i);
  157. }
  158. bm_finish("log_printf");
  159. */
  160. return (0);
  161. }