benchmark.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Gearman server and library
  2. * Copyright (C) 2008 Brian Aker, Eric Day
  3. * All rights reserved.
  4. *
  5. * Use and distribution licensed under the BSD license. See
  6. * the COPYING file in the parent directory for full text.
  7. */
  8. /**
  9. * @file
  10. * @brief Common benchmark header
  11. */
  12. #pragma once
  13. #include <config.h>
  14. #include <libgearman/gearman.h>
  15. #ifdef HAVE_ERRNO_H
  16. #include <errno.h>
  17. #endif
  18. #ifdef HAVE_SIGNAL_H
  19. #include <signal.h>
  20. #endif
  21. #ifdef HAVE_STDIO_H
  22. #include <stdio.h>
  23. #endif
  24. #ifdef HAVE_STDLIB_H
  25. #include <stdlib.h>
  26. #endif
  27. #ifdef HAVE_STRING_H
  28. #include <string.h>
  29. #endif
  30. #ifdef HAVE_UNISTD_H
  31. #include <unistd.h>
  32. #endif
  33. #ifdef TIME_WITH_SYS_TIME
  34. # include <sys/time.h>
  35. # include <time.h>
  36. #else
  37. # ifdef HAVE_SYS_TIME_H
  38. # include <sys/time.h>
  39. # else
  40. # include <time.h>
  41. # endif
  42. #endif
  43. #define GEARMAN_BENCHMARK_DEFAULT_FUNCTION "gb"
  44. /**
  45. * @addtogroup benchmark Common Benchmark Utilities
  46. * @{
  47. */
  48. struct gearman_benchmark_st
  49. {
  50. bool background;
  51. uint8_t verbose;
  52. uint64_t total_jobs;
  53. uint64_t jobs;
  54. struct timeval total;
  55. struct timeval begin;
  56. struct timeval end;
  57. gearman_benchmark_st() :
  58. background(false),
  59. verbose(0),
  60. total_jobs(0),
  61. jobs(0),
  62. end()
  63. {
  64. gettimeofday(&total, NULL);
  65. gettimeofday(&begin, NULL);
  66. }
  67. };
  68. /**
  69. * Check and possibly print time.
  70. */
  71. void benchmark_check_time(gearman_benchmark_st *benchmark);