builtin-bench.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. *
  3. * builtin-bench.c
  4. *
  5. * General benchmarking subsystem provided by perf
  6. *
  7. * Copyright (C) 2009, Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
  8. *
  9. */
  10. /*
  11. *
  12. * Available subsystem list:
  13. * sched ... scheduler and IPC mechanism
  14. *
  15. */
  16. #include "perf.h"
  17. #include "util/util.h"
  18. #include "util/parse-options.h"
  19. #include "builtin.h"
  20. #include "bench/bench.h"
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. struct bench_suite {
  25. const char *name;
  26. const char *summary;
  27. int (*fn)(int, const char **, const char *);
  28. };
  29. static struct bench_suite sched_suites[] = {
  30. { "messaging",
  31. "Benchmark for scheduler and IPC mechanisms",
  32. bench_sched_messaging },
  33. { "pipe",
  34. "Flood of communication over pipe() between two processes",
  35. bench_sched_pipe },
  36. { NULL,
  37. NULL,
  38. NULL }
  39. };
  40. struct bench_subsys {
  41. const char *name;
  42. const char *summary;
  43. struct bench_suite *suites;
  44. };
  45. static struct bench_subsys subsystems[] = {
  46. { "sched",
  47. "scheduler and IPC mechanism",
  48. sched_suites },
  49. { NULL,
  50. NULL,
  51. NULL }
  52. };
  53. static void dump_suites(int subsys_index)
  54. {
  55. int i;
  56. printf("List of available suites for %s...\n\n",
  57. subsystems[subsys_index].name);
  58. for (i = 0; subsystems[subsys_index].suites[i].name; i++)
  59. printf("\t%s: %s\n",
  60. subsystems[subsys_index].suites[i].name,
  61. subsystems[subsys_index].suites[i].summary);
  62. printf("\n");
  63. return;
  64. }
  65. int cmd_bench(int argc, const char **argv, const char *prefix __used)
  66. {
  67. int i, j, status = 0;
  68. if (argc < 2) {
  69. /* No subsystem specified. */
  70. printf("Usage: perf bench <subsystem> <suite> [<options>]\n\n");
  71. printf("List of available subsystems...\n\n");
  72. for (i = 0; subsystems[i].name; i++)
  73. printf("\t%s: %s\n",
  74. subsystems[i].name, subsystems[i].summary);
  75. printf("\n");
  76. goto end;
  77. }
  78. for (i = 0; subsystems[i].name; i++) {
  79. if (strcmp(subsystems[i].name, argv[1]))
  80. continue;
  81. if (argc < 3) {
  82. /* No suite specified. */
  83. dump_suites(i);
  84. goto end;
  85. }
  86. for (j = 0; subsystems[i].suites[j].name; j++) {
  87. if (strcmp(subsystems[i].suites[j].name, argv[2]))
  88. continue;
  89. status = subsystems[i].suites[j].fn(argc - 2,
  90. argv + 2, prefix);
  91. goto end;
  92. }
  93. if (!strcmp(argv[2], "-h") || !strcmp(argv[2], "--help")) {
  94. dump_suites(i);
  95. goto end;
  96. }
  97. printf("Unknown suite:%s for %s\n", argv[2], argv[1]);
  98. status = 1;
  99. goto end;
  100. }
  101. printf("Unknown subsystem:%s\n", argv[1]);
  102. status = 1;
  103. end:
  104. return status;
  105. }