Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResultsComparer] make sure the data is not duplicated #2427

Merged
merged 1 commit into from
May 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/tools/ResultsComparer/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using SharpCompress.Archives.Zip;
using SharpCompress.Readers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
Expand All @@ -22,6 +23,7 @@ internal static void Decompress(FileInfo zip, DirectoryInfo output)
using Stream mainZipStream = zip.OpenRead();
using ZipArchive mainArchive = ZipArchive.Open(mainZipStream);
string folderPath;
HashSet<string> savedFiles = new();

foreach (ZipArchiveEntry mainArchiveEntry in mainArchive.Entries.Where(e => !e.IsDirectory))
{
Expand All @@ -33,7 +35,10 @@ internal static void Decompress(FileInfo zip, DirectoryInfo output)
using ZipArchive zipArchive = ZipArchive.Open(zipArchiveEntryCopy);
foreach (var zipEntry in zipArchive.Entries.Where(e => e.Key.EndsWith(".json")))
{
zipEntry.WriteToDirectory(folderPath ??= GetFolderPath(output, mainArchiveEntry.Key, zipEntry.Key, zipEntry));
if (IsNotDuplicate(zipEntry.Key, folderPath ??= GetFolderPath(output, mainArchiveEntry.Key, zipEntry.Key, zipEntry), savedFiles))
{
zipEntry.WriteToDirectory(folderPath);
}
}
}
else if (mainArchiveEntry.Key.EndsWith(".tar.gz") // produced by benchmarks_monthly.py
Expand All @@ -49,7 +54,10 @@ internal static void Decompress(FileInfo zip, DirectoryInfo output)
using TarArchive tarArchive = TarArchive.Open(tarCopy);
foreach (var tarEntry in tarArchive.Entries.Where(e => e.Key.EndsWith(".json")))
{
tarEntry.WriteToDirectory(folderPath ??= GetFolderPath(output, mainArchiveEntry.Key, extractedGzip.Entry.Key, tarEntry));
if (IsNotDuplicate(tarEntry.Key, folderPath ??= GetFolderPath(output, mainArchiveEntry.Key, extractedGzip.Entry.Key, tarEntry), savedFiles))
{
tarEntry.WriteToDirectory(folderPath);
}
}
}
}
Expand Down Expand Up @@ -131,5 +139,21 @@ private static string GetSimplifiedProcessorName(string processorName)

return processorName.Replace(" ", "");
}

private static bool IsNotDuplicate(string key, string folderPath, HashSet<string> storedFiles)
{
string filePath = key.Split('/')[^1]; // sth like Performance-Runs/nativeaot6.0/adsitnik/arm64_win10-nativeaot6.0.tar.gz
// some of the results contain duplicated data, example:
// FractalPerf.Launch-report-full.json
// FractalPerf.Launch-resume-report-full.json
filePath = filePath.Replace("resume-report", "report");
// but they might also be stored in different .tar.gz files like:
// arm64-2022-05-04-23-17-Debian_Bullseye-net7.0-preview3.tar
// arm64-2022-05-05-12-40-Debian_Bullseye-net7.0-preview3.tar
// so we need to check if the file has been already stored:
filePath = Path.Combine(folderPath, filePath);
// and we perform an in-memory check (orders of magnitude faster than Path.Exists)
return storedFiles.Add(filePath);
}
}
}