private void ProcessDiskIoLog() { var entropyOptions = new ReducePathEntropyOptions(); var replacements = DiskIoDomainKnowledge.NewDefaultReplacementsTable(); var specificTempFile = new FileInfo(_diskIoTempFiles[WptInterop.DiskIoTempOutputLabel]); foreach ( var m in WptInterop.GetDiskIoMeasurementsFromXPerfOutput(specificTempFile.FullName)) { m.PathSummary = ReducePathEntropy ? DiskIoDomainKnowledge.ReducePathEntropy(m.PathRaw, replacements, entropyOptions) : m.PathRaw; m.AttributionBucket = DiskIoDomainKnowledge.ResolveDiskIoAttributionBucket(m.ProcessName, m.PathRaw, m.PathSummary); if (RegisterNonAggregatedMeasurements) RegisterMeasurement(m); if (AggregateByProcessAndFile) { if (!_aProcessAndFile.ContainsKey(m.ProcessAndPathSummaryKey)) { var m2 = (DiskIo) m.Clone(); m2.IsAggregate = true; m2.IoType = "MixedAggregate"; _aProcessAndFile.Add(m.ProcessAndPathSummaryKey, m2); } else { var updateThis = _aProcessAndFile[m.ProcessAndPathSummaryKey]; updateThis.IoTimeUSec += m.IoTimeUSec; updateThis.DiskSvcTimeUSec += m.DiskSvcTimeUSec; updateThis.Count++; updateThis.Bytes += m.Bytes; } } } var i = 0; while (i < 4) { i++; try { File.Delete(_diskIoTempFiles[WptInterop.DiskIoTempOutputLabel]); File.Delete(_diskIoTempFiles[WptInterop.DiskIoTempErrorLabel]); break; } catch { Thread.Sleep(500); } } if (!AggregateByProcessAndFile) return; foreach (var am in _aProcessAndFile.Values) { RegisterMeasurement(am); } }
public static string ReducePathEntropy(string originalPath, ICollection<Tuple<string, string>> replacementsTable, ReducePathEntropyOptions options) { var newValue = originalPath; foreach (var row in replacementsTable) { var startsWithRegExPattern = "^" + Regex.Escape(row.Item1); newValue = Regex.Replace(newValue, startsWithRegExPattern, row.Item2, RegexOptions.IgnoreCase); //if (!originalPath.StartsWith(row.Item1, StringComparison.OrdinalIgnoreCase)) continue; //newValue = originalPath.Replace(row.Item1.ToUpperInvariant(), row.Item2); //break; } var tokenizedPath = newValue.Split(Path.DirectorySeparatorChar); if (string.Equals(tokenizedPath[0], ProgramFilesLabel, StringComparison.OrdinalIgnoreCase) || string.Equals(tokenizedPath[0], CommonFilesLabel, StringComparison.OrdinalIgnoreCase) || string.Equals(tokenizedPath[0], ProgramDataLabel, StringComparison.OrdinalIgnoreCase)) { var effectiveDepthLimit = options.DepthLimit; if (tokenizedPath.Length > 1 && string.Equals(tokenizedPath[1], "Microsoft", StringComparison.OrdinalIgnoreCase)) { effectiveDepthLimit += options.DepthBoostSpecial; } newValue = string.Join(@"\", tokenizedPath.Take(effectiveDepthLimit)); } else if (string.Equals(tokenizedPath[0], UserProfilesRootLabel, StringComparison.OrdinalIgnoreCase)) { var effectiveDepthLimit = options.DepthLimit; if (tokenizedPath.Contains("microsoft", StringComparer.OrdinalIgnoreCase)) { effectiveDepthLimit = effectiveDepthLimit + options.DepthBoostSpecial; } var includedTokens = new List<string> {tokenizedPath[0]}; includedTokens.AddRange(tokenizedPath.Skip(2).Take(effectiveDepthLimit)); newValue = string.Join(@"\", includedTokens); } else if (string.Equals(tokenizedPath[0], WinDirLabel)) { var effectiveDepthLimit = options.DepthLimit; if (tokenizedPath.Contains("wbem", StringComparer.OrdinalIgnoreCase)) { effectiveDepthLimit = 3; } else if (tokenizedPath.Contains("winevt", StringComparer.OrdinalIgnoreCase)) { effectiveDepthLimit = 4; } else if (tokenizedPath.Contains("config", StringComparer.OrdinalIgnoreCase)) { effectiveDepthLimit = 4; } else if (tokenizedPath.Length > 3 && string.Equals(tokenizedPath[1], "system32", StringComparison.OrdinalIgnoreCase)) { effectiveDepthLimit = 3; } newValue = string.Join(@"\", tokenizedPath.Take(effectiveDepthLimit)); } else { newValue = string.Join(@"\", tokenizedPath.Take(options.DepthLimit)); } newValue = Regex.Replace(newValue, @"[\dA-Fa-f]{4,}", "%N%"); return newValue.Length > options.LengthLimit ? newValue.Substring(0, options.LengthLimit) : newValue; }