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

add a benchmark Github Action and add comments #3581

Merged
merged 6 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 2 additions & 0 deletions .bettercodehub.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Depth of components to analyze (2 levels deep)
component_depth: 2

# Programming languages to analyze
languages:
- csharp
48 changes: 48 additions & 0 deletions .github/workflows/benchmark_action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: benchmark_action
on:
push:
tags:
- '**'
branches:
- '**'



env:
DOTNET_INSTALL_DIR: "./.dotnet"
Solution_Name: AElf.All.sln
Service_Name: AELF

jobs:
test:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0'

- name: 'Download AElf build tools'
run: bash scripts/download_binary.sh

- name: 'Install protobuf'
run: bash scripts/install_protobuf.sh

- name: Install dependencies
run: dotnet restore bench/AElf.Benchmark/AElf.Benchmark.csproj --verbosity quiet

- name: BenchMark
run: |
cd bench/AElf.Benchmark
dotnet run --filter '*MinerTests*'
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ env.Service_Name }}
path: bench/AElf.Benchmark/BenchmarkDotNet.Artifacts/results
retention-days: 30
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,4 @@ tools
.idea/.idea.AElf/.idea/projectSettingsUpdater.xml
.idea/.idea.AElf/.idea/vcs.xml
.idea/.idea.AElf/.idea/workspace.xml
.idea/.idea.AElf/riderModule.iml
.idea/.idea.AElf/riderModule.iml
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sphinx:
# Optionally build your docs in additional formats such as PDF and ePub
formats: all

# Optionally set the version of Python and requirements required to build your docs
# Optionally set the version of python and requirements required to build your docs
python:
version: 3.7
install:
Expand Down
3 changes: 2 additions & 1 deletion AElf.ContractTools.targets
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
</PropertyGroup>
</Otherwise>
</Choose>


<!-- Generate protobuf code before building and getting the target path -->
<Target Name="GenerateProtobufCode" BeforeTargets="BeforeBuild;GetTargetPath">
<PropertyGroup>
<LocalProtobufDir>$(ProjectDir)/Protobuf</LocalProtobufDir>
Expand Down
3 changes: 1 addition & 2 deletions AElf.Contracts.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "contract", "contract", "{651F0F6E-86CF-42D2-9110-5F3EAE5704F0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{26990847-E0A2-4FCC-8C71-267CA77557CD}"
Expand Down
29 changes: 16 additions & 13 deletions AElf.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml"
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeEditing/SuppressNullableWarningFix/Enabled/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=JS/@EntryIndexedValue">JS</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=aelf/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=appsettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=blockchain/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Blockchains/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DPOS/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=grpc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=hangfire/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Merkle/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=pubkey/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ssdb/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Xunit/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=JS/@EntryIndexedValue">JS</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=aelf/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=appsettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=blockchain/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Blockchains/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DPOS/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=grpc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=hangfire/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Merkle/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=pubkey/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ssdb/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Xunit/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
1 change: 1 addition & 0 deletions CodeCoverage.runsettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This XML defines run settings for code coverage. -->
<!-- File name extension must be .runsettings -->
<RunSettings>
<DataCollectionRunSettings>
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# appveyor configuration file
version: 1.0.0.{build}
skip_tags: true
os: Windows Server 2012 R2
Expand Down
1 change: 1 addition & 0 deletions azure-myget-publish.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Azure DevOps pipeline configuration for publishing NuGet packages to MyGet
pool:
vmImage: ubuntu-latest
pr: none
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# File: azure-pipelines.yml
# Azure Pipelines configuration file
jobs:
- template: templates/build-template-window.yml
parameters:
Expand Down
82 changes: 82 additions & 0 deletions bench/AElf.Benchmark/HtmlSummaryExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Reports;

using System.Collections.Generic;
using System.IO;


