create.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*++
  2. Copyright (c) 2015 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. create.c
  5. Abstract:
  6. This module implements the performance benchmark tests for the creat() and
  7. remove() C library calls.
  8. Author:
  9. Chris Stevens 5-May-2015
  10. Environment:
  11. User
  12. --*/
  13. //
  14. // ------------------------------------------------------------------- Includes
  15. //
  16. #include <stdio.h>
  17. #include <errno.h>
  18. #include <sys/stat.h>
  19. #include <unistd.h>
  20. #include "perftest.h"
  21. //
  22. // ---------------------------------------------------------------- Definitions
  23. //
  24. #define PT_CREATE_TEST_FILE_NAME_LENGTH 48
  25. //
  26. // ------------------------------------------------------ Data Type Definitions
  27. //
  28. //
  29. // ----------------------------------------------- Internal Function Prototypes
  30. //
  31. //
  32. // -------------------------------------------------------------------- Globals
  33. //
  34. //
  35. // ------------------------------------------------------------------ Functions
  36. //
  37. void
  38. CreateMain (
  39. PPT_TEST_INFORMATION Test,
  40. PPT_TEST_RESULT Result
  41. )
  42. /*++
  43. Routine Description:
  44. This routine performs the create performance benchmark test.
  45. Arguments:
  46. Test - Supplies a pointer to the performance test being executed.
  47. Result - Supplies a pointer to a performance test result structure that
  48. receives the tests results.
  49. Return Value:
  50. None.
  51. --*/
  52. {
  53. int FileDescriptor;
  54. char FileName[PT_CREATE_TEST_FILE_NAME_LENGTH];
  55. unsigned long long Iterations;
  56. pid_t ProcessId;
  57. int Status;
  58. Iterations = 0;
  59. Result->Type = PtResultIterations;
  60. Result->Status = 0;
  61. //
  62. // Get the process ID and create a process safe file path to create and
  63. // remove.
  64. //
  65. ProcessId = getpid();
  66. Status = snprintf(FileName,
  67. PT_CREATE_TEST_FILE_NAME_LENGTH,
  68. "create_%d.txt",
  69. ProcessId);
  70. if (Status < 0) {
  71. Result->Status = errno;
  72. goto MainEnd;
  73. }
  74. //
  75. // Start the test. This snaps resource usage and starts the clock ticking.
  76. //
  77. Status = PtStartTimedTest(Test->Duration);
  78. if (Status != 0) {
  79. Result->Status = errno;
  80. goto MainEnd;
  81. }
  82. //
  83. // Measure the performance of the creat() and remove() C library routines
  84. // by counting the number of times a file can be created and removed.
  85. //
  86. while (PtIsTimedTestRunning() != 0) {
  87. FileDescriptor = creat(FileName, S_IRUSR | S_IWUSR);
  88. if (FileDescriptor < 0) {
  89. Result->Status = errno;
  90. break;
  91. }
  92. Status = close(FileDescriptor);
  93. if (Status != 0) {
  94. Result->Status = errno;
  95. break;
  96. }
  97. Status = remove(FileName);
  98. if (Status != 0) {
  99. Result->Status = errno;
  100. break;
  101. }
  102. Iterations += 1;
  103. }
  104. Status = PtFinishTimedTest(Result);
  105. if ((Status != 0) && (Result->Status == 0)) {
  106. Result->Status = errno;
  107. }
  108. MainEnd:
  109. Result->Data.Iterations = Iterations;
  110. return;
  111. }
  112. //
  113. // --------------------------------------------------------- Internal Functions
  114. //