Implement benchmark in GUI.

This commit is contained in:
2018-10-08 23:32:00 +01:00
parent 6c1ea13ec6
commit cfd0ba4188
6 changed files with 273 additions and 2 deletions

View File

@@ -1605,6 +1605,8 @@
<e p="SvgImageView.cs" t="Include" />
</e>
<e p="Dialogs" t="Include">
<e p="dlgBenchmark.xeto" t="Include" />
<e p="dlgBenchmark.xeto.cs" t="Include" />
<e p="dlgEncodings.xeto" t="Include" />
<e p="dlgEncodings.xeto.cs" t="Include" />
<e p="dlgPlugins.xeto" t="Include" />

View File

@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?><!--
// /***************************************************************************
// The Disc Image Chef
// ============================================================================
//
// Filename : dlgBenchmark.xeto
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Benchmark dialog.
//
// ==[ Description ] ==========================================================
//
// Defines the structure for the benchmark dialog.
//
// ==[ License ] ==============================================================
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General public License for more details.
//
// You should have received a copy of the GNU General public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ============================================================================
// Copyright © 2011-2018 Natalia Portillo
// ****************************************************************************/
-->
<Dialog xmlns="http://schema.picoe.ca/eto.forms" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Benchmark" ClientSize="460, 160" Padding="10" Maximizable="False" Minimizable="False" Resizable="False"
WindowStyle="None">
<StackLayout Orientation="Vertical">
<StackLayoutItem HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Expand="True">
<StackLayout Orientation="Vertical" ID="stkPreCalculation">
<StackLayoutItem HorizontalAlignment="Stretch" VerticalAlignment="Top">
<StackLayout Orientation="Horizontal">
<NumericStepper ID="nmuBufferSize" Value="128" MinValue="1" MaxValue="1024"/>
<Label Text="MiB of buffer"/>
</StackLayout>
</StackLayoutItem>
<StackLayoutItem HorizontalAlignment="Stretch" VerticalAlignment="Top">
<StackLayout Orientation="Horizontal">
<NumericStepper ID="nmuBlockSize" Value="512" MinValue="2" MaxValue="65536"/>
<Label Text="bytes per block"/>
</StackLayout>
</StackLayoutItem>
<StackLayoutItem HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Expand="True">
<StackLayout Orientation="Vertical" ID="stkProgress">
<StackLayoutItem HorizontalAlignment="Stretch" Expand="True">
<Label ID="lblProgress" Size="-1, -1"/>
</StackLayoutItem>
<StackLayoutItem HorizontalAlignment="Stretch" Expand="True">
<ProgressBar ID="prgProgress"/>
</StackLayoutItem>
</StackLayout>
</StackLayoutItem>
</StackLayout>
</StackLayoutItem>
<StackLayoutItem HorizontalAlignment="Right" VerticalAlignment="Bottom" Expand="True">
<StackLayout Orientation="Horizontal" ID="stkButtons">
<StackLayoutItem HorizontalAlignment="Stretch" Expand="True">
<Button ID="btnStart" Click="OnBtnStart">Start</Button>
</StackLayoutItem>
<StackLayoutItem HorizontalAlignment="Stretch" Expand="True">
<Button ID="btnClose" Click="OnBtnClose">Close</Button>
</StackLayoutItem>
</StackLayout>
</StackLayoutItem>
</StackLayout>
</Dialog>

View File