public class HtmlSummaryExporter : IExporter
{
public string Name => nameof(HtmlSummaryExporter);

public void ExportToLog(Summary summary, ILogger logger)
{

}

public IEnumerable<string> ExportToFiles(Summary summary, ILogger consoleLogger)
{
string directoryPath = summary.ResultsDirectoryPath;
string outputPath = Path.Combine(directoryPath, "Summary.html");

var htmlFiles = Directory.GetFiles(directoryPath, "*.html");

using (StreamWriter writer = new StreamWriter(outputPath))
{
writer.WriteLine("<html>");
writer.WriteLine("<head>");
writer.WriteLine("<title>Benchmark Summary</title>");

writer.WriteLine("<style>");
foreach (var file in htmlFiles)
{
string content = File.ReadAllText(file);
string styleContent = GetStyleContent(content);
writer.WriteLine(styleContent);
}
writer.WriteLine("</style>");

writer.WriteLine("</head>");
writer.WriteLine("<body>");

foreach (var file in htmlFiles)
{
string fileName = Path.GetFileName(file);
writer.WriteLine($"<h2>{fileName}</h2>");
string content = File.ReadAllText(file);
string bodyContent = GetBodyContent(content);
writer.WriteLine(bodyContent);
}

writer.WriteLine("</body>");
writer.WriteLine("</html>");
}

consoleLogger.WriteLine($"Summary HTML file created successfully at {outputPath}.");

return new[] { outputPath };
}

private string GetBodyContent(string html)
{
int bodyStartIndex = html.IndexOf("<body>") + "<body>".Length;
int bodyEndIndex = html.IndexOf("</body>");
if (bodyStartIndex >= 0 && bodyEndIndex >= 0)
{
return html.Substring(bodyStartIndex, bodyEndIndex - bodyStartIndex);
}
return string.Empty;
}

private string GetStyleContent(string html)
{
int styleStartIndex = html.IndexOf("<style>") + "<style>".Length;
int styleEndIndex = html.IndexOf("</style>");
if (styleStartIndex >= 0 && styleEndIndex >= 0)
{
return html.Substring(styleStartIndex, styleEndIndex - styleStartIndex);
}
return string.Empty;
}
}
13 changes: 11 additions & 2 deletions bench/AElf.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
using System.IO;
using System.Reflection;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.Csv;
using BenchmarkDotNet.Exporters.Xml;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using Volo.Abp;

Expand All @@ -18,8 +22,13 @@ private static void Main(string[] args)
}))
{
application.Initialize();
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, new DebugInProcessConfig());
}
var config = new DebugInProcessConfig()
.WithSummaryStyle(SummaryStyle.Default.WithMaxParameterColumnWidth(50))
.AddExporter(XmlExporter.Default)
.AddExporter(HtmlExporter.Default)
.AddExporter(new HtmlSummaryExporter())
.AddExporter(CsvExporter.Default);
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args, config); }
}

private static void RegisterAssemblyResolveEvent()
Expand Down
1 change: 0 additions & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ Task("Test-with-Codecov")
actions.Add(action);
}


