Skip to content

[WIP] Benchmark #7

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

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
446e093
initial benchmark
gukoff Aug 30, 2024
564d064
install libstapsdt on CI
gukoff Aug 30, 2024
110ed4c
attempt to fix libstapsdt build
gukoff Aug 30, 2024
7c42c4c
try store results
gukoff Aug 30, 2024
f933cb5
Merge remote-tracking branch 'origin/main' into benchmark
gukoff Sep 1, 2024
886f72d
merge fix
gukoff Sep 1, 2024
4eb6bdf
amend pipeline
gukoff Sep 1, 2024
ef5f6b6
add runtime monikers
gukoff Sep 1, 2024
a332e71
Rm windows-only moniker
gukoff Sep 1, 2024
3c8cc34
change exporter
gukoff Sep 1, 2024
bb6c2e1
fix bench name
gukoff Sep 1, 2024
44f985a
list folder
gukoff Sep 1, 2024
17100fe
list folder
gukoff Sep 1, 2024
2ee7f76
trigger ci
gukoff Sep 1, 2024
908f697
post summary
gukoff Sep 1, 2024
6848b30
cleanup commented code
gukoff Sep 2, 2024
5ce5ab7
cache last benchmark
gukoff Sep 2, 2024
d432172
do not update cached perf file when triggered on PR
gukoff Sep 2, 2024
ac811f1
more permissions
gukoff Sep 2, 2024
b49d3e6
upload artifacts
gukoff Sep 2, 2024
2f679ad
try different float formatting
gukoff Sep 2, 2024
a1981ef
comment with github report
gukoff Sep 2, 2024
c779ef5
try with main
gukoff Sep 2, 2024
9ab87ef
try with tag
gukoff Sep 2, 2024
7a32cc8
fix action
gukoff Sep 2, 2024
d5af3ef
light adjustment
gukoff Sep 3, 2024
5aa28c9
don't use the forked action, something's wrong with it
gukoff Sep 3, 2024
dc7740a
try from master
gukoff Sep 3, 2024
bd03b08
try forked action again
gukoff Sep 3, 2024
4807274
change title
gukoff Sep 3, 2024
b2598e9
Merge branch 'main' into benchmark
gukoff Sep 3, 2024
13ec6ad
Merge branch 'main' into benchmark
gukoff Sep 3, 2024
85c162d
merge fix
gukoff Sep 3, 2024
7349175
temporarily save bench file
gukoff Sep 3, 2024
d017ea2
enable comparison again
gukoff Sep 3, 2024
2c6fa8a
Merge branch 'main' into benchmark
gukoff Sep 11, 2024
d4e2095
Fix merge conflicts
gukoff Sep 11, 2024
1b4f9be
allow more dotnet versions. My VM only has 8.0.108, and upgrading dot…
gukoff Sep 11, 2024
cfb80b6
tmp-save progress
gukoff Sep 11, 2024
a5f4f60
make read-only again
gukoff Sep 11, 2024
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
79 changes: 79 additions & 0 deletions .github/workflows/benchmark.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Benchmark

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
benchmark:
name: Run benchmark
runs-on: ubuntu-latest
permissions:
pull-requests: write # in order to add a comment to PR
steps:
- name: Checkout libstapsdt repo
uses: actions/checkout@v4
with:
repository: linux-usdt/libstapsdt
ref: refs/heads/main
path: ext_libstapsdt

- name: Install libstapsdt
run: |
set -euxo pipefail
sudo apt install libelf-dev
cd ext_libstapsdt
make
sudo make install
sudo ldconfig
shell: bash

- name: Checkout DynamicProbes repo
uses: actions/checkout@v4

- name: Install dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.401'

- name: Run benchmark
run: cd benchmark && dotnet run --exporters json --filter '*' -c Release

- uses: actions/upload-artifact@v4
with:
name: results
path: benchmark/BenchmarkDotNet.Artifacts/results/

# Download previous benchmark result from cache (if exists)
- name: Download previous benchmark data
uses: actions/cache@v4
with:
path: ./cache
key: last-benchmark

# - name: PR comment with file
# uses: thollander/actions-comment-pull-request@v2
# with:
# filePath: benchmark/BenchmarkDotNet.Artifacts/results/Benchmark.NotObservedProbeFireBenchmarks-report-github.md