@@ -0,0 +1,187 @@
// /***************************************************************************
// The Disc Image Chef
// ----------------------------------------------------------------------------
//
// Filename : dlgBenchmark.xeto.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// Component : Benchmark dialog.
//
// --[ Description ] ----------------------------------------------------------
//
// Implements the benchmark dialog.
//
// --[ License ] --------------------------------------------------------------
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General public License for more details.
//
// You should have received a copy of the GNU General public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2011-2018 Natalia Portillo
// ****************************************************************************/
using System;
using System.Collections.Generic;
using System.Threading;
using DiscImageChef.Core;
using Eto.Drawing;
using Eto.Forms;
using Eto.Serialization.Xaml;
namespace DiscImageChef.Gui.Dialogs
{
public class dlgBenchmark : Dialog
{
Dictionary<string, double> checksumTimes;
int counter;
BenchmarkResults results;
int step;
public dlgBenchmark()
{
XamlReader.Load(this);
}
protected void OnBtnStart(object sender, EventArgs e)
{
checksumTimes = new Dictionary<string, double>();
Benchmark.UpdateProgressEvent += UpdateProgress;
stkProgress.Visible = true;
lblProgress.Text = "";
btnClose.Enabled = false;
btnStart.Enabled = false;
nmuBufferSize.Enabled = false;
nmuBlockSize.Enabled = false;
Thread thread = new Thread(() =>
{
counter = step = (int)(nmuBufferSize.Value * 1024 * 1024 / nmuBlockSize.Value) % 3333;
// TODO: Able to cancel!
results = Benchmark.Do((int)(nmuBufferSize.Value * 1024 * 1024), (int)nmuBlockSize.Value);
Application.Instance.Invoke(Finish);
});
thread.Start();
}
void Finish()
{
Benchmark.UpdateProgressEvent += UpdateProgress;
StackLayout stkCalculationResults = new StackLayout();
stkCalculationResults.Items.Add(new Label
{
Text =
$"Took {results.FillTime} seconds to fill buffer, {results.FillSpeed:F3} MiB/sec."
});
stkCalculationResults.Items.Add(new Label
{
Text =
$"Took {results.ReadTime} seconds to read buffer, {results.ReadSpeed:F3} MiB/sec."
});
stkCalculationResults.Items.Add(new Label
{
Text =
$"Took {results.EntropyTime} seconds to entropy buffer, {results.EntropySpeed:F3} MiB/sec."
});
foreach(KeyValuePair<string, BenchmarkEntry> entry in results.Entries)
{
checksumTimes.Add(entry.Key, entry.Value.TimeSpan);
stkCalculationResults.Items.Add(new Label
{
Text =
$"Took {entry.Value.TimeSpan} seconds to {entry.Key} buffer, {entry.Value.Speed:F3} MiB/sec."
});
;
}
stkCalculationResults.Items.Add(new Label
{
Text =
$"Took {results.TotalTime} seconds to do all algorithms at the same time, {results.TotalSpeed:F3} MiB/sec."
});
stkCalculationResults.Items.Add(new Label
{
Text =
$"Took {results.SeparateTime} seconds to do all algorithms sequentially, {results.SeparateSpeed:F3} MiB/sec."
});
stkCalculationResults.Items.Add(new Label {Text = $"Max memory used is {results.MaxMemory} bytes"});
stkCalculationResults.Items.Add(new Label {Text = $"Min memory used is {results.MinMemory} bytes"});
Statistics.AddCommand("benchmark");
Statistics.AddBenchmark(checksumTimes, results.EntropyTime, results.TotalTime, results.SeparateTime,
results.MaxMemory, results.MinMemory);
stkCalculationResults.Items.Add(new StackLayoutItem(stkButtons, HorizontalAlignment.Right, true));
stkCalculationResults.Visible = true;
btnStart.Visible = false;
btnClose.Enabled = true;
Content = stkCalculationResults;
ClientSize = new Size(-1, -1);
}
void UpdateProgress(string text, long current, long maximum)
{
if(counter < step)
{
counter++;
return;
}
counter = 0;
Application.Instance.Invoke(() =>
{
lblProgress.Text = text;
if(maximum == 0)
{
prgProgress.Indeterminate = true;
return;
}
if(prgProgress.Indeterminate) prgProgress.Indeterminate = false;
if(maximum > int.MaxValue || current > int.MaxValue)
{
prgProgress.MaxValue = (int)(maximum / int.MaxValue);
prgProgress.Value = (int)(current / int.MaxValue);
}
else
{
prgProgress.MaxValue = (int)maximum;
prgProgress.Value = (int)current;
}
});
}
protected void OnBtnClose(object sender, EventArgs e)
{
Close();
}
#region XAML controls
NumericStepper nmuBufferSize;
NumericStepper nmuBlockSize;
StackLayout stkProgress;
Label lblProgress;
ProgressBar prgProgress;
Button btnStart;
Button btnClose;
StackLayout stkPreCalculation;
StackLayout stkButtons;
#endregion
}
}

View File

@@ -51,6 +51,7 @@
<ButtonMenuItem Text="&amp;Console" Click="OnMenuConsole"/>
</ButtonMenuItem>
<ButtonMenuItem Text="&amp;Help">
<ButtonMenuItem Text="&amp;Benchmark" Click="OnMenuBenchmark"/>
<ButtonMenuItem Text="&amp;Encodings" Click="OnMenuEncodings"/>
<ButtonMenuItem Text="&amp;Plugins" Click="OnMenuPlugins"/>
</ButtonMenuItem>

View File

@@ -473,6 +473,11 @@ namespace DiscImageChef.Gui.Forms
new dlgEncodings().ShowModal(this);
}
protected void OnMenuBenchmark(object sender, EventArgs e)
{
new dlgBenchmark().ShowModal(this);
}
protected void OnTreeImagesSelectedItemChanged(object sender, EventArgs e)
{
if(!(sender is TreeGridView tree)) return;

View File

@@ -61,9 +61,9 @@ namespace DiscImageChef.Commands
entry.Value.Speed);
}
DicConsole.WriteLine("Took {0} seconds to do all algorithms at the same time, {1} MiB/sec.",
DicConsole.WriteLine("Took {0} seconds to do all algorithms at the same time, {1:F3} MiB/sec.",
results.TotalTime, results.TotalSpeed);
DicConsole.WriteLine("Took {0} seconds to do all algorithms sequentially, {1} MiB/sec.",
DicConsole.WriteLine("Took {0} seconds to do all algorithms sequentially, {1:F3} MiB/sec.",
results.SeparateTime, results.SeparateSpeed);
DicConsole.WriteLine();