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

Performance Monitor Plugin #188

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
a88d0c1
block properties metrics
meevee98 Jan 24, 2020
57c80ff
helper methods
meevee98 Feb 27, 2020
a111972
other metrics
meevee98 Feb 27, 2020
efa546e
fix time in percentage calculation
meevee98 Feb 27, 2020
28cd1f9
cpu usage monitor
meevee98 Feb 27, 2020
8031850
io metrics
meevee98 Feb 27, 2020
93d9ea7
listen blockchain and remotes new blocks
meevee98 Feb 27, 2020
5d14b34
consensus algorithm metrics
meevee98 Feb 27, 2020
3038243
network protocol metrics
meevee98 Mar 2, 2020
91f41ed
rename plugin
meevee98 Mar 3, 2020
84d12bc
format
meevee98 Mar 3, 2020
0ffa0b8
separate main class in different files
meevee98 Mar 4, 2020
45b10a0
change comment and reorder methods
meevee98 Mar 4, 2020
d968149
add readme
Mar 6, 2020
d8a3d9b
fix remote height on connected and ping commands
meevee98 Mar 9, 2020
7048b9a
handle io exceptions
meevee98 Mar 9, 2020
3a7add8
fix results
meevee98 Mar 9, 2020
63f1c32
additional info
Mar 10, 2020
ad1bef9
fix typo
Mar 11, 2020
3af0a35
Merge branch 'master' into metrics-plugin
meevee98 Mar 11, 2020
8aef748
change precision
meevee98 Mar 11, 2020
09d615f
add note for consensus commands
Mar 12, 2020
f90f684
Merge pull request #7 from bettybao1209/metrics-plugin
melanke Mar 12, 2020
0d98aa3
show remote port on connected and ping
meevee98 Mar 16, 2020
a7b7067
remove check disk command
meevee98 Mar 16, 2020
4330963
refactor commands
meevee98 Mar 31, 2020
3740373
separate commands from the metrics calculation
meevee98 Apr 2, 2020
0ca9fc7
remove unnecessary iteration
meevee98 Apr 2, 2020
61f823b
Merge pull request #8 from simplitech/separate-commands
melanke Apr 2, 2020
9ea812f
add rpc methods
meevee98 Apr 7, 2020
49bdefc
don't print messages when calling rpc methods
meevee98 Apr 7, 2020
6e0f116
don't call CheckAllThreads twice to get the correct result
meevee98 Apr 8, 2020
85665b4
add rpc from refactored methods
meevee98 Apr 7, 2020
69648e7
Merge pull request #9 from simplitech/rpc-methods
melanke Apr 8, 2020
3dc3d7d
Merge pull request #10 from simplitech/rpc-refactored-methods
melanke Apr 8, 2020
3663fd9
Merge branch 'master' into metrics-plugin
meevee98 May 29, 2020
cba8144
update version
meevee98 May 29, 2020
7ab1374
get block timestamp
meevee98 May 29, 2020
e559e8b
print timestamp as datetime
meevee98 Jun 1, 2020
8a4d004
fix cpu high usage on block sync
meevee98 Jun 17, 2020
910cf6f
Merge branch 'master' into metrics-plugin
meevee98 Jul 6, 2020
14c3159
Merge branch 'master' into metrics-plugin
meevee98 Jul 9, 2020
c800081
code review
meevee98 Jul 9, 2020
fcfd339
Merge check cpu, threads and memory
meevee98 Jul 9, 2020
4efd244
Merge branch 'master' into metrics-plugin
meevee98 Jul 13, 2020
b4e4399
update commands limits and timeouts
meevee98 Jul 13, 2020
4245576
Merge branch 'master' into metrics-plugin
meevee98 Aug 4, 2020
203bd38
fix payload/confirmation time
meevee98 Aug 4, 2020
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
181 changes: 94 additions & 87 deletions neo-modules.sln
Original file line number Diff line number Diff line change
@@ -1,87 +1,94 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28729.10
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{97E81C78-1637-481F-9485-DA1225E94C23}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{59D802AB-C552-422A-B9C3-64D329FBCDCC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationLogs", "src\ApplicationLogs\ApplicationLogs.csproj", "{84DA8EA6-EF60-4FCD-B1C6-65C1A8323B3F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StatesDumper", "src\StatesDumper\StatesDumper.csproj", "{86531DB1-A231-46C4-823F-BE60972F7523}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcNep5Tracker", "src\RpcNep5Tracker\RpcNep5Tracker.csproj", "{BBE8AC15-12DF-4AF0-ABC1-F1557EB5DC8E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LevelDBStore", "src\LevelDBStore\LevelDBStore.csproj", "{C66214CD-0B97-4EA5-B7A2-164F54346F19}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RocksDBStore", "src\RocksDBStore\RocksDBStore.csproj", "{0E2AAF05-C55A-4B36-8750-F55743FBE4B3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcClient", "src\RpcClient\RpcClient.csproj", "{8DC57A45-A192-4953-81B1-6907FB7C28D2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcServer", "src\RpcServer\RpcServer.csproj", "{1403FFE9-4265-4269-8E3D-5A79EFD108CA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Network.RPC.Tests", "tests\Neo.Network.RPC.Tests\Neo.Network.RPC.Tests.csproj", "{D52460B3-AB5C-4D07-B400-9E7ADCB01FF5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Plugins.Storage.Tests", "tests\Neo.Plugins.Storage.Tests\Neo.Plugins.Storage.Tests.csproj", "{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{84DA8EA6-EF60-4FCD-B1C6-65C1A8323B3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84DA8EA6-EF60-4FCD-B1C6-65C1A8323B3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84DA8EA6-EF60-4FCD-B1C6-65C1A8323B3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84DA8EA6-EF60-4FCD-B1C6-65C1A8323B3F}.Release|Any CPU.Build.0 = Release|Any CPU
{86531DB1-A231-46C4-823F-BE60972F7523}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{86531DB1-A231-46C4-823F-BE60972F7523}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86531DB1-A231-46C4-823F-BE60972F7523}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86531DB1-A231-46C4-823F-BE60972F7523}.Release|Any CPU.Build.0 = Release|Any CPU
{BBE8AC15-12DF-4AF0-ABC1-F1557EB5DC8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BBE8AC15-12DF-4AF0-ABC1-F1557EB5DC8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BBE8AC15-12DF-4AF0-ABC1-F1557EB5DC8E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BBE8AC15-12DF-4AF0-ABC1-F1557EB5DC8E}.Release|Any CPU.Build.0 = Release|Any CPU
{C66214CD-0B97-4EA5-B7A2-164F54346F19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C66214CD-0B97-4EA5-B7A2-164F54346F19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C66214CD-0B97-4EA5-B7A2-164F54346F19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C66214CD-0B97-4EA5-B7A2-164F54346F19}.Release|Any CPU.Build.0 = Release|Any CPU
{0E2AAF05-C55A-4B36-8750-F55743FBE4B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E2AAF05-C55A-4B36-8750-F55743FBE4B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E2AAF05-C55A-4B36-8750-F55743FBE4B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E2AAF05-C55A-4B36-8750-F55743FBE4B3}.Release|Any CPU.Build.0 = Release|Any CPU
{8DC57A45-A192-4953-81B1-6907FB7C28D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8DC57A45-A192-4953-81B1-6907FB7C28D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8DC57A45-A192-4953-81B1-6907FB7C28D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8DC57A45-A192-4953-81B1-6907FB7C28D2}.Release|Any CPU.Build.0 = Release|Any CPU
{1403FFE9-4265-4269-8E3D-5A79EFD108CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1403FFE9-4265-4269-8E3D-5A79EFD108CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1403FFE9-4265-4269-8E3D-5A79EFD108CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1403FFE9-4265-4269-8E3D-5A79EFD108CA}.Release|Any CPU.Build.0 = Release|Any CPU
{D52460B3-AB5C-4D07-B400-9E7ADCB01FF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D52460B3-AB5C-4D07-B400-9E7ADCB01FF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D52460B3-AB5C-4D07-B400-9E7ADCB01FF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D52460B3-AB5C-4D07-B400-9E7ADCB01FF5}.Release|Any CPU.Build.0 = Release|Any CPU
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{84DA8EA6-EF60-4FCD-B1C6-65C1A8323B3F} = {97E81C78-1637-481F-9485-DA1225E94C23}
{86531DB1-A231-46C4-823F-BE60972F7523} = {97E81C78-1637-481F-9485-DA1225E94C23}
{BBE8AC15-12DF-4AF0-ABC1-F1557EB5DC8E} = {97E81C78-1637-481F-9485-DA1225E94C23}
{C66214CD-0B97-4EA5-B7A2-164F54346F19} = {97E81C78-1637-481F-9485-DA1225E94C23}
{0E2AAF05-C55A-4B36-8750-F55743FBE4B3} = {97E81C78-1637-481F-9485-DA1225E94C23}
{8DC57A45-A192-4953-81B1-6907FB7C28D2} = {97E81C78-1637-481F-9485-DA1225E94C23}
{1403FFE9-4265-4269-8E3D-5A79EFD108CA} = {97E81C78-1637-481F-9485-DA1225E94C23}
{D52460B3-AB5C-4D07-B400-9E7ADCB01FF5} = {59D802AB-C552-422A-B9C3-64D329FBCDCC}
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C} = {59D802AB-C552-422A-B9C3-64D329FBCDCC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61D3ADE6-BBFC-402D-AB42-1C71C9F9EDE3}
EndGlobalSection
EndGlobal
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28729.10
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{97E81C78-1637-481F-9485-DA1225E94C23}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{59D802AB-C552-422A-B9C3-64D329FBCDCC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationLogs", "src\ApplicationLogs\ApplicationLogs.csproj", "{84DA8EA6-EF60-4FCD-B1C6-65C1A8323B3F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StatesDumper", "src\StatesDumper\StatesDumper.csproj", "{86531DB1-A231-46C4-823F-BE60972F7523}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcNep5Tracker", "src\RpcNep5Tracker\RpcNep5Tracker.csproj", "{BBE8AC15-12DF-4AF0-ABC1-F1557EB5DC8E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LevelDBStore", "src\LevelDBStore\LevelDBStore.csproj", "{C66214CD-0B97-4EA5-B7A2-164F54346F19}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RocksDBStore", "src\RocksDBStore\RocksDBStore.csproj", "{0E2AAF05-C55A-4B36-8750-F55743FBE4B3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcClient", "src\RpcClient\RpcClient.csproj", "{8DC57A45-A192-4953-81B1-6907FB7C28D2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcServer", "src\RpcServer\RpcServer.csproj", "{1403FFE9-4265-4269-8E3D-5A79EFD108CA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Network.RPC.Tests", "tests\Neo.Network.RPC.Tests\Neo.Network.RPC.Tests.csproj", "{D52460B3-AB5C-4D07-B400-9E7ADCB01FF5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Plugins.Storage.Tests", "tests\Neo.Plugins.Storage.Tests\Neo.Plugins.Storage.Tests.csproj", "{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PerformanceMonitor", "src\PerformanceMonitor\PerformanceMonitor.csproj", "{4837193E-0A6E-4754-B042-8E694BC01794}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{84DA8EA6-EF60-4FCD-B1C6-65C1A8323B3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84DA8EA6-EF60-4FCD-B1C6-65C1A8323B3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84DA8EA6-EF60-4FCD-B1C6-65C1A8323B3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84DA8EA6-EF60-4FCD-B1C6-65C1A8323B3F}.Release|Any CPU.Build.0 = Release|Any CPU
{86531DB1-A231-46C4-823F-BE60972F7523}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{86531DB1-A231-46C4-823F-BE60972F7523}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86531DB1-A231-46C4-823F-BE60972F7523}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86531DB1-A231-46C4-823F-BE60972F7523}.Release|Any CPU.Build.0 = Release|Any CPU
{BBE8AC15-12DF-4AF0-ABC1-F1557EB5DC8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BBE8AC15-12DF-4AF0-ABC1-F1557EB5DC8E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BBE8AC15-12DF-4AF0-ABC1-F1557EB5DC8E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BBE8AC15-12DF-4AF0-ABC1-F1557EB5DC8E}.Release|Any CPU.Build.0 = Release|Any CPU
{C66214CD-0B97-4EA5-B7A2-164F54346F19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C66214CD-0B97-4EA5-B7A2-164F54346F19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C66214CD-0B97-4EA5-B7A2-164F54346F19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C66214CD-0B97-4EA5-B7A2-164F54346F19}.Release|Any CPU.Build.0 = Release|Any CPU
{0E2AAF05-C55A-4B36-8750-F55743FBE4B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E2AAF05-C55A-4B36-8750-F55743FBE4B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E2AAF05-C55A-4B36-8750-F55743FBE4B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E2AAF05-C55A-4B36-8750-F55743FBE4B3}.Release|Any CPU.Build.0 = Release|Any CPU
{8DC57A45-A192-4953-81B1-6907FB7C28D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8DC57A45-A192-4953-81B1-6907FB7C28D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8DC57A45-A192-4953-81B1-6907FB7C28D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8DC57A45-A192-4953-81B1-6907FB7C28D2}.Release|Any CPU.Build.0 = Release|Any CPU
{1403FFE9-4265-4269-8E3D-5A79EFD108CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1403FFE9-4265-4269-8E3D-5A79EFD108CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1403FFE9-4265-4269-8E3D-5A79EFD108CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1403FFE9-4265-4269-8E3D-5A79EFD108CA}.Release|Any CPU.Build.0 = Release|Any CPU
{D52460B3-AB5C-4D07-B400-9E7ADCB01FF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D52460B3-AB5C-4D07-B400-9E7ADCB01FF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D52460B3-AB5C-4D07-B400-9E7ADCB01FF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D52460B3-AB5C-4D07-B400-9E7ADCB01FF5}.Release|Any CPU.Build.0 = Release|Any CPU
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C}.Release|Any CPU.Build.0 = Release|Any CPU
{4837193E-0A6E-4754-B042-8E694BC01794}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4837193E-0A6E-4754-B042-8E694BC01794}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4837193E-0A6E-4754-B042-8E694BC01794}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4837193E-0A6E-4754-B042-8E694BC01794}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{84DA8EA6-EF60-4FCD-B1C6-65C1A8323B3F} = {97E81C78-1637-481F-9485-DA1225E94C23}
{86531DB1-A231-46C4-823F-BE60972F7523} = {97E81C78-1637-481F-9485-DA1225E94C23}
{BBE8AC15-12DF-4AF0-ABC1-F1557EB5DC8E} = {97E81C78-1637-481F-9485-DA1225E94C23}
{C66214CD-0B97-4EA5-B7A2-164F54346F19} = {97E81C78-1637-481F-9485-DA1225E94C23}
{0E2AAF05-C55A-4B36-8750-F55743FBE4B3} = {97E81C78-1637-481F-9485-DA1225E94C23}
{8DC57A45-A192-4953-81B1-6907FB7C28D2} = {97E81C78-1637-481F-9485-DA1225E94C23}
{1403FFE9-4265-4269-8E3D-5A79EFD108CA} = {97E81C78-1637-481F-9485-DA1225E94C23}
{D52460B3-AB5C-4D07-B400-9E7ADCB01FF5} = {59D802AB-C552-422A-B9C3-64D329FBCDCC}
{9E7EA895-302A-4C0C-BA9B-54F9A67AD75C} = {59D802AB-C552-422A-B9C3-64D329FBCDCC}
{4837193E-0A6E-4754-B042-8E694BC01794} = {97E81C78-1637-481F-9485-DA1225E94C23}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61D3ADE6-BBFC-402D-AB42-1C71C9F9EDE3}
EndGlobalSection
EndGlobal
114 changes: 114 additions & 0 deletions src/PerformanceMonitor/BlockHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using System.Collections.Generic;

namespace Neo.Plugins
{
internal static class BlockHelper
{
/// <summary>
/// Returns the time the given block was active
/// </summary>
/// <param name="block">
/// The given block to verify the time
/// </param>
/// <returns>
/// Returns 0 if <paramref name="block"/> is the current block or it is the genesis block or it is null;
/// otherwise, returns the time the block was active in milliseconds
/// </returns>
public static ulong GetTime(this Block block)
meevee98 marked this conversation as resolved.
Show resolved Hide resolved
{
ulong time = 0;

if (block != null && block.Index > 0 && block.Index < Blockchain.Singleton.Height)
{
var nextBlock = Blockchain.Singleton.GetBlock(block.Index + 1);

if (nextBlock != null)
{
time = nextBlock.Timestamp - block.Timestamp;
}
}

return time;
}

/// <summary>
/// Returns the average time the latest blocks are active
/// </summary>
/// <param name="desiredCount">
/// The desired number of blocks that should be checked to calculate the average time
/// </param>
/// <returns>
/// Returns the average time per block in milliseconds if the number of analysed blocks
/// is greater than zero; otherwise, returns 0.0
/// </returns>
public static double GetAverageTimePerBlock(this SnapshotView snapshot, uint desiredCount)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned above, I see a logic like this more useful:

private JObject GetBlocksTime(uint nBlocks, uint lastHeight)
        {
            // It is currently limited to query blocks generated in the last 24hours (86400 seconds)
            uint maxNBlocksPerDay = 86400 / (Blockchain.MillisecondsPerBlock / 1000);
            if (lastHeight != 0)
            {
                if (lastHeight >= Blockchain.Singleton.Height)
                {
                    JObject json = new JObject();
                    return json["error"] = "Requested height to start " + lastHeight + " exceeds " + Blockchain.Singleton.Height;
                }

                if (nBlocks > lastHeight)
                {
                    JObject json = new JObject();
                    return json["error"] = "Requested " + nBlocks + " blocks timestamps is greater than starting at height " + lastHeight;
                }
            }

            if (nBlocks > maxNBlocksPerDay)
            {
                JObject json = new JObject();
                return json["error"] = "Requested number of blocks timestamps exceeds " + maxNBlocksPerDay;
            }

            if (nBlocks >= Blockchain.Singleton.Height)
            {
                JObject json = new JObject();
                return json["error"] = "Requested number of blocks timestamps " + nBlocks + " exceeds quantity of known blocks " + Blockchain.Singleton.Height;
            }

            if (nBlocks == 0)
            {
                JObject json = new JObject();
                return json["error"] = "Requested number of block times can not be = 0";
            }

            JArray array = new JArray();
            uint heightToBegin = lastHeight > 0 ? lastHeight - nBlocks : (Blockchain.Singleton.Height - 1) - nBlocks;
            for (uint i = heightToBegin; i <= heightToBegin + nBlocks; i++)
            {
                Header header = Blockchain.Singleton.GetHeader(i);
                if (header == null) break;

                JObject json = new JObject();
                json["timestamp"] = header.Timestamp;
                json["height"] = i;
                array.Add(json);
            }

            return array;
        }

You can pass begin and count.
This code can be adjusted for average if you do not want to return an array of values, which I see as useful.

{
var firstIndex = Blockchain.GenesisBlock.Index;
var blockHash = snapshot.CurrentBlockHash;

var countedBlocks = -1;
Block block = snapshot.GetBlock(blockHash);
ulong totaltime = 0;

do
{
totaltime += block.GetTime();
block = snapshot.GetBlock(block.PrevHash);
countedBlocks++;
} while (block != null && block.Index != firstIndex && desiredCount > countedBlocks);

double averageTime = 0.0;
if (countedBlocks > 0)
{
averageTime = 1.0 * totaltime / countedBlocks;
}

return averageTime;
}

/// <summary>
/// Returns the block timestamp for each of the n latest blocks.
/// </summary>
/// <param name="desiredCount">
/// The desired number of blocks that should map the timestamp
/// </param>
/// <param name="lastHeight">
/// The current height of the blockchain
/// </param>
/// <returns>
/// Returns a dictionary that maps each block index with its timestamp if the number of blocks
/// is greater than zero; otherwise, returns an empty dictionary.
/// </returns>
public static Dictionary<uint, ulong> GetBlocksTimestamp(this SnapshotView snapshot, uint desiredCount, Block lastBlock = null)
{
var dictionary = new Dictionary<uint, ulong>();
var firstIndex = Blockchain.GenesisBlock.Index;
var blockHash = snapshot.CurrentBlockHash;

var countedBlocks = 0;
Block block;

if (lastBlock != null && lastBlock.Index < snapshot.Height)
{
block = lastBlock;
}
else
{
block = snapshot.GetBlock(blockHash);
}

while (block != null && block.Index != firstIndex && desiredCount > countedBlocks)
{
dictionary.Add(block.Index, block.Timestamp);

block = snapshot.GetBlock(block.PrevHash);
countedBlocks++;
}

return dictionary;
}
}
}
Loading