Skip to content

Commit

Permalink
Manager: Add thread count number to game data gathering
Browse files Browse the repository at this point in the history
  • Loading branch information
Sejsel committed Aug 17, 2023
1 parent 25f2c45 commit f6be5ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions ArcdpsLogManager/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This is the full changelog of the arcdps Log Manager.
## Log Manager v1.10
#### New features
- Added a button to set the dps.report user token in the settings
- Added max parallel threads setting to the Game data gathering tab (View -> Debug Data must be enabled to see this tab).
#### Fixes
- Fixed log detail pane not appearing for selected logs processed with Log Manager versions 1.3 and older.
- Fixed a stray debug data section appearing when multiple logs were selected even if debug data wasn't enabled
Expand Down
26 changes: 20 additions & 6 deletions ArcdpsLogManager/Sections/GameDataGathering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ public override int GetHashCode()
public GameDataCollecting(LogList logList, LogCache logCache, ApiData apiData, LogDataProcessor logProcessor,
UploadProcessor uploadProcessor, ImageProvider imageProvider, ILogNameProvider nameProvider)
{
var threadCountStepper = new NumericStepper
{
// 4 seems to be a good default value, there doesn't seem to be any scaling beyond this,
// at least on a Ryzen 5900X with an SSD.
Value = Math.Min(Environment.ProcessorCount, 4),
MinValue = 1, Increment = 1.0
};
var gatherButton = new Button {Text = "Collect data"};
var cancelButton = new Button {Text = "Cancel"};
var exportSpeciesButton = new Button {Text = "Export species data to csv"};
Expand All @@ -140,6 +147,13 @@ public GameDataCollecting(LogList logList, LogCache logCache, ApiData apiData, L
AddCentered(
"Collects a list of all different agent species and skills found in logs (uses current filters).");
AddCentered("Requires all logs to be processed again as this data is not cached.");
AddSpace(yscale: false);
BeginCentered(spacing: new Size(5, 5));
{
var label = new Label { Text = "Threads to use for parallel processing", VerticalAlignment = VerticalAlignment.Center };
AddRow(label, threadCountStepper);
}
EndCentered();
BeginCentered(spacing: new Size(5, 5));
{
AddRow(gatherButton, cancelButton);
Expand Down Expand Up @@ -292,8 +306,7 @@ public GameDataCollecting(LogList logList, LogCache logCache, ApiData apiData, L

cancelButton.Click += (sender, args) => cancellationTokenSource?.Cancel();
gatherButton.Click += (sender, args) =>
GatherData(logList, progressBar, progressLabel, speciesGridView, skillGridView, speciesSorter,
skillSorter);
GatherData(logList, progressBar, progressLabel, speciesGridView, skillGridView, speciesSorter, skillSorter, (int) threadCountStepper.Value);
exportSkillsButton.Click += (sender, args) =>
SaveToCsv(skillGridView.DataStore ?? Enumerable.Empty<SkillData>());
exportSpeciesButton.Click += (sender, args) =>
Expand Down Expand Up @@ -334,7 +347,7 @@ private void SaveToCsv(IEnumerable<SpeciesData> speciesData)

private void GatherData(LogList logList, ProgressBar progressBar, Label progressLabel,
GridView<SpeciesData> speciesGridView, GridView<SkillData> skillGridView,
GridViewSorter<SpeciesData> speciesSorter, GridViewSorter<SkillData> skillSorter)
GridViewSorter<SpeciesData> speciesSorter, GridViewSorter<SkillData> skillSorter, int maxDegreeOfParallelism)
{
cancellationTokenSource?.Cancel();
cancellationTokenSource = new CancellationTokenSource();
Expand All @@ -343,6 +356,7 @@ private void GatherData(LogList logList, ProgressBar progressBar, Label progress
ParseLogs(
logs,
cancellationTokenSource.Token,
maxDegreeOfParallelism,
new Progress<(int done, int totalLogs, int failed)>(progress =>
{
(int done, int totalLogs, int failed) = progress;
Expand Down Expand Up @@ -371,17 +385,17 @@ private void GatherData(LogList logList, ProgressBar progressBar, Label progress
}

private Task<(IEnumerable<SpeciesData>, IEnumerable<SkillData>)> ParseLogs(IReadOnlyCollection<LogData> logs,
CancellationToken cancellationToken, IProgress<(int done, int totalLogs, int failed)> progress = null)
CancellationToken cancellationToken, int maxDegreeOfParallelism, IProgress<(int done, int totalLogs, int failed)> progress = null)
{
return Task.Run(() =>
{
// TODO: Change List into some kind of concurrent bag
var species = new ConcurrentDictionary<int, ConcurrentDictionary<SpeciesData, ConcurrentBag<LogData>>>();
var skills = new ConcurrentDictionary<uint, ConcurrentDictionary<SkillData, ConcurrentBag<LogData>>>();
int done = 0;
int failed = 0;
Parallel.ForEach(logs, log =>
var options = new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism };
Parallel.ForEach(logs, options, log =>
{
cancellationToken.ThrowIfCancellationRequested();
Expand Down

0 comments on commit f6be5ab

Please sign in to comment.