fix log parsing when runs were completed abnormally

This commit is contained in:
13xforever 2019-07-04 18:07:23 +05:00
parent cc21f6eb85
commit 8fb5ca5685
4 changed files with 13 additions and 13 deletions

View File

@ -34,7 +34,7 @@ namespace CompatBot.EventHandlers.LogParsing
["RPCS3"] = new Regex(@"^\s*(?<build_and_specs>RPCS3.*)\r?$", DefaultSingleLineOptions),
},
OnNewLineAsync = PiracyCheckAsync,
EndTrigger = "·",
EndTrigger = new[] {"·"},
},
new LogSection
{
@ -51,7 +51,7 @@ namespace CompatBot.EventHandlers.LogParsing
["custom config:"] = new Regex(@"custom config: (?<custom_config>.*?)\r?$", DefaultOptions),
},
OnNewLineAsync = PiracyCheckAsync,
EndTrigger = "Core:",
EndTrigger = new[] {"Core:"},
},
new LogSection
{
@ -78,7 +78,7 @@ namespace CompatBot.EventHandlers.LogParsing
["Load libraries:"] = new Regex(@"libraries:\r?\n(?<library_list>(.*?(- .*?|\[\])\r?\n)+)", DefaultOptions),
["HLE lwmutex:"] = new Regex(@"HLE lwmutex: (?<hle_lwmutex>.*?)\r?$", DefaultOptions),
},
EndTrigger = "VFS:",
EndTrigger = new[] {"VFS:"},
},
new LogSection
{
@ -86,7 +86,7 @@ namespace CompatBot.EventHandlers.LogParsing
{
["Enable /host_root/:"] = new Regex(@"Enable /host_root/: (?<host_root>.*?)\r?$", DefaultOptions),
},
EndTrigger = "Video:",
EndTrigger = new[] {"Video:"},
},
new LogSection
{
@ -113,7 +113,7 @@ namespace CompatBot.EventHandlers.LogParsing
["12:"] = new Regex(@"(D3D12|DirectX 12):\s*\r?\n\s*Adapter: (?<d3d_gpu>.*?)\r?$", DefaultOptions),
["Vulkan:"] = new Regex(@"Vulkan:\s*\r?\n\s*Adapter: (?<vulkan_gpu>.*?)\r?$", DefaultOptions),
},
EndTrigger = "Audio:",
EndTrigger = new[] {"Audio:"},
},
new LogSection // Audio, Input/Output, System, Net, Miscellaneous
{
@ -129,7 +129,7 @@ namespace CompatBot.EventHandlers.LogParsing
["Use native user interface:"] = new Regex("Use native user interface: (?<native_ui>.*?)\r?$", DefaultOptions),
},
EndTrigger = "Log:",
EndTrigger = new[] {"Log:"},
},
new LogSection
{
@ -137,7 +137,7 @@ namespace CompatBot.EventHandlers.LogParsing
{
["Log:"] = new Regex(@"Log:\s*\r?\n?\s*(\{(?<log_disabled_channels>.*?)\}|(?<log_disabled_channels_multiline>(\s+\w+\:\s*\w+\r?\n)+))\r?$", DefaultOptions),
},
EndTrigger = "·",
EndTrigger = new[] {"·"},
OnSectionEnd = MarkAsComplete,
},
new LogSection
@ -184,7 +184,7 @@ namespace CompatBot.EventHandlers.LogParsing
},
OnNewLineAsync = LimitedPiracyCheckAsync,
OnSectionEnd = MarkAsCompleteAndReset,
EndTrigger = "All threads stopped...",
EndTrigger = new[] {"All threads stopped...", "LDR: Booting from"},
}
};

View File

@ -78,13 +78,13 @@ namespace CompatBot.EventHandlers.LogParsing
private static async Task OnNewLineAsync(ReadOnlySequence<byte> line, ReadOnlySequence<byte> buffer, LinkedList<ReadOnlySequence<byte>> sectionLines, LogParseState state)
{
var currentProcessor = SectionParsers[state.Id];
if (line.AsString().Contains(currentProcessor.EndTrigger, StringComparison.InvariantCultureIgnoreCase))
var strLine = line.AsString();
if (currentProcessor.EndTrigger.Any(et => strLine.Contains(et, StringComparison.InvariantCultureIgnoreCase)))
{
await FlushAllLinesAsync(buffer, sectionLines, state).ConfigureAwait(false);
await TaskScheduler.WaitForClearTagAsync(state).ConfigureAwait(false);
SectionParsers[state.Id].OnSectionEnd?.Invoke(state);
state.Id++;
currentProcessor = SectionParsers[state.Id];
}
if (sectionLines.Count == 50)
await ProcessFirstLineInBufferAsync(buffer, sectionLines, state).ConfigureAwait(false);

View File

@ -25,7 +25,7 @@ namespace CompatBot.EventHandlers.LogParsing
{
OnLineCheckAsync = sectionDescription.OnNewLineAsync ?? ((l, s) => Task.CompletedTask),
OnSectionEnd = sectionDescription.OnSectionEnd,
EndTrigger = sectionDescription.EndTrigger.ToLatin8BitEncoding(),
EndTrigger = sectionDescription.EndTrigger.Select(s => s.ToLatin8BitEncoding()).ToArray(),
};
// the idea here is to construct Aho-Corasick parser that will look for any data marker and run the associated regex to extract the data into state
if (sectionDescription.Extractors?.Count > 0)
@ -91,7 +91,7 @@ namespace CompatBot.EventHandlers.LogParsing
public OnNewLineDelegate OnExtract;
public Func<string, LogParseState, Task> OnLineCheckAsync;
public Action<LogParseState> OnSectionEnd;
public string EndTrigger;
public string[] EndTrigger;
}
}
}

View File

@ -7,7 +7,7 @@ namespace CompatBot.EventHandlers.LogParsing.POCOs
{
internal class LogSection
{
public string EndTrigger;
public string[] EndTrigger;
public Dictionary<string, Regex> Extractors;
public Func<string, LogParseState, Task> OnNewLineAsync;
public Action<LogParseState> OnSectionEnd;