📄 perform.c
字号:
/****************************************************************************** File Name : perform.c Description : STAVFS Performance tests******************************************************************************//* we always need some STTBX_PRINT in this file to output the actual statistics, but if it is turned on globally, output extra diagnostic info too, like the other tests */#ifdef STTBX_PRINT#define DO_EXTRA_PRINT#else#define STTBX_PRINT#endif/* Includes ---------------------------------------------------------------- */#include <stdlib.h>#include <stdio.h>#include <ctype.h>#include <string.h>#include <assert.h>#include <ostime.h>#include "wrapper.h" /* from ../utils. Uses ../../src */#include "stavfs.h"/* Private Types ----------------------------------------------------------- *//* Private Constants ------------------------------------------------------- *//* standard device name where only one is needed */#define DEV_NAME "PerformDev"/* standard file name where only one is needed */#define FILE_NAME "Perform"/* number of disk partitions for OpenClose test */#define NUM_PARTITIONS (4)/* Private Variables ------------------------------------------------------- *//* Standard write/read buffer - we don't care what's in it */static U8 Buffer[64 * K_BYTES];/* conversion factor from ticks to milliseconds, set up in 'Perform' */static U32 TicksPerMS;/* Private Macros ---------------------------------------------------------- */#ifdef DO_EXTRA_PRINT#define EXTRA_Print(x) STTBX_Print(x)#else#define EXTRA_Print(x)#endif/* Private Function Prototypes --------------------------------------------- */static TestResult_t OpenClose (int TestNo, TestVariant_t Variant);static TestResult_t AllocDealloc (int TestNo, TestVariant_t Variant);static TestResult_t WriteRead (int TestNo, TestVariant_t Variant);static TestResult_t WriteExpand (int TestNo, TestVariant_t Variant);static TestResult_t Pause (int TestNo, TestVariant_t Variant);static TestResult_t RawHAL (int TestNo, TestVariant_t Variant);static void WriteReadInner (STAVFS_FileHandle_t FileHandle, int Partition, U32 BytesLimit, TestResult_t * Result_p);static void WriteExpandInner (STAVFS_FileHandle_t FileHandle, U32 BlockSize, TestResult_t * Result_p);static void PauseInner (STAVFS_FileHandle_t FileHandle, U32 FileBytes, TestResult_t * Result_p);/* Functions --------------------------------------------------------------- *//******************************************************************************Function Name : Perform Description : Performance test section function Parameters :******************************************************************************/BOOL Perform (parse_t * pars_p, char *result_sym_p){ char *Description = "Performance tests"; TestCall_t TestList[] = { OpenClose, /* Test 001 */ AllocDealloc, /* Test 002 */ WriteRead, /* Test 003 */ WriteExpand, /* Test 004 */ Pause, /* Test 005 */ RawHAL, /* Test 006 */ }; /* Get the conversion factor from ticks to seconds. Not very accurate */ TicksPerMS = ST_GetClocksPerSecond () / 1000; GenericTest (pars_p, result_sym_p, Description, TestList, TABLE_LEN(TestList)-1, TEST_VARIANT_A); return (FALSE);}/******************************************************************************Function Name : OpenClose Description : Performance tests for partition open/close Parameters :******************************************************************************/static TestResult_t OpenClose(int TestNo, TestVariant_t Variant){ TestResult_t Result = TEST_PASSED; STAVFS_Handle_t DiskHandles[NUM_PARTITIONS]; char * DevNames[NUM_PARTITIONS] = {"Dev0", "Dev1", "Dev2", "Dev3"}; int i; int LongestPartition; /* absolute time values */ clock_t StartTime, PartitionStartTime, EndTime; /* time value differences */ clock_t DeltaTime, LongestTime; /* ---- partition opening ---- */ LongestTime = 0; PartitionStartTime = StartTime = time_now (); for (i = 0; i < NUM_PARTITIONS; ++i) { /* Init, default fsck that has nothing to do, Open */ if (TEST_PASSED != OpenPartition (0, i, DevNames[i], &DiskHandles[i])) { Result = TEST_FAILED; /* message already displayed */ break; /* since we wouldn't display results anyway */ } EndTime = time_now (); DeltaTime = time_minus (EndTime, PartitionStartTime); if (DeltaTime > LongestTime) { LongestTime = DeltaTime; LongestPartition = i; } PartitionStartTime = time_now (); /* for next iteration */ } EndTime = time_now (); DeltaTime = time_minus (EndTime, StartTime); /* only produce output if test has run as intended */ if (Result == TEST_PASSED) { STTBX_Print (("\n\tOpening partitions:" "\n\t\taverage time: %5u ms per partition" "\n\t\tlongest time: %5u ms for partition %i\n", DeltaTime / (NUM_PARTITIONS * TicksPerMS), LongestTime / TicksPerMS, LongestPartition)); } /* ---- partition closing ---- */ LongestTime = 0; PartitionStartTime = StartTime = time_now (); while (--i >= 0) { /* Close, Term */ if (TEST_PASSED != ClosePartition (DevNames[i], DiskHandles[i])) { Result = TEST_FAILED; /* message already displayed */ /* ... but keep trying to terminate the others */ } EndTime = time_now (); DeltaTime = time_minus (EndTime, PartitionStartTime); if (DeltaTime > LongestTime) { LongestTime = DeltaTime; LongestPartition = i; } PartitionStartTime = time_now (); /* for next iteration */ } EndTime = time_now (); DeltaTime = time_minus (EndTime, StartTime); /* only produce output if test has run as intended */ if (Result == TEST_PASSED) { STTBX_Print (("\n\tClosing partitions:" "\n\t\taverage time: %5u ms per partition" "\n\t\tlongest time: %5u ms for partition %i\n", DeltaTime / (NUM_PARTITIONS * TicksPerMS), LongestTime / TicksPerMS, LongestPartition)); } return (Result);}/******************************************************************************Function Name : AllocDealloc Description : Performance tests for cluster allocation/deallocation Parameters :******************************************************************************/static TestResult_t AllocDealloc(int TestNo, TestVariant_t Variant){ TestResult_t Result = TEST_PASSED; STAVFS_Handle_t DiskHandle; STAVFS_OpenMode_t OpenMode; STAVFS_FileHandle_t FileHandle; int Partition, Streaming; U64 FileSize; U32 FileBytes = 100 * M_BYTES; /* absolute time values */ clock_t StartTime, EndTime; /* time value differences */ clock_t CreateTime, DeleteTime; I64_SetValue (FileBytes, 0, FileSize); for (Partition = 1; (Partition <= 3) && (Result == TEST_PASSED); ++Partition) { if (TEST_PASSED != OpenPartition (0, Partition, DEV_NAME, &DiskHandle)) { Result = TEST_FAILED; /* message already displayed */ } else { for (Streaming = 0; (Streaming <= 1) && (Result == TEST_PASSED); ++Streaming) { /* File create */ OpenMode = Streaming ? STAVFS_STREAM_FILE : 0; OpenMode |= STAVFS_WRITE_MODE; StartTime = time_now (); if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME, OpenMode, FileSize, &FileHandle)) { EXTRA_Print (("Couldn't create %s file on partition %i\n", Streaming ? "stream" : "regular", Partition)); Result = TEST_FAILED; } else if (ST_NO_ERROR != STAVFS_CloseFile(FileHandle)) { EXTRA_Print (("Couldn't close %s file on partition %i\n", Streaming ? "stream" : "regular", Partition)); Result = TEST_FAILED; } EndTime = time_now (); CreateTime = time_minus (EndTime, StartTime); /* File delete */ StartTime = time_now (); if (ST_NO_ERROR != STAVFS_DeleteFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME)) { EXTRA_Print (("Couldn't delete %s file on partition %i\n", Streaming ? "stream" : "regular", Partition)); Result = TEST_FAILED; } EndTime = time_now (); DeleteTime = time_minus (EndTime, StartTime); /* Display results provided test ran as intended */ if (Result == TEST_PASSED) { STTBX_Print (("\n\t%u MB %s file" " on %i sector(s) per cluster:" "\n\t\tcreate %6u ms, delete %6u ms\n", FileBytes / M_BYTES, Streaming ? "stream" : "regular", TestPartitionDefs[Partition].SizeOfCluster, CreateTime / TicksPerMS, DeleteTime / TicksPerMS)); } } if (TEST_PASSED != ClosePartition (DEV_NAME, DiskHandle)) { Result = TEST_FAILED; /* message already displayed */ } } } return (Result);}/******************************************************************************Function Name : WriteRead Description : Performance tests for file write/read, in preallocated file Parameters :******************************************************************************/static TestResult_t WriteRead(int TestNo, TestVariant_t Variant){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -