-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config: save asynchronously to prevent hitches
- Loading branch information
Showing
3 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
Dalamud/Interface/Internal/Windows/Data/Widgets/VfsWidget.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System.Diagnostics; | ||
using System.IO; | ||
|
||
using Dalamud.Configuration.Internal; | ||
using Dalamud.Storage; | ||
using ImGuiNET; | ||
using Serilog; | ||
|
||
namespace Dalamud.Interface.Internal.Windows.Data.Widgets; | ||
|
||
/// <summary> | ||
/// Widget for displaying configuration info. | ||
/// </summary> | ||
internal class VfsWidget : IDataWindowWidget | ||
{ | ||
private int numBytes = 1024; | ||
private int reps = 1; | ||
|
||
/// <inheritdoc/> | ||
public string[]? CommandShortcuts { get; init; } = { "vfs" }; | ||
|
||
/// <inheritdoc/> | ||
public string DisplayName { get; init; } = "VFS Performance"; | ||
|
||
/// <inheritdoc/> | ||
public bool Ready { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public void Load() | ||
{ | ||
this.Ready = true; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public void Draw() | ||
{ | ||
var service = Service<ReliableFileStorage>.Get(); | ||
var dalamud = Service<Dalamud>.Get(); | ||
|
||
ImGui.InputInt("Num bytes", ref this.numBytes); | ||
ImGui.InputInt("Reps", ref this.reps); | ||
|
||
var path = Path.Combine(dalamud.StartInfo.WorkingDirectory!, "test.bin"); | ||
|
||
if (ImGui.Button("Write")) | ||
{ | ||
Log.Information("=== WRITING ==="); | ||
var data = new byte[this.numBytes]; | ||
var stopwatch = new Stopwatch(); | ||
var acc = 0L; | ||
|
||
for (var i = 0; i < this.reps; i++) | ||
{ | ||
stopwatch.Restart(); | ||
service.WriteAllBytes(path, data); | ||
stopwatch.Stop(); | ||
acc += stopwatch.ElapsedMilliseconds; | ||
Log.Information("Turn {Turn} took {Ms}ms", i, stopwatch.ElapsedMilliseconds); | ||
} | ||
|
||
Log.Information("Took {Ms}ms in total", acc); | ||
} | ||
|
||
if (ImGui.Button("Read")) | ||
{ | ||
Log.Information("=== READING ==="); | ||
var stopwatch = new Stopwatch(); | ||
var acc = 0L; | ||
|
||
for (var i = 0; i < this.reps; i++) | ||
{ | ||
stopwatch.Restart(); | ||
service.ReadAllBytes(path); | ||
stopwatch.Stop(); | ||
acc += stopwatch.ElapsedMilliseconds; | ||
Log.Information("Turn {Turn} took {Ms}ms", i, stopwatch.ElapsedMilliseconds); | ||
} | ||
|
||
Log.Information("Took {Ms}ms in total", acc); | ||
} | ||
|
||
if (ImGui.Button("Test Config")) | ||
{ | ||
var config = Service<DalamudConfiguration>.Get(); | ||
|
||
Log.Information("=== READING ==="); | ||
var stopwatch = new Stopwatch(); | ||
var acc = 0L; | ||
|
||
for (var i = 0; i < this.reps; i++) | ||
{ | ||
stopwatch.Restart(); | ||
config.ForceSave(); | ||
stopwatch.Stop(); | ||
acc += stopwatch.ElapsedMilliseconds; | ||
Log.Information("Turn {Turn} took {Ms}ms", i, stopwatch.ElapsedMilliseconds); | ||
} | ||
|
||
Log.Information("Took {Ms}ms in total", acc); | ||
} | ||
} | ||
} |