logsysbench.c 5.1 KB

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