-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from xoofx/elf-refactoring
ELF refactoring with breaking changes
- Loading branch information
Showing
116 changed files
with
26,153 additions
and
8,825 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="SuperluminalPerf" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\LibObjectFile\LibObjectFile.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,86 @@ | ||
// Copyright (c) Alexandre Mutel. All rights reserved. | ||
// This file is licensed under the BSD-Clause 2 license. | ||
// See the license.txt file in the project root for more information. | ||
|
||
using System.Diagnostics; | ||
using LibObjectFile.Elf; | ||
|
||
namespace LibObjectFile.Bench; | ||
|
||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Loading files into memory"); | ||
var clock = Stopwatch.StartNew(); | ||
var streams = new List<MemoryStream>(); | ||
int biggestCapacity = 0; | ||
foreach (var file in GetLinuxBins()) | ||
{ | ||
using var stream = File.OpenRead((string)file[0]); | ||
if (ElfFile.IsElf(stream)) | ||
{ | ||
stream.Position = 0; | ||
var localStream = new MemoryStream((int)stream.Length); | ||
stream.CopyTo(localStream); | ||
localStream.Position = 0; | ||
streams.Add(localStream); | ||
if (localStream.Capacity > biggestCapacity) | ||
{ | ||
biggestCapacity = localStream.Capacity; | ||
} | ||
} | ||
} | ||
|
||
clock.Stop(); | ||
Console.WriteLine($"End reading in {clock.Elapsed.TotalMilliseconds}ms"); | ||
Console.ReadLine(); | ||
|
||
Console.WriteLine("Processing"); | ||
var memoryStream = new MemoryStream(biggestCapacity); | ||
clock.Restart(); | ||
//SuperluminalPerf.Initialize(); | ||
for (int i = 0; i < 10; i++) | ||
{ | ||
//SuperluminalPerf.BeginEvent($"Round{i}"); | ||
foreach (var stream in streams) | ||
{ | ||
stream.Position = 0; | ||
var elf = ElfFile.Read(stream); | ||
memoryStream.SetLength(0); | ||
elf.Write(memoryStream); | ||
} | ||
//SuperluminalPerf.EndEvent(); | ||
} | ||
clock.Stop(); | ||
Console.WriteLine($"{clock.Elapsed.TotalMilliseconds}ms"); | ||
} | ||
|
||
public static IEnumerable<object[]> GetLinuxBins() | ||
{ | ||
var wslDirectory = @"\\wsl$\Ubuntu\usr\bin"; | ||
if (OperatingSystem.IsLinux()) | ||
{ | ||
foreach (var file in Directory.EnumerateFiles(@"/usr/bin")) | ||
{ | ||
yield return new object[] { file }; | ||
} | ||
} | ||
else if (OperatingSystem.IsWindows() && Directory.Exists(wslDirectory)) | ||
{ | ||
foreach (var file in Directory.EnumerateFiles(wslDirectory)) | ||
{ | ||
var fileInfo = new FileInfo(file); | ||
// Skip symbolic links as loading them will fail | ||
if ((fileInfo.Attributes & FileAttributes.ReparsePoint) == 0) | ||
{ | ||
yield return new object[] { file }; | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
yield return new object[] { string.Empty }; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.