mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Use a more precise mechanism to measure elapsed times in operations.
This commit is contained in:
@@ -102,8 +102,6 @@ public sealed partial class MediaScan
|
||||
results.E = 0; // >=150ms, <500ms
|
||||
results.F = 0; // >=500ms
|
||||
results.Errored = 0;
|
||||
DateTime start;
|
||||
DateTime end;
|
||||
results.ProcessingTime = 0;
|
||||
double currentSpeed = 0;
|
||||
results.MaxSpeed = double.MinValue;
|
||||
@@ -130,8 +128,8 @@ public sealed partial class MediaScan
|
||||
mhddLog = new MhddLog(_mhddLogPath, _dev, results.Blocks, blockSize, blocksToRead, false);
|
||||
ibgLog = new IbgLog(_ibgLogPath, ataProfile);
|
||||
|
||||
start = DateTime.UtcNow;
|
||||
DateTime timeSpeedStart = DateTime.UtcNow;
|
||||
_scanStopwatch.Restart();
|
||||
_speedStopwatch.Restart();
|
||||
ulong sectorSpeedStart = 0;
|
||||
InitProgress?.Invoke();
|
||||
|
||||
@@ -206,7 +204,7 @@ public sealed partial class MediaScan
|
||||
|
||||
sectorSpeedStart += blocksToRead;
|
||||
|
||||
double elapsed = (DateTime.UtcNow - timeSpeedStart).TotalSeconds;
|
||||
double elapsed = _speedStopwatch.Elapsed.TotalSeconds;
|
||||
|
||||
if(elapsed <= 0)
|
||||
continue;
|
||||
@@ -214,14 +212,15 @@ public sealed partial class MediaScan
|
||||
currentSpeed = sectorSpeedStart * blockSize / (1048576 * elapsed);
|
||||
ScanSpeed?.Invoke(i, currentSpeed * 1024);
|
||||
sectorSpeedStart = 0;
|
||||
timeSpeedStart = DateTime.UtcNow;
|
||||
_speedStopwatch.Restart();
|
||||
}
|
||||
|
||||
end = DateTime.UtcNow;
|
||||
_speedStopwatch.Stop();
|
||||
_scanStopwatch.Stop();
|
||||
EndProgress?.Invoke();
|
||||
mhddLog.Close();
|
||||
|
||||
ibgLog.Close(_dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
|
||||
ibgLog.Close(_dev, results.Blocks, blockSize, _scanStopwatch.Elapsed.TotalSeconds, currentSpeed * 1024,
|
||||
blockSize * (double)(results.Blocks + 1) / 1024 / (results.ProcessingTime / 1000),
|
||||
_devicePath);
|
||||
|
||||
@@ -261,8 +260,8 @@ public sealed partial class MediaScan
|
||||
|
||||
ulong currentBlock = 0;
|
||||
results.Blocks = (ulong)(cylinders * heads * sectors);
|
||||
start = DateTime.UtcNow;
|
||||
DateTime timeSpeedStart = DateTime.UtcNow;
|
||||
_scanStopwatch.Restart();
|
||||
_speedStopwatch.Restart();
|
||||
ulong sectorSpeedStart = 0;
|
||||
InitProgress?.Invoke();
|
||||
|
||||
@@ -337,7 +336,7 @@ public sealed partial class MediaScan
|
||||
sectorSpeedStart++;
|
||||
currentBlock++;
|
||||
|
||||
double elapsed = (DateTime.UtcNow - timeSpeedStart).TotalSeconds;
|
||||
double elapsed = _speedStopwatch.Elapsed.TotalSeconds;
|
||||
|
||||
if(elapsed <= 0)
|
||||
continue;
|
||||
@@ -345,16 +344,17 @@ public sealed partial class MediaScan
|
||||
currentSpeed = sectorSpeedStart * blockSize / (1048576 * elapsed);
|
||||
ScanSpeed?.Invoke(currentBlock, currentSpeed * 1024);
|
||||
sectorSpeedStart = 0;
|
||||
timeSpeedStart = DateTime.UtcNow;
|
||||
_speedStopwatch.Restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end = DateTime.UtcNow;
|
||||
_speedStopwatch.Stop();
|
||||
_scanStopwatch.Stop();
|
||||
EndProgress?.Invoke();
|
||||
mhddLog.Close();
|
||||
|
||||
ibgLog.Close(_dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
|
||||
ibgLog.Close(_dev, results.Blocks, blockSize, _scanStopwatch.Elapsed.TotalSeconds, currentSpeed * 1024,
|
||||
blockSize * (double)(results.Blocks + 1) / 1024 / (results.ProcessingTime / 1000),
|
||||
_devicePath);
|
||||
|
||||
@@ -391,7 +391,7 @@ public sealed partial class MediaScan
|
||||
}
|
||||
|
||||
results.ProcessingTime /= 1000;
|
||||
results.TotalTime = (end - start).TotalSeconds;
|
||||
results.TotalTime = _scanStopwatch.Elapsed.TotalSeconds;
|
||||
results.AvgSpeed = blockSize * (double)(results.Blocks + 1) / 1048576 / results.ProcessingTime;
|
||||
results.SeekTimes = seekTimes;
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
// ****************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Aaru.CommonTypes;
|
||||
using Aaru.CommonTypes.Enums;
|
||||
using Aaru.Devices;
|
||||
@@ -40,14 +41,16 @@ namespace Aaru.Core.Devices.Scanning;
|
||||
|
||||
public sealed partial class MediaScan
|
||||
{
|
||||
readonly Device _dev;
|
||||
readonly string _devicePath;
|
||||
readonly string _ibgLogPath;
|
||||
readonly string _mhddLogPath;
|
||||
readonly bool _seekTest;
|
||||
readonly bool _useBufferedReads;
|
||||
bool _aborted;
|
||||
static readonly TimeSpan _oneSecond = 1.Seconds();
|
||||
readonly Device _dev;
|
||||
readonly string _devicePath;
|
||||
readonly string _ibgLogPath;
|
||||
readonly string _mhddLogPath;
|
||||
readonly bool _seekTest;
|
||||
readonly bool _useBufferedReads;
|
||||
bool _aborted;
|
||||
static readonly TimeSpan _oneSecond = 1.Seconds();
|
||||
readonly Stopwatch _scanStopwatch;
|
||||
readonly Stopwatch _speedStopwatch;
|
||||
|
||||
/// <param name="mhddLogPath">Path to a MHDD log file</param>
|
||||
/// <param name="ibgLogPath">Path to a IMGBurn log file</param>
|
||||
@@ -68,6 +71,8 @@ public sealed partial class MediaScan
|
||||
_aborted = false;
|
||||
_seekTest = seekTest;
|
||||
_useBufferedReads = useBufferedReads;
|
||||
_scanStopwatch = new Stopwatch();
|
||||
_speedStopwatch = new Stopwatch();
|
||||
}
|
||||
|
||||
/// <summary>Starts a media scan</summary>
|
||||
|
||||
@@ -276,8 +276,6 @@ public sealed partial class MediaScan
|
||||
results.E = 0; // >=150ms, <500ms
|
||||
results.F = 0; // >=500ms
|
||||
results.Errored = 0;
|
||||
DateTime start;
|
||||
DateTime end;
|
||||
results.ProcessingTime = 0;
|
||||
results.TotalTime = 0;
|
||||
double currentSpeed = 0;
|
||||
@@ -309,7 +307,7 @@ public sealed partial class MediaScan
|
||||
return results;
|
||||
}
|
||||
|
||||
start = DateTime.UtcNow;
|
||||
_scanStopwatch.Restart();
|
||||
|
||||
if(readcd)
|
||||
while(true)
|
||||
@@ -340,7 +338,7 @@ public sealed partial class MediaScan
|
||||
InitBlockMap?.Invoke(results.Blocks, blockSize, blocksToRead, currentProfile);
|
||||
mhddLog = new MhddLog(_mhddLogPath, _dev, results.Blocks, blockSize, blocksToRead, false);
|
||||
ibgLog = new IbgLog(_ibgLogPath, currentProfile);
|
||||
DateTime timeSpeedStart = DateTime.UtcNow;
|
||||
_speedStopwatch.Restart();
|
||||
ulong sectorSpeedStart = 0;
|
||||
|
||||
InitProgress?.Invoke();
|
||||
@@ -459,7 +457,7 @@ public sealed partial class MediaScan
|
||||
|
||||
sectorSpeedStart += blocksToRead;
|
||||
|
||||
double elapsed = (DateTime.UtcNow - timeSpeedStart).TotalSeconds;
|
||||
double elapsed = _speedStopwatch.Elapsed.TotalSeconds;
|
||||
|
||||
if(elapsed <= 0)
|
||||
continue;
|
||||
@@ -467,14 +465,15 @@ public sealed partial class MediaScan
|
||||
currentSpeed = sectorSpeedStart * blockSize / (1048576 * elapsed);
|
||||
ScanSpeed?.Invoke(i, currentSpeed * 1024);
|
||||
sectorSpeedStart = 0;
|
||||
timeSpeedStart = DateTime.UtcNow;
|
||||
_speedStopwatch.Restart();
|
||||
}
|
||||
|
||||
end = DateTime.UtcNow;
|
||||
_speedStopwatch.Stop();
|
||||
_scanStopwatch.Stop();
|
||||
EndProgress?.Invoke();
|
||||
mhddLog.Close();
|
||||
|
||||
currentSpeed = sectorSpeedStart * blockSize / (1048576 * (end - timeSpeedStart).TotalSeconds);
|
||||
currentSpeed = sectorSpeedStart * blockSize / (1048576 * _speedStopwatch.Elapsed.TotalSeconds);
|
||||
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
if(results.MaxSpeed == double.MinValue)
|
||||
@@ -484,20 +483,20 @@ public sealed partial class MediaScan
|
||||
if(results.MinSpeed == double.MaxValue)
|
||||
results.MinSpeed = currentSpeed;
|
||||
|
||||
ibgLog.Close(_dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
|
||||
ibgLog.Close(_dev, results.Blocks, blockSize, _scanStopwatch.Elapsed.TotalSeconds, currentSpeed * 1024,
|
||||
blockSize * (double)(results.Blocks + 1) / 1024 / (results.ProcessingTime / 1000),
|
||||
_devicePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
start = DateTime.UtcNow;
|
||||
_scanStopwatch.Restart();
|
||||
|
||||
UpdateStatus?.Invoke(string.Format(Localization.Core.Reading_0_sectors_at_a_time, scsiReader.BlocksToRead));
|
||||
|
||||
InitBlockMap?.Invoke(results.Blocks, blockSize, scsiReader.BlocksToRead, currentProfile);
|
||||
mhddLog = new MhddLog(_mhddLogPath, _dev, results.Blocks, blockSize, scsiReader.BlocksToRead, false);
|
||||
ibgLog = new IbgLog(_ibgLogPath, currentProfile);
|
||||
DateTime timeSpeedStart = DateTime.UtcNow;
|
||||
_speedStopwatch.Restart();
|
||||
ulong sectorSpeedStart = 0;
|
||||
|
||||
InitProgress?.Invoke();
|
||||
@@ -578,7 +577,7 @@ public sealed partial class MediaScan
|
||||
|
||||
sectorSpeedStart += blocksToRead;
|
||||
|
||||
double elapsed = (DateTime.UtcNow - timeSpeedStart).TotalSeconds;
|
||||
double elapsed = _speedStopwatch.Elapsed.TotalSeconds;
|
||||
|
||||
if(elapsed <= 0)
|
||||
continue;
|
||||
@@ -586,14 +585,15 @@ public sealed partial class MediaScan
|
||||
currentSpeed = sectorSpeedStart * blockSize / (1048576 * elapsed);
|
||||
ScanSpeed?.Invoke(i, currentSpeed * 1024);
|
||||
sectorSpeedStart = 0;
|
||||
timeSpeedStart = DateTime.UtcNow;
|
||||
_speedStopwatch.Restart();
|
||||
}
|
||||
|
||||
end = DateTime.UtcNow;
|
||||
_speedStopwatch.Stop();
|
||||
_scanStopwatch.Stop();
|
||||
EndProgress?.Invoke();
|
||||
mhddLog.Close();
|
||||
|
||||
ibgLog.Close(_dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
|
||||
ibgLog.Close(_dev, results.Blocks, blockSize, _scanStopwatch.Elapsed.TotalSeconds, currentSpeed * 1024,
|
||||
blockSize * (double)(results.Blocks + 1) / 1024 / (results.ProcessingTime / 1000),
|
||||
_devicePath);
|
||||
}
|
||||
@@ -642,7 +642,7 @@ public sealed partial class MediaScan
|
||||
EndProgress?.Invoke();
|
||||
|
||||
results.ProcessingTime /= 1000;
|
||||
results.TotalTime = (end - start).TotalSeconds;
|
||||
results.TotalTime = _scanStopwatch.Elapsed.TotalSeconds;
|
||||
results.AvgSpeed = blockSize * (double)(results.Blocks + 1) / 1048576 / results.ProcessingTime;
|
||||
results.SeekTimes = seekTimes;
|
||||
|
||||
|
||||
@@ -196,8 +196,6 @@ public sealed partial class MediaScan
|
||||
results.E = 0; // >=150ms, <500ms
|
||||
results.F = 0; // >=500ms
|
||||
results.Errored = 0;
|
||||
DateTime start;
|
||||
DateTime end;
|
||||
results.ProcessingTime = 0;
|
||||
double currentSpeed = 0;
|
||||
results.MaxSpeed = double.MinValue;
|
||||
@@ -223,8 +221,8 @@ public sealed partial class MediaScan
|
||||
var mhddLog = new MhddLog(_mhddLogPath, _dev, results.Blocks, blockSize, blocksToRead, false);
|
||||
var ibgLog = new IbgLog(_ibgLogPath, sdProfile);
|
||||
|
||||
start = DateTime.UtcNow;
|
||||
DateTime timeSpeedStart = DateTime.UtcNow;
|
||||
_scanStopwatch.Restart();
|
||||
_speedStopwatch.Restart();
|
||||
ulong sectorSpeedStart = 0;
|
||||
InitProgress?.Invoke();
|
||||
|
||||
@@ -311,7 +309,7 @@ public sealed partial class MediaScan
|
||||
|
||||
sectorSpeedStart += blocksToRead;
|
||||
|
||||
double elapsed = (DateTime.UtcNow - timeSpeedStart).TotalSeconds;
|
||||
double elapsed = _speedStopwatch.Elapsed.TotalSeconds;
|
||||
|
||||
if(elapsed <= 0)
|
||||
continue;
|
||||
@@ -319,14 +317,15 @@ public sealed partial class MediaScan
|
||||
currentSpeed = sectorSpeedStart * blockSize / (1048576 * elapsed);
|
||||
ScanSpeed?.Invoke(i, currentSpeed * 1024);
|
||||
sectorSpeedStart = 0;
|
||||
timeSpeedStart = DateTime.UtcNow;
|
||||
_speedStopwatch.Restart();
|
||||
}
|
||||
|
||||
end = DateTime.UtcNow;
|
||||
_speedStopwatch.Stop();
|
||||
_scanStopwatch.Stop();
|
||||
EndProgress?.Invoke();
|
||||
mhddLog.Close();
|
||||
|
||||
ibgLog.Close(_dev, results.Blocks, blockSize, (end - start).TotalSeconds, currentSpeed * 1024,
|
||||
ibgLog.Close(_dev, results.Blocks, blockSize, _scanStopwatch.Elapsed.TotalSeconds, currentSpeed * 1024,
|
||||
blockSize * (double)(results.Blocks + 1) / 1024 / (results.ProcessingTime / 1000), _devicePath);
|
||||
|
||||
InitProgress?.Invoke();
|
||||
@@ -357,7 +356,7 @@ public sealed partial class MediaScan
|
||||
EndProgress?.Invoke();
|
||||
|
||||
results.ProcessingTime /= 1000;
|
||||
results.TotalTime = (end - start).TotalSeconds;
|
||||
results.TotalTime = _scanStopwatch.Elapsed.TotalSeconds;
|
||||
results.AvgSpeed = blockSize * (double)(results.Blocks + 1) / 1048576 / results.ProcessingTime;
|
||||
results.SeekTimes = seekTimes;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user