123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- /*++
- Copyright (c) 2015 Minoca Corp. All Rights Reserved
- Module Name:
- create.c
- Abstract:
- This module implements the performance benchmark tests for the creat() and
- remove() C library calls.
- Author:
- Chris Stevens 5-May-2015
- Environment:
- User
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #include <stdio.h>
- #include <errno.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include "perftest.h"
- //
- // ---------------------------------------------------------------- Definitions
- //
- #define PT_CREATE_TEST_FILE_NAME_LENGTH 48
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // ----------------------------------------------- Internal Function Prototypes
- //
- //
- // -------------------------------------------------------------------- Globals
- //
- //
- // ------------------------------------------------------------------ Functions
- //
- void
- CreateMain (
- PPT_TEST_INFORMATION Test,
- PPT_TEST_RESULT Result
- )
- /*++
- Routine Description:
- This routine performs the create performance benchmark test.
- Arguments:
- Test - Supplies a pointer to the performance test being executed.
- Result - Supplies a pointer to a performance test result structure that
- receives the tests results.
- Return Value:
- None.
- --*/
- {
- int FileDescriptor;
- char FileName[PT_CREATE_TEST_FILE_NAME_LENGTH];
- unsigned long long Iterations;
- pid_t ProcessId;
- int Status;
- Iterations = 0;
- Result->Type = PtResultIterations;
- Result->Status = 0;
- //
- // Get the process ID and create a process safe file path to create and
- // remove.
- //
- ProcessId = getpid();
- Status = snprintf(FileName,
- PT_CREATE_TEST_FILE_NAME_LENGTH,
- "create_%d.txt",
- ProcessId);
- if (Status < 0) {
- Result->Status = errno;
- goto MainEnd;
- }
- //
- // Start the test. This snaps resource usage and starts the clock ticking.
- //
- Status = PtStartTimedTest(Test->Duration);
- if (Status != 0) {
- Result->Status = errno;
- goto MainEnd;
- }
- //
- // Measure the performance of the creat() and remove() C library routines
- // by counting the number of times a file can be created and removed.
- //
- while (PtIsTimedTestRunning() != 0) {
- FileDescriptor = creat(FileName, S_IRUSR | S_IWUSR);
- if (FileDescriptor < 0) {
- Result->Status = errno;
- break;
- }
- Status = close(FileDescriptor);
- if (Status != 0) {
- Result->Status = errno;
- break;
- }
- Status = remove(FileName);
- if (Status != 0) {
- Result->Status = errno;
- break;
- }
- Iterations += 1;
- }
- Status = PtFinishTimedTest(Result);
- if ((Status != 0) && (Result->Status == 0)) {
- Result->Status = errno;
- }
- MainEnd:
- Result->Data.Iterations = Iterations;
- return;
- }
- //
- // --------------------------------------------------------- Internal Functions
- //
|