var options = new ParallelOptions {
MaxDegreeOfParallelism = 1,
//CancellationToken = cancellationToken
Expand Down
2 changes: 1 addition & 1 deletion build.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
CAKE_VERSION=0.37.0
DOTNET_VERSION=6.0.300
DOTNET_VERSION=6.0.300
1 change: 1 addition & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent

[string] $CakeVersion = ''
[string] $DotNetVersion= ''

foreach($line in Get-Content (Join-Path $PSScriptRoot 'build.config'))
{
if ($line -like 'CAKE_VERSION=*') {
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Define varibles
# Define variables
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPT_DIR/build.config
TOOLS_DIR=$SCRIPT_DIR/tools
Expand Down
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
<None Include="../../LICENSE" Pack="true" PackagePath=""/>
</ItemGroup>

</Project>
</Project>
1 change: 0 additions & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ services:
- 8001:8000
volumes:
- /opt:/opt

1 change: 0 additions & 1 deletion docker/start-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
BIND_VOLUME='-v /opt:/opt'
CONFIGURE_PATH='-w /opt/aelf-node'
docker run -it --rm $BIND_VOLUME $CONFIGURE_PATH aelf/node

2 changes: 1 addition & 1 deletion docker/start-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
PUBLISH_PORT='-p 6800:6800 -p 8000:8000'
BIND_VOLUME='-v /opt:/opt'
CONfIGURE_PATH='/opt/aelf-node'
docker run -itd $PUBLISH_PORT $BIND_VOLUME -w $CONfIGURE_PATH aelf/node dotnet /app/AElf.Launcher.dll --config.path $CONfIGURE_PATH
docker run -itd $PUBLISH_PORT $BIND_VOLUME -w $CONfIGURE_PATH aelf/node dotnet /app/AElf.Launcher.dll --config.path $CONfIGURE_PATH
2 changes: 1 addition & 1 deletion docs-sphinx/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ Welcome to AElf's official documentation!

tutorials/cross-chain/running-side-chain
tutorials/__run-node
getting-started/smart-contract-development/developing-smart-contracts/index
getting-started/smart-contract-development/developing-smart-contracts/index
2 changes: 1 addition & 1 deletion docs/main-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@
* [Google cloud](resources/cloud/gcp/GCP.md)
* [Browser Extension](resources/browser-extension.md)
* [Joining AElf's testnet](resources/testnet.md)
* [Running a side chain](tutorials/cross-chain/running-side-chain.md)
* [Running a side chain](tutorials/cross-chain/running-side-chain.md)
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ dotnet build /clp:ErrorsOnly /p:GeneratePackageOnBuild=false -v quiet "AElf.All.
if [[ $? -ne 0 ]] ; then
echo "Build failed."
exit 1
fi
fi
2 changes: 1 addition & 1 deletion scripts/deploy_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ docker build -t aelf/node:${TAG} ~/aelf/.
docker tag aelf/node:${TAG} aelf/node:latest
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
docker push aelf/node:${TAG}
docker push aelf/node:latest
docker push aelf/node:latest
2 changes: 1 addition & 1 deletion scripts/deploy_myget.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ do
fi
done
cd ../
done
done
2 changes: 1 addition & 1 deletion scripts/deploy_myget_daily.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ do
fi
done
cd ../
done
done
2 changes: 1 addition & 1 deletion scripts/deploy_nuget.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ do
fi
done
cd ../
done
done
2 changes: 1 addition & 1 deletion scripts/download_binary.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ if not exist "%scriptdir%contract_csharp_plugin.exe" (
)
echo "unzip file: %file%"
unzip %scriptdir%%filename% -d %scriptdir%
)
)
2 changes: 1 addition & 1 deletion scripts/download_binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ if [[ ! -f ${plugin} ]]; then

# Unzip
unzip -o ${filename} -d "${scriptdir}"
fi
fi
2 changes: 1 addition & 1 deletion scripts/generate_contract_base.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ protoc --proto_path=../../protobuf ^
--contract_opt=%2,nocontract ^
--contract_out=./Protobuf/Generated ^
--plugin=protoc-gen-contract="%scriptdir%contract_csharp_plugin.exe" ^
%1
%1
2 changes: 1 addition & 1 deletion scripts/generate_contract_base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ protoc --proto_path=${solutiondir}/protobuf \
--contract_opt="$2",nocontract \
--contract_out=./Protobuf/Generated \
--plugin=protoc-gen-contract=${plugin} \
$1
$1
2 changes: 1 addition & 1 deletion scripts/generate_contract_code.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ protoc --proto_path=../../protobuf ^
--csharp_opt=file_extension=.g.cs ^
--contract_out=./Protobuf/Generated ^
--plugin=protoc-gen-contract="%scriptdir%contract_csharp_plugin.exe" ^
%*
%*
2 changes: 1 addition & 1 deletion scripts/generate_contract_code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ protoc --proto_path=${solutiondir}/protobuf \
--csharp_opt=file_extension=.g.cs \
--contract_out=./Protobuf/Generated \
--plugin=protoc-gen-contract=${plugin} \
$@
$@
Loading
Loading