logsysbench.c 5.1 KB

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