-
Notifications
You must be signed in to change notification settings - Fork 53
/
DiskBench.cpp
931 lines (824 loc) · 20.4 KB
/
DiskBench.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
/*---------------------------------------------------------------------------*/
// Author : hiyohiyo
// Mail : [email protected]
// Web : https://crystalmark.info/
// License : MIT License
/*---------------------------------------------------------------------------*/
#include "stdafx.h"
#include "DiskMark.h"
#include "DiskMarkDlg.h"
#include "DiskBench.h"
#include <afxmt.h>
#include <winioctl.h>
#include <mmsystem.h>
#pragma comment(lib,"winmm.lib")
#pragma warning(disable : 4996)
static CString TestFilePath;
static CString TestFileDir;
static CString DiskSpdExe;
static HANDLE hFile;
static int DiskTestCount;
static UINT64 DiskTestSize;
static int BenchType[9];
static int BenchSize[9];
static int BenchQueues[9];
static int BenchThreads[9];
// static int Affinity;
static BOOL MixMode;
static int MixRatio;
static void ShowErrorMessage(CString message);
static void Interval(void* dlg);
static BOOL Init(void* dlg);
static void DiskSpd(void* dlg, DISK_SPD_CMD cmd);
static UINT Exit(void* dlg);
static void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
static volatile BOOL WaitFlag;
#define DISK_SPD_EXE_32 L"CdmResource\\diskspd\\diskspd32.exe"
#define DISK_SPD_EXE_64 L"CdmResource\\diskspd\\diskspd64.exe"
#define DISK_SPD_EXE_32_LEGACY L"CdmResource\\diskspd\\diskspd32L.exe"
#define DISK_SPD_EXE_64_LEGACY L"CdmResource\\diskspd\\diskspd64L.exe"
#define DISK_SPD_EXE_ARM32 L"CdmResource\\diskspd\\diskspdA32.exe"
#define DISK_SPD_EXE_ARM64 L"CdmResource\\diskspd\\diskspdA64.exe"
PROCESS_INFORMATION pi;
int ExecAndWait(TCHAR *pszCmd, BOOL bNoWindow, double *latency)
{
DWORD Code = 0;
BOOL bSuccess;
STARTUPINFO si;
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
if (bNoWindow) {
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
}
CString name;
name.Format(L"CrystalDiskMark%08X", GetCurrentProcessId());
auto size = 8;
HANDLE hSharedMemory = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, NULL, size, name.GetString());
if (hSharedMemory != NULL)
{
auto pMemory = (double*)MapViewOfFile(hSharedMemory, FILE_MAP_ALL_ACCESS, NULL, NULL, size);
if (pMemory != NULL)
{
bSuccess = CreateProcess(NULL, pszCmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
if (bSuccess != TRUE)
{
UnmapViewOfFile(pMemory);
CloseHandle(hSharedMemory);
return 0;
}
WaitForInputIdle(pi.hProcess, INFINITE);
WaitForSingleObject(pi.hProcess, INFINITE);
GetExitCodeProcess(pi.hProcess, &Code);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
pi.hProcess = NULL;
*latency = (double)*pMemory * 1000; // milli sec to micro sec
UnmapViewOfFile(pMemory);
CloseHandle(hSharedMemory);
}
}
return Code;
}
void ShowErrorMessage(CString message)
{
DWORD lastErrorCode = GetLastError();
CString errorMessage;
LPVOID lpMessageBuffer;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, lastErrorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMessageBuffer, 0, NULL);
errorMessage.Format(L"0x%08X:%s", lastErrorCode, (LPTSTR) lpMessageBuffer);
AfxMessageBox(message + L"\r\n" + errorMessage);
LocalFree( lpMessageBuffer );
}
void Interval(void* dlg)
{
int intervalTime = ((CDiskMarkDlg*) dlg)->m_IntervalTime;
CString title;
for (int i = 0; i < intervalTime; i++)
{
if (!((CDiskMarkDlg*) dlg)->m_DiskBenchStatus)
{
return;
}
title.Format(L"Interval Time %d/%d sec", i, intervalTime);
::PostMessage(((CDiskMarkDlg*) dlg)->GetSafeHwnd(), WM_UPDATE_MESSAGE, (WPARAM) &title, 0);
Sleep(1000);
}
}
UINT ExecDiskBenchAll(LPVOID dlg)
{
int benchmark = ((CDiskMarkDlg*)dlg)->m_Benchmark;
if(Init(dlg))
{
if (benchmark & BENCHMARK_READ)
{
DiskSpd(dlg, TEST_READ_0); Interval(dlg);
DiskSpd(dlg, TEST_READ_1); Interval(dlg);
DiskSpd(dlg, TEST_READ_2); Interval(dlg);
DiskSpd(dlg, TEST_READ_3);
}
if ((benchmark & BENCHMARK_READ) && (benchmark & BENCHMARK_WRITE))
{
Interval(dlg);
}
if (benchmark & BENCHMARK_WRITE)
{
DiskSpd(dlg, TEST_WRITE_0); Interval(dlg);
DiskSpd(dlg, TEST_WRITE_1); Interval(dlg);
DiskSpd(dlg, TEST_WRITE_2); Interval(dlg);
DiskSpd(dlg, TEST_WRITE_3);
}
#ifdef MIX_MODE
if (MixMode)
{
Interval(dlg);
DiskSpd(dlg, TEST_MIX_0); Interval(dlg);
DiskSpd(dlg, TEST_MIX_1); Interval(dlg);
DiskSpd(dlg, TEST_MIX_2); Interval(dlg);
DiskSpd(dlg, TEST_MIX_3);
}
#endif
}
return Exit(dlg);
}
UINT ExecDiskBenchAllPeak(LPVOID dlg)
{
int benchmark = ((CDiskMarkDlg*)dlg)->m_Benchmark;
if (Init(dlg))
{
if (benchmark & BENCHMARK_READ)
{
DiskSpd(dlg, TEST_READ_4); Interval(dlg);
DiskSpd(dlg, TEST_READ_5);
}
if ((benchmark & BENCHMARK_READ) && (benchmark & BENCHMARK_WRITE))
{
Interval(dlg);
}
if (benchmark & BENCHMARK_WRITE)
{
DiskSpd(dlg, TEST_WRITE_4); Interval(dlg);
DiskSpd(dlg, TEST_WRITE_5);
}
#ifdef MIX_MODE
if (MixMode)
{
Interval(dlg);
DiskSpd(dlg, TEST_MIX_4); Interval(dlg);
DiskSpd(dlg, TEST_MIX_5);
}
#endif
}
return Exit(dlg);
}
UINT ExecDiskBenchAllReal(LPVOID dlg)
{
int benchmark = ((CDiskMarkDlg*)dlg)->m_Benchmark;
if (Init(dlg))
{
if (benchmark & BENCHMARK_READ)
{
DiskSpd(dlg, TEST_READ_6); Interval(dlg);
DiskSpd(dlg, TEST_READ_7);
}
if ((benchmark & BENCHMARK_READ) && (benchmark & BENCHMARK_WRITE))
{
Interval(dlg);
}
if (benchmark & BENCHMARK_WRITE)
{
DiskSpd(dlg, TEST_WRITE_6); Interval(dlg);
DiskSpd(dlg, TEST_WRITE_7);
}
#ifdef MIX_MODE
if (MixMode)
{
Interval(dlg);
DiskSpd(dlg, TEST_MIX_6); Interval(dlg);
DiskSpd(dlg, TEST_MIX_7);
}
#endif
}
return Exit(dlg);
}
UINT ExecDiskBenchAllDemo(LPVOID dlg)
{
int benchmark = ((CDiskMarkDlg*)dlg)->m_Benchmark;
if (Init(dlg))
{
if (benchmark & BENCHMARK_READ)
{
DiskSpd(dlg, TEST_READ_8);
}
if ((benchmark & BENCHMARK_READ) && (benchmark & BENCHMARK_WRITE))
{
Interval(dlg);
}
if (benchmark & BENCHMARK_WRITE)
{
DiskSpd(dlg, TEST_WRITE_8);
}
}
return Exit(dlg);
}
UINT ExecDiskBench0(LPVOID dlg)
{
int benchmark = ((CDiskMarkDlg*)dlg)->m_Benchmark;
if (Init(dlg))
{
if (benchmark & BENCHMARK_READ)
{
DiskSpd(dlg, TEST_READ_0);
}
if ((benchmark & BENCHMARK_READ) && (benchmark & BENCHMARK_WRITE))
{
Interval(dlg);
}
if (benchmark & BENCHMARK_WRITE)
{
DiskSpd(dlg, TEST_WRITE_0);
}
#ifdef MIX_MODE
if (MixMode)
{
Interval(dlg);
DiskSpd(dlg, TEST_MIX_0);
}
#endif
}
return Exit(dlg);
}
UINT ExecDiskBench1(LPVOID dlg)
{
int benchmark = ((CDiskMarkDlg*)dlg)->m_Benchmark;
if (Init(dlg))
{
if (benchmark & BENCHMARK_READ)
{
DiskSpd(dlg, TEST_READ_1);
}
if ((benchmark & BENCHMARK_READ) && (benchmark & BENCHMARK_WRITE))
{
Interval(dlg);
}
if (benchmark & BENCHMARK_WRITE)
{
DiskSpd(dlg, TEST_WRITE_1);
}
#ifdef MIX_MODE
if (MixMode)
{
Interval(dlg);
DiskSpd(dlg, TEST_MIX_1);
}
#endif
}
return Exit(dlg);
}
UINT ExecDiskBench2(LPVOID dlg)
{
int benchmark = ((CDiskMarkDlg*)dlg)->m_Benchmark;
if (Init(dlg))
{
if (benchmark & BENCHMARK_READ)
{
DiskSpd(dlg, TEST_READ_2);
}
if ((benchmark & BENCHMARK_READ) && (benchmark & BENCHMARK_WRITE))
{
Interval(dlg);
}
if (benchmark & BENCHMARK_WRITE)
{
DiskSpd(dlg, TEST_WRITE_2);
}
#ifdef MIX_MODE
if (MixMode)
{
Interval(dlg);
DiskSpd(dlg, TEST_MIX_2);
}
#endif
}
return Exit(dlg);
}
UINT ExecDiskBench3(LPVOID dlg)
{
int benchmark = ((CDiskMarkDlg*)dlg)->m_Benchmark;
if (Init(dlg))
{
if (benchmark & BENCHMARK_READ)
{
DiskSpd(dlg, TEST_READ_3);
}
if ((benchmark & BENCHMARK_READ) && (benchmark & BENCHMARK_WRITE))
{
Interval(dlg);
}
if (benchmark & BENCHMARK_WRITE)
{
DiskSpd(dlg, TEST_WRITE_3);
}
#ifdef MIX_MODE
if (MixMode)
{
Interval(dlg);
DiskSpd(dlg, TEST_MIX_3);
}
#endif
}
return Exit(dlg);
}
UINT ExecDiskBench4(LPVOID dlg)
{
int benchmark = ((CDiskMarkDlg*)dlg)->m_Benchmark;
if (Init(dlg))
{
if (benchmark & BENCHMARK_READ)
{
DiskSpd(dlg, TEST_READ_4);
}
if ((benchmark & BENCHMARK_READ) && (benchmark & BENCHMARK_WRITE))
{
Interval(dlg);
}
if (benchmark & BENCHMARK_WRITE)
{
DiskSpd(dlg, TEST_WRITE_4);
}
#ifdef MIX_MODE
if (MixMode)
{
Interval(dlg);
DiskSpd(dlg, TEST_MIX_4);
}
#endif
}
return Exit(dlg);
}
UINT ExecDiskBench5(LPVOID dlg)
{
int benchmark = ((CDiskMarkDlg*)dlg)->m_Benchmark;
if (Init(dlg))
{
if (benchmark & BENCHMARK_READ)
{
DiskSpd(dlg, TEST_READ_5);
}
if ((benchmark & BENCHMARK_READ) && (benchmark & BENCHMARK_WRITE))
{
Interval(dlg);
}
if (benchmark & BENCHMARK_WRITE)
{
DiskSpd(dlg, TEST_WRITE_5);
}
#ifdef MIX_MODE
if (MixMode)
{
Interval(dlg);
DiskSpd(dlg, TEST_MIX_5);
}
#endif
}
return Exit(dlg);
}
UINT ExecDiskBench6(LPVOID dlg)
{
int benchmark = ((CDiskMarkDlg*)dlg)->m_Benchmark;
if (Init(dlg))
{
if (benchmark & BENCHMARK_READ)
{
DiskSpd(dlg, TEST_READ_6);
}
if ((benchmark & BENCHMARK_READ) && (benchmark & BENCHMARK_WRITE))
{
Interval(dlg);
}
if (benchmark & BENCHMARK_WRITE)
{
DiskSpd(dlg, TEST_WRITE_6);
}
#ifdef MIX_MODE
if (MixMode)
{
Interval(dlg);
DiskSpd(dlg, TEST_MIX_6);
}
#endif
}
return Exit(dlg);
}
UINT ExecDiskBench7(LPVOID dlg)
{
int benchmark = ((CDiskMarkDlg*)dlg)->m_Benchmark;
if (Init(dlg))
{
if (benchmark & BENCHMARK_READ)
{
DiskSpd(dlg, TEST_READ_7);
}
if ((benchmark & BENCHMARK_READ) && (benchmark & BENCHMARK_WRITE))
{
Interval(dlg);
}
if (benchmark & BENCHMARK_WRITE)
{
DiskSpd(dlg, TEST_WRITE_7);
}
#ifdef MIX_MODE
if (MixMode)
{
Interval(dlg);
DiskSpd(dlg, TEST_MIX_7);
}
#endif
}
return Exit(dlg);
}
BOOL Init(void* dlg)
{
BOOL FlagArc;
BOOL result;
static CString cstr;
TCHAR drive;
ULARGE_INTEGER freeBytesAvailableToCaller;
ULARGE_INTEGER totalNumberOfBytes;
ULARGE_INTEGER totalNumberOfFreeBytes;
// Init m_Ini
TCHAR *ptrEnd;
TCHAR temp[MAX_PATH];
::GetModuleFileName(NULL, temp, MAX_PATH);
if ((ptrEnd = _tcsrchr(temp, '\\')) != NULL)
{
*ptrEnd = '\0';
}
pi.hProcess = NULL;
#ifdef _M_ARM
DiskSpdExe.Format(L"%s\\%s", temp, DISK_SPD_EXE_ARM32);
#elif _M_ARM64
DiskSpdExe.Format(L"%s\\%s", temp, DISK_SPD_EXE_ARM64);
#elif _M_X64
if(IsWin8orLater())
{
DiskSpdExe.Format(L"%s\\%s", temp, DISK_SPD_EXE_64);
}
else
{
DiskSpdExe.Format(L"%s\\%s", temp, DISK_SPD_EXE_64_LEGACY);
}
#else
if (IsWin8orLater())
{
DiskSpdExe.Format(L"%s\\%s", temp, DISK_SPD_EXE_32);
}
else
{
DiskSpdExe.Format(L"%s\\%s", temp, DISK_SPD_EXE_32_LEGACY);
}
#endif
if (! IsFileExist(DiskSpdExe))
{
AfxMessageBox(((CDiskMarkDlg*) dlg)->m_MesDiskSpdNotFound);
((CDiskMarkDlg*) dlg)->m_DiskBenchStatus = FALSE;
return FALSE;
}
DiskTestCount = ((CDiskMarkDlg*) dlg)->m_IndexTestCount + 1;
CString testSize = ((CDiskMarkDlg*)dlg)->m_ValueTestSize;
if (testSize.Find(L"M") == -1) // GiB
{
DiskTestSize = (UINT64)_tstoi(testSize) * 1024;
}
else // MiB
{
DiskTestSize = (UINT64)_tstoi(testSize);
}
for (int i = 0; i < 9; i++)
{
BenchType[i] = ((CDiskMarkDlg*)dlg)->m_BenchType[i];
BenchSize[i] = ((CDiskMarkDlg*)dlg)->m_BenchSize[i];
BenchQueues[i] = ((CDiskMarkDlg*)dlg)->m_BenchQueues[i];
BenchThreads[i] = ((CDiskMarkDlg*)dlg)->m_BenchThreads[i];
}
MixMode = ((CDiskMarkDlg*)dlg)->m_MixMode;
MixRatio = ((CDiskMarkDlg*)dlg)->m_MixRatio;
CString RootPath;
if(((CDiskMarkDlg*)dlg)->m_MaxIndexTestDrive != ((CDiskMarkDlg*)dlg)->m_IndexTestDrive)
{
drive = ((CDiskMarkDlg*)dlg)->m_ValueTestDrive.GetAt(0);
cstr.Format(L"%C:", drive);
GetDiskFreeSpaceEx(cstr, &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes);
if (totalNumberOfBytes.QuadPart < ((ULONGLONG)8 * 1024 * 1024 * 1024)) // < 8 GB
{
((CDiskMarkDlg*)dlg)->m_TestDriveInfo.Format(L"%C: %.1f%% (%.1f/%.1f MiB)", drive,
(double)(totalNumberOfBytes.QuadPart - totalNumberOfFreeBytes.QuadPart) / (double)totalNumberOfBytes.QuadPart * 100,
(totalNumberOfBytes.QuadPart - totalNumberOfFreeBytes.QuadPart) / 1024 / 1024.0,
totalNumberOfBytes.QuadPart / 1024 / 1024.0);
}
else
{
((CDiskMarkDlg*)dlg)->m_TestDriveInfo.Format(L"%C: %.1f%% (%.1f/%.1f GiB)", drive,
(double)(totalNumberOfBytes.QuadPart - totalNumberOfFreeBytes.QuadPart) / (double)totalNumberOfBytes.QuadPart * 100,
(totalNumberOfBytes.QuadPart - totalNumberOfFreeBytes.QuadPart) / 1024 / 1024 / 1024.0,
totalNumberOfBytes.QuadPart / 1024 / 1024 / 1024.0);
}
RootPath.Format(L"%c:\\", drive);
}
else
{
RootPath = ((CDiskMarkDlg*)dlg)->m_TestTargetPath;
RootPath += L"\\";
}
TestFileDir.Format(L"%sCrystalDiskMark%08X", (LPTSTR)RootPath.GetString(), timeGetTime());
CreateDirectory(TestFileDir, NULL);
TestFilePath.Format(L"%s\\CrystalDiskMark%08X.tmp", (LPTSTR)TestFileDir.GetString(), timeGetTime());
DWORD FileSystemFlags;
GetVolumeInformation(RootPath, NULL, NULL, NULL, NULL, &FileSystemFlags, NULL, NULL);
if(FileSystemFlags & FS_VOL_IS_COMPRESSED)
{
FlagArc = TRUE;
}
else
{
FlagArc = FALSE;
}
// Check Disk Capacity //
OSVERSIONINFO osVersionInfo;
osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osVersionInfo);
ULARGE_INTEGER FreeBytesAvailableToCaller, TotalNumberOfBytes, TotalNumberOfFreeBytes;
GetDiskFreeSpaceEx(RootPath, &FreeBytesAvailableToCaller, &TotalNumberOfBytes, &TotalNumberOfFreeBytes);
if(DiskTestSize > TotalNumberOfFreeBytes.QuadPart / 1024 / 1024 )
{
AfxMessageBox(((CDiskMarkDlg*)dlg)->m_MesDiskCapacityError);
((CDiskMarkDlg*)dlg)->m_DiskBenchStatus = FALSE;
return FALSE;
}
CString title;
title.Format(L"Preparing... Create Test File");
::PostMessage(((CDiskMarkDlg*)dlg)->GetSafeHwnd(), WM_UPDATE_MESSAGE, (WPARAM)& title, 0);
// Preapare Test File
hFile = ::CreateFile(TestFilePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_NO_BUFFERING|FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
AfxMessageBox(((CDiskMarkDlg*)dlg)->m_MesDiskCreateFileError);
((CDiskMarkDlg*)dlg)->m_DiskBenchStatus = FALSE;
return FALSE;
}
// Set End Of File to prevent fragmentation of test file
LARGE_INTEGER nFileSize;
nFileSize.QuadPart = 1024 * 1024 * DiskTestSize;
LARGE_INTEGER nStart;
nStart.QuadPart = 0;
SetFilePointerEx(hFile, nFileSize, NULL, FILE_BEGIN);
SetEndOfFile(hFile);
SetFilePointerEx(hFile, nStart, NULL, FILE_BEGIN);
// COMPRESSION_FORMAT_NONE
USHORT lpInBuffer = COMPRESSION_FORMAT_NONE;
DWORD lpBytesReturned = 0;
DeviceIoControl(hFile, FSCTL_SET_COMPRESSION, (LPVOID) &lpInBuffer,
sizeof(USHORT), NULL, 0, (LPDWORD)&lpBytesReturned, NULL);
// Fill Test Data
char* buf = NULL;
int BufSize;
int Loop;
int i;
DWORD writesize;
BufSize = 1024 * 1024;
Loop = (int)DiskTestSize;
buf = (char*) VirtualAlloc(NULL, BufSize, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if (buf == NULL)
{
AfxMessageBox(L"Failed VirtualAlloc().");
((CDiskMarkDlg*) dlg)->m_DiskBenchStatus = FALSE;
return FALSE;
}
if (((CDiskMarkDlg*) dlg)->m_TestData == TEST_DATA_ALL0X00)
{
for (i = 0; i < BufSize; i++)
{
buf[i] = 0;
}
}
else
{
// Compatible with DiskSpd
for (i = 0; i < BufSize; i++)
{
buf[i] = (char) (rand() % 256);
}
}
for (i = 0; i < Loop; i++)
{
if (((CDiskMarkDlg*) dlg)->m_DiskBenchStatus)
{
result = WriteFile(hFile, buf, BufSize, &writesize, NULL);
}
else
{
CloseHandle(hFile);
VirtualFree(buf, 0, MEM_RELEASE);
((CDiskMarkDlg*) dlg)->m_DiskBenchStatus = FALSE;
return FALSE;
}
}
VirtualFree(buf, 0, MEM_RELEASE);
CloseHandle(hFile);
return TRUE;
}
void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
if(idEvent == TIMER_ID)
{
WaitFlag = FALSE;
KillTimer(hwnd, idEvent);
}
}
UINT Exit(void* dlg)
{
DeleteFile(TestFilePath);
RemoveDirectory(TestFileDir);
static CString cstr;
cstr = L"";
if(((CDiskMarkDlg*)dlg)->m_TestData == TEST_DATA_ALL0X00)
{
cstr = ALL_0X00_0FILL;
}
::PostMessage(((CDiskMarkDlg*)dlg)->GetSafeHwnd(), WM_UPDATE_MESSAGE, NULL, (LPARAM)&cstr);
::PostMessage(((CDiskMarkDlg*)dlg)->GetSafeHwnd(), WM_EXIT_BENCHMARK, 0, 0);
((CDiskMarkDlg*)dlg)->m_DiskBenchStatus = FALSE;
((CDiskMarkDlg*)dlg)->m_WinThread = NULL;
return 0;
}
void DiskSpd(void* dlg, DISK_SPD_CMD cmd)
{
static CString cstr;
double *maxScore = NULL;
double *minLatency = NULL;
CString command;
CString title;
CString option;
CString bufOption;
int duration = 5;
int index = 0;
int j = 0;
if (!((CDiskMarkDlg*) dlg)->m_DiskBenchStatus)
{
return;
}
if (((CDiskMarkDlg*) dlg)->m_TestData == TEST_DATA_ALL0X00)
{
bufOption += L" -Z";
}
else
{
switch (cmd)
{
case TEST_WRITE_0:
case TEST_WRITE_1:
case TEST_WRITE_2:
case TEST_WRITE_3:
case TEST_WRITE_4:
case TEST_WRITE_5:
case TEST_WRITE_6:
case TEST_WRITE_7:
case TEST_WRITE_8:
index = cmd - TEST_WRITE_0;
cstr.Format(L" -Z%dK", BenchSize[index]);
bufOption += cstr;
break;
case TEST_MIX_0:
case TEST_MIX_1:
case TEST_MIX_2:
case TEST_MIX_3:
case TEST_MIX_4:
case TEST_MIX_5:
case TEST_MIX_6:
case TEST_MIX_7:
case TEST_MIX_8:
index = cmd - TEST_MIX_0;
cstr.Format(L" -Z%dK", BenchSize[index]);
bufOption += cstr;
break;
}
}
switch (cmd)
{
case TEST_READ_0:
case TEST_READ_1:
case TEST_READ_2:
case TEST_READ_3:
case TEST_READ_4:
case TEST_READ_5:
case TEST_READ_6:
case TEST_READ_7:
case TEST_READ_8:
index = cmd - TEST_READ_0;
if (BenchType[index])
{
title.Format(L"Random Read");
option.Format(L"-b%dK -o%d -t%d -W0 -S -w0 -r", BenchSize[index], BenchQueues[index], BenchThreads[index]);
}
else
{
title.Format(L"Sequential Read");
option.Format(L"-b%dK -o%d -t%d -W0 -S -w0", BenchSize[index], BenchQueues[index], BenchThreads[index]);
}
maxScore = &(((CDiskMarkDlg*) dlg)->m_ReadScore[index]);
minLatency = &(((CDiskMarkDlg*)dlg)->m_ReadLatency[index]);
break;
case TEST_WRITE_0:
case TEST_WRITE_1:
case TEST_WRITE_2:
case TEST_WRITE_3:
case TEST_WRITE_4:
case TEST_WRITE_5:
case TEST_WRITE_6:
case TEST_WRITE_7:
case TEST_WRITE_8:
index = cmd - TEST_WRITE_0;
if (BenchType[index])
{
title.Format(L"Random Write");
option.Format(L"-b%dK -o%d -t%d -W0 -S -w100 -r", BenchSize[index], BenchQueues[index], BenchThreads[index]);
}
else
{
title.Format(L"Sequential Write");
option.Format(L"-b%dK -o%d -t%d -W0 -S -w100", BenchSize[index], BenchQueues[index], BenchThreads[index]);
}
option += bufOption;
maxScore = &(((CDiskMarkDlg*)dlg)->m_WriteScore[index]);
minLatency = &(((CDiskMarkDlg*)dlg)->m_WriteLatency[index]);
break;
#ifdef MIX_MODE
case TEST_MIX_0:
case TEST_MIX_1:
case TEST_MIX_2:
case TEST_MIX_3:
case TEST_MIX_4:
case TEST_MIX_5:
case TEST_MIX_6:
case TEST_MIX_7:
case TEST_MIX_8:
index = cmd - TEST_MIX_0;
if (BenchType[index])
{
title.Format(L"Random Mix");
option.Format(L"-b%dK -o%d -t%d -W0 -S -w%d -r", BenchSize[index], BenchQueues[index], BenchThreads[index], MixRatio);
}
else
{
title.Format(L"Sequential Mix");
option.Format(L"-b%dK -o%d -t%d -W0 -S -w%d", BenchSize[index], BenchQueues[index], BenchThreads[index], MixRatio);
}
option += bufOption;
maxScore = &(((CDiskMarkDlg*)dlg)->m_MixScore[index]);
minLatency = &(((CDiskMarkDlg*)dlg)->m_MixLatency[index]);
break;
#endif
}
option += L" -ag";
double score = 0.0;
double latency = 0.0;
if (maxScore == NULL || minLatency == NULL)
{
return ;
}
*maxScore = 0.0;
*minLatency = -1.0;
for (j = 0; j <= DiskTestCount; j++)
{
if (j == 0)
{
duration = 5;
cstr.Format(L"Preparing... %s", title.GetString());
}
else
{
duration = ((CDiskMarkDlg*)dlg)->m_MeasureTime;
cstr.Format(L"%s (%d/%d)", title.GetString(), j, DiskTestCount);
}
::PostMessage(((CDiskMarkDlg*) dlg)->GetSafeHwnd(), WM_UPDATE_MESSAGE, (WPARAM) &cstr, 0);
command.Format(L"\"%s\" %s -d%d -A%d -L \"%s\"", (LPTSTR)DiskSpdExe.GetString(), (LPTSTR)option.GetString(), duration, GetCurrentProcessId(), (LPTSTR)TestFilePath.GetString());
score = ExecAndWait((TCHAR*) (command.GetString()), TRUE, &latency) / 10 / 1000.0;
if (j > 0 && score > *maxScore)
{
*maxScore = score;
::PostMessage(((CDiskMarkDlg*) dlg)->GetSafeHwnd(), WM_UPDATE_SCORE, 0, 0);
}
if (j > 0 && score > 0.0 && (latency < *minLatency || *minLatency < 0))
{
*minLatency = latency;
::PostMessage(((CDiskMarkDlg*)dlg)->GetSafeHwnd(), WM_UPDATE_SCORE, 0, 0);
}
if (!((CDiskMarkDlg*) dlg)->m_DiskBenchStatus)
{
return;
}
}
::PostMessage(((CDiskMarkDlg*) dlg)->GetSafeHwnd(), WM_UPDATE_SCORE, 0, 0);
}