collect function call stats per game

This commit is contained in:
13xforever 2019-08-07 03:35:50 +05:00
parent 2e493ba757
commit bc14931d39
4 changed files with 70 additions and 27 deletions

View File

@ -185,6 +185,7 @@ namespace CompatBot.EventHandlers.LogParsing
["Unimplemented syscall"] = new Regex(@"U \d+:\d+:\d+\.\d+ ({(?<unimplemented_syscall_context>.+?)} )?.*Unimplemented syscall (?<unimplemented_syscall>.*)\r?$", DefaultOptions),
["Could not enqueue"] = new Regex(@"cellAudio: Could not enqueue buffer onto audio backend(?<enqueue_buffer_error>.).*\r?$", DefaultOptions),
["Failed to bind device"] = new Regex(@"Failed to bind device (?<failed_pad>.+) to handler (?<failed_pad_handler>.+).*\r?$", DefaultOptions),
["{PPU["] = new Regex(@"{PPU\[.+\]} (?<syscall_module>[^ :]+)( TODO)?: (?<syscall_name>[^ :]+)\(.*\r?$", DefaultOptions),
},
OnNewLineAsync = LimitedPiracyCheckAsync,
OnSectionEnd = MarkAsCompleteAndReset,
@ -239,6 +240,11 @@ namespace CompatBot.EventHandlers.LogParsing
return PiracyCheckAsync(line, state);
}
private static async Task CollectFunctionStatsAsync(string line, LogParseState state)
{
}
private static void ClearResults(LogParseState state)
{

View File

@ -39,7 +39,7 @@ namespace CompatBot.EventHandlers.LogParsing
state.ExtractorHitStats.TryGetValue(extractorPair.Key, out var stat);
state.ExtractorHitStats[extractorPair.Key] = stat + 1;
#endif
OnExtractorHit(buffer, extractorPair.Value, state);
OnExtractorHit(buffer, extractorPair.Key, extractorPair.Value, state);
})
), true);
parser.OnExtract = (line, buffer, state) => { act.ParseText(line, h => { h.Value(buffer, state); }); };
@ -49,39 +49,62 @@ namespace CompatBot.EventHandlers.LogParsing
SectionParsers = parsers.AsReadOnly();
}
private static void OnExtractorHit(string buffer, Regex extractor, LogParseState state)
private static void OnExtractorHit(string buffer, string trigger, Regex extractor, LogParseState state)
{
var matches = extractor.Matches(buffer);
if (matches.Count == 0)
return;
foreach (Match match in matches)
foreach (Group group in match.Groups)
if (!string.IsNullOrEmpty(group.Name) && group.Name != "0" && !string.IsNullOrWhiteSpace(group.Value))
if (trigger == "{PPU[")
{
if (state.WipCollection["serial"] is string serial)
{
if (string.IsNullOrEmpty(group.Value))
continue;
var strValue = group.Value.ToUtf8();
Config.Log.Trace($"regex {group.Name} = {group.Value}");
lock(state)
var match = extractor.Match(buffer);
if (match.Success
&& match.Groups["syscall_module"]?.Value.ToUtf8() is string syscallModule
&& match.Groups["syscall_name"]?.Value.ToUtf8() is string syscallName)
{
if (MultiValueItems.Contains(group.Name))
lock (state)
{
var currentValue = state.WipCollection[group.Name];
if (!string.IsNullOrEmpty(currentValue))
currentValue += Environment.NewLine;
state.WipCollection[group.Name] = currentValue + strValue;
}
else
state.WipCollection[group.Name] = strValue;
if (CountValueItems.Contains(group.Name))
{
state.ValueHitStats.TryGetValue(group.Name, out var hits);
state.ValueHitStats[group.Name] = ++hits;
if (!state.Syscalls.TryGetValue(serial, out var serialSyscallStats))
state.Syscalls[serial] = serialSyscallStats = new Dictionary<string, HashSet<string>>();
if (!serialSyscallStats.TryGetValue(syscallModule, out var moduleStats))
serialSyscallStats[syscallModule] = moduleStats = new HashSet<string>();
moduleStats.Add(syscallName);
}
}
}
}
else
{
var matches = extractor.Matches(buffer);
if (matches.Count == 0)
return;
foreach (Match match in matches)
foreach (Group group in match.Groups)
if (!string.IsNullOrEmpty(group.Name) && group.Name != "0" && !string.IsNullOrWhiteSpace(group.Value))
{
if (string.IsNullOrEmpty(group.Value))
continue;
var strValue = group.Value.ToUtf8();
Config.Log.Trace($"regex {group.Name} = {group.Value}");
lock (state)
{
if (MultiValueItems.Contains(group.Name))
{
var currentValue = state.WipCollection[group.Name];
if (!string.IsNullOrEmpty(currentValue))
currentValue += Environment.NewLine;
state.WipCollection[group.Name] = currentValue + strValue;
}
else
state.WipCollection[group.Name] = strValue;
if (CountValueItems.Contains(group.Name))
{
state.ValueHitStats.TryGetValue(group.Name, out var hits);
state.ValueHitStats[group.Name] = ++hits;
}
}
}
}
}
private delegate void OnNewLineDelegate(string line, string buffer, LogParseState state);

View File

@ -10,6 +10,7 @@ namespace CompatBot.EventHandlers.LogParsing.POCOs
public NameValueCollection CompleteCollection = null;
public NameValueCollection WipCollection = new NameValueCollection();
public readonly Dictionary<string, int> ValueHitStats = new Dictionary<string, int>();
public readonly Dictionary<string, Dictionary<string, HashSet<string>>> Syscalls = new Dictionary<string, Dictionary<string, HashSet<string>>>();
public int Id = 0;
public ErrorCode Error = ErrorCode.None;
public readonly Dictionary<int, (Piracystring filter, string context)> FilterTriggers = new Dictionary<int, (Piracystring filter, string context)>();

View File

@ -267,6 +267,19 @@ namespace CompatBot.EventHandlers
Config.Log.Info($"{stat.Value}: {stat.Key}");
else
Config.Log.Debug($"{stat.Value}: {stat.Key}");
Config.Log.Debug("~~~~~~~~~~~~~~~~~~~~");
Config.Log.Debug("Syscall stats:");
int serialCount = result.Syscalls.Count, moduleCount = 0, functionCount = 0;
foreach (var moduleStats in result.Syscalls.Values)
{
moduleCount += moduleStats.Count;
foreach (var funcStats in moduleStats.Values)
functionCount += funcStats.Count;
}
Config.Log.Debug("Product keys: " + serialCount);
Config.Log.Debug("Modules: " + moduleCount);
Config.Log.Debug("Functions: " + functionCount);
#endif
}
catch (Exception e)