- name: Publish benchmark result
uses: gukoff/github-action-benchmark@short-floats
with:
name: Benchmark (compared to main) # bench data is cached inside `external-data-json-path` by this name
tool: 'benchmarkdotnet'
output-file-path: benchmark/BenchmarkDotNet.Artifacts/results/Benchmark.NotObservedProbeFireBenchmarks-report-full-compressed.json
external-data-json-path: ./cache/benchmark-data.json
github-token: ${{ secrets.GITHUB_TOKEN }}
summary-always: true
comment-always: true
# Caveat: https://github.com/benchmark-action/github-action-benchmark?tab=readme-ov-file#caveats
# When triggering on PRs, it's important to have this action "read-only"
save-data-file: ${{ github.event_name != 'pull_request' }}
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@gukoff'
6 changes: 6 additions & 0 deletions DynamicProbes.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark", "benchmark\Benchmark.csproj", "{2F9E49F9-1B8C-4170-8FF1-313BEF57D91C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -24,6 +26,10 @@ Global
{1B1F3A57-1538-4C11-ABD8-7024A4ABA2A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B1F3A57-1538-4C11-ABD8-7024A4ABA2A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B1F3A57-1538-4C11-ABD8-7024A4ABA2A7}.Release|Any CPU.Build.0 = Release|Any CPU
{2F9E49F9-1B8C-4170-8FF1-313BEF57D91C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F9E49F9-1B8C-4170-8FF1-313BEF57D91C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F9E49F9-1B8C-4170-8FF1-313BEF57D91C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F9E49F9-1B8C-4170-8FF1-313BEF57D91C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
15 changes: 15 additions & 0 deletions benchmark/Benchmark.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<ProjectReference Include="..\src\DynamicProbes.csproj" />
</ItemGroup>

</Project>
72 changes: 72 additions & 0 deletions benchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using LibstapsdtPinvokes;

namespace Benchmark;

[JsonExporterAttribute.Full]
[JsonExporterAttribute.FullCompressed]
[SimpleJob(RuntimeMoniker.NativeAot80)]
public class NotObservedProbeFireBenchmarks
{
nint provider;
nint probe1;
nint probe2;
nint probe3;
nint probe4;
nint probe5;
nint probe6;
readonly long arg1 = 1234567890123456789;
readonly long arg2 = 2234567890123456789;
readonly long arg3 = 3234567890123456789;
readonly long arg4 = 4234567890123456789;
readonly long arg5 = 5234567890123456789;
readonly long arg6 = 6234567890123456789;

[GlobalSetup]
public void GlobalSetup()
{
this.provider = Libstapsdt.ProviderInit("myprovider");
this.probe1 = Libstapsdt.ProviderAddProbe(this.provider, "myprobe1", ArgType.Int64);
this.probe2 = Libstapsdt.ProviderAddProbe(this.provider, "myprobe2", ArgType.Int64, ArgType.Int64);
this.probe3 = Libstapsdt.ProviderAddProbe(this.provider, "myprobe3", ArgType.Int64, ArgType.Int64, ArgType.Int64);
this.probe4 = Libstapsdt.ProviderAddProbe(this.provider, "myprobe4", ArgType.Int64, ArgType.Int64, ArgType.Int64, ArgType.Int64);
this.probe5 = Libstapsdt.ProviderAddProbe(this.provider, "myprobe5", ArgType.Int64, ArgType.Int64, ArgType.Int64, ArgType.Int64, ArgType.Int64);
this.probe6 = Libstapsdt.ProviderAddProbe(this.provider, "myprobe6", ArgType.Int64, ArgType.Int64, ArgType.Int64, ArgType.Int64, ArgType.Int64, ArgType.Int64);
_ = Libstapsdt.ProviderLoad(this.provider);
}

[GlobalCleanup]
public void GlobalCleanup()
{
_ = Libstapsdt.ProviderUnload(this.provider);
Libstapsdt.ProviderDestroy(this.provider);
}

[Benchmark]
public void ArgCount1() => Libstapsdt.ProbeFire(this.probe1, this.arg1);

[Benchmark]
public void ArgCount2() => Libstapsdt.ProbeFire(this.probe2, this.arg1, this.arg2);

[Benchmark]
public void ArgCount3() => Libstapsdt.ProbeFire(this.probe3, this.arg1, this.arg2, this.arg3);

[Benchmark]
public void ArgCount4() => Libstapsdt.ProbeFire(this.probe4, this.arg1, this.arg2, this.arg3, this.arg4);

[Benchmark]
public void ArgCount5() => Libstapsdt.ProbeFire(this.probe5, this.arg1, this.arg2, this.arg3, this.arg4, this.arg5);

[Benchmark]
public void ArgCount6() => Libstapsdt.ProbeFire(this.probe6, this.arg1, this.arg2, this.arg3, this.arg4, this.arg5, this.arg6);
}

public static class Program
{
public static void Main()
{
_ = BenchmarkRunner.Run<NotObservedProbeFireBenchmarks>();
}
}
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.400",
"rollForward": "latestPatch"
"version": "8.0.100",
"rollForward": "latestFeature"
}
}
15 changes: 11 additions & 4 deletions src/Libstapsdt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
#pragma warning disable CA5392 // Use DefaultDllImportSearchPaths attribute for P/Invokes
// ...but it has no effect on non-Windows platforms or the Mono runtime.

namespace Libstapsdt;
#pragma warning disable CA1401 // P/Invokes should not be visible
// ...the point of this library is to make P/Invokes visible.

namespace LibstapsdtPinvokes;

// Source: https://github.com/linux-usdt/libstapsdt/blob/0d53f987b0787362fd9c16a93cdad2c273d809fc/src/libstapsdt.h

static partial class Libstapsdt
public static partial class Libstapsdt
{
const string LibstapsdtLibrary = "libstapsdt.so.0";

Expand Down Expand Up @@ -125,7 +128,9 @@ enum SdtError // SDTError_t
SharedLibraryCloseError = 4 // sharedLibraryCloseError
}

enum ArgType // ArgType_t

#pragma warning disable CA1720 // Identifiers should not contain type names
public enum ArgType // ArgType_t
{
NoArg = 0, // noarg
UInt8 = 1, // uint8
Expand All @@ -138,7 +143,9 @@ enum ArgType // ArgType_t
Int64 = -8 // int64
}

enum MemfdOption // MemFDOption_t
#pragma warning restore CA1720 // Identifiers should not contain type names

public enum MemfdOption // MemFDOption_t
{
Disabled = 0, // memfd_disabled
Enabled = 1 // memfd_enabled
Expand Down
15 changes: 7 additions & 8 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@

using System.Globalization;
using System.Runtime.InteropServices;
using Libstapsdt;

using LibstapsdtPinvokes;

try
{
var providerName = "myprovider";
var probeName = "myprobe";

var provider = Libstapsdt.Libstapsdt.ProviderInit(providerName);
var provider = Libstapsdt.ProviderInit(providerName);

//Libstapsdt.Libstapsdt.ProviderUseMemfd(ref provider, MemFDOption_t.MemfdEnabled);
_ = Libstapsdt.ProviderUseMemfd(provider, MemfdOption.Enabled);

var probe = Libstapsdt.Libstapsdt.ProviderAddProbe(provider, probeName, ArgType.Int64, ArgType.UInt64);
var probe = Libstapsdt.ProviderAddProbe(provider, probeName, ArgType.Int64, ArgType.UInt64);
if (probe == IntPtr.Zero)
throw new Exception("Could not initialize the probe");

var res = Libstapsdt.Libstapsdt.ProviderLoad(provider);
var res = Libstapsdt.ProviderLoad(provider);
if (res != 0)
throw new Exception("Could not load provider");

Expand All @@ -33,13 +32,13 @@
var isoTimeStringPtr = Marshal.StringToCoTaskMemUTF8(isoTimeString);
try
{
Libstapsdt.Libstapsdt.ProbeFire(probe, val, isoTimeStringPtr);
Libstapsdt.ProbeFire(probe, val, isoTimeStringPtr);
}
finally
{
Marshal.FreeCoTaskMem(isoTimeStringPtr);
}
Console.WriteLine("Probe fired! Probe is currently {0}", Libstapsdt.Libstapsdt.ProbeIsEnabled(probe) ? "watched" : "not watched");
Console.WriteLine("Probe fired! Probe is currently {0}", Libstapsdt.ProbeIsEnabled(probe) ? "watched" : "not watched");
Thread.Sleep(500);
}
}
Expand Down