mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Media scan] Change speed calculation algorithm for one more stable and with less spikes.
This commit is contained in:
@@ -57,8 +57,8 @@ public sealed partial class MediaScan
|
||||
const ushort sdProfile = 0x0001;
|
||||
ushort blocksToRead = 128;
|
||||
uint blockSize = 512;
|
||||
bool byteAddressed = true;
|
||||
bool supportsCmd23 = false;
|
||||
var byteAddressed = true;
|
||||
var supportsCmd23 = false;
|
||||
|
||||
switch(_dev.Type)
|
||||
{
|
||||
@@ -214,9 +214,7 @@ public sealed partial class MediaScan
|
||||
var rnd = new Random();
|
||||
|
||||
if(supportsCmd23 || blocksToRead == 1)
|
||||
{
|
||||
UpdateStatus?.Invoke(string.Format(Localization.Core.Reading_0_sectors_at_a_time, blocksToRead));
|
||||
}
|
||||
else if(_useBufferedReads)
|
||||
{
|
||||
UpdateStatus?.Invoke(string.Format(Localization.Core.Reading_0_sectors_at_a_time_using_OS_buffered_reads,
|
||||
@@ -233,9 +231,9 @@ public sealed partial class MediaScan
|
||||
var ibgLog = new IbgLog(_ibgLogPath, sdProfile);
|
||||
|
||||
_scanStopwatch.Restart();
|
||||
_speedStopwatch.Restart();
|
||||
ulong sectorSpeedStart = 0;
|
||||
InitProgress?.Invoke();
|
||||
uint accumulatedSpeedSectors = 0;
|
||||
double accumulatedSpeedMs = 0;
|
||||
|
||||
for(ulong i = 0; i < results.Blocks; i += blocksToRead)
|
||||
{
|
||||
@@ -256,6 +254,8 @@ public sealed partial class MediaScan
|
||||
|
||||
bool error;
|
||||
|
||||
_speedStopwatch.Restart();
|
||||
|
||||
if(blocksToRead == 1)
|
||||
{
|
||||
error = _dev.ReadSingleBlock(out cmdBuf,
|
||||
@@ -291,6 +291,10 @@ public sealed partial class MediaScan
|
||||
out duration);
|
||||
}
|
||||
|
||||
_speedStopwatch.Stop();
|
||||
accumulatedSpeedMs += _speedStopwatch.ElapsedMilliseconds;
|
||||
accumulatedSpeedSectors += blocksToRead;
|
||||
|
||||
if(!error)
|
||||
{
|
||||
switch(duration)
|
||||
@@ -337,23 +341,21 @@ public sealed partial class MediaScan
|
||||
ibgLog.Write(i, 0);
|
||||
}
|
||||
|
||||
sectorSpeedStart += blocksToRead;
|
||||
|
||||
double elapsed = _speedStopwatch.Elapsed.TotalSeconds;
|
||||
|
||||
if(elapsed <= 0) continue;
|
||||
|
||||
currentSpeed = sectorSpeedStart * blockSize / (1048576 * elapsed);
|
||||
ScanSpeed?.Invoke(i, currentSpeed * 1024);
|
||||
sectorSpeedStart = 0;
|
||||
_speedStopwatch.Restart();
|
||||
if(accumulatedSpeedMs >= 100)
|
||||
{
|
||||
currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0));
|
||||
ScanSpeed?.Invoke(i, currentSpeed * 1024);
|
||||
accumulatedSpeedMs = 0;
|
||||
accumulatedSpeedSectors = 0;
|
||||
}
|
||||
}
|
||||
|
||||
_speedStopwatch.Stop();
|
||||
_scanStopwatch.Stop();
|
||||
EndProgress?.Invoke();
|
||||
mhddLog.Close();
|
||||
|
||||
currentSpeed = accumulatedSpeedSectors * blockSize / (1048576 * (accumulatedSpeedMs / 1000.0));
|
||||
|
||||
ibgLog.Close(_dev,
|
||||
results.Blocks,
|
||||
blockSize,
|
||||
@@ -364,11 +366,11 @@ public sealed partial class MediaScan
|
||||
|
||||
InitProgress?.Invoke();
|
||||
|
||||
for(int i = 0; i < seekTimes; i++)
|
||||
for(var i = 0; i < seekTimes; i++)
|
||||
{
|
||||
if(_aborted || !_seekTest) break;
|
||||
|
||||
uint seekPos = (uint)rnd.Next((int)results.Blocks);
|
||||
var seekPos = (uint)rnd.Next((int)results.Blocks);
|
||||
|
||||
PulseProgress?.Invoke(string.Format(Localization.Core.Seeking_to_sector_0, seekPos));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user