-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove warnings from build
- Loading branch information
Showing
16 changed files
with
507 additions
and
339 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
GameServer/PerformanceStatistics/CurrentProcessCpuUsageStatistics.cs
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,61 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.Versioning; | ||
|
||
namespace DOL.PerformanceStatistics | ||
{ | ||
public class CurrentProcessCpuUsagePercentStatistic : IPerformanceStatistic | ||
{ | ||
private IPerformanceStatistic processorTimeRatioStatistic; | ||
|
||
public CurrentProcessCpuUsagePercentStatistic() | ||
{ | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
processorTimeRatioStatistic = new PerformanceCounterStatistic("Process", "% processor time", Process.GetCurrentProcess().ProcessName); | ||
} | ||
else | ||
{ | ||
processorTimeRatioStatistic = new LinuxCurrentProcessUsagePercentStatistic(); | ||
} | ||
} | ||
|
||
public float GetNextValue() | ||
=> processorTimeRatioStatistic.GetNextValue(); | ||
} | ||
|
||
#if NET | ||
[UnsupportedOSPlatform("Windows")] | ||
#endif | ||
internal class LinuxCurrentProcessUsagePercentStatistic : IPerformanceStatistic | ||
{ | ||
private IPerformanceStatistic idleProcessorTimeStatistic = new PerSecondStatistic(new LinuxSystemIdleProcessorTimeInSeconds()); | ||
private IPerformanceStatistic totalProcessorTimeStatistic = new PerSecondStatistic(new LinuxTotalProcessorTimeInSeconds()); | ||
private IPerformanceStatistic currentProcessProcessorTimeStatistic = new PerSecondStatistic(new LinuxCurrentProcessProcessorTimeInSeconds()); | ||
|
||
public float GetNextValue() | ||
{ | ||
var idleTime = idleProcessorTimeStatistic.GetNextValue(); | ||
var totalTime = totalProcessorTimeStatistic.GetNextValue(); | ||
var processTime = currentProcessProcessorTimeStatistic.GetNextValue(); | ||
return processTime / totalTime * 100 * Environment.ProcessorCount; | ||
} | ||
} | ||
|
||
#if NET | ||
[UnsupportedOSPlatform("Windows")] | ||
#endif | ||
internal class LinuxCurrentProcessProcessorTimeInSeconds : IPerformanceStatistic | ||
{ | ||
public float GetNextValue() | ||
{ | ||
var pid = Process.GetCurrentProcess().Id; | ||
var statArray = File.ReadAllText($"/proc/{pid}/stat").Split(' '); | ||
var processorTime = Convert.ToInt64(statArray[13]) + Convert.ToInt64(statArray[14]); | ||
return processorTime * 0.001f; | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
GameServer/PerformanceStatistics/DiskTransferStatistics.cs
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,52 @@ | ||
using System; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.Versioning; | ||
|
||
namespace DOL.PerformanceStatistics | ||
{ | ||
public class DiskTransfersPerSecondStatistic : IPerformanceStatistic | ||
{ | ||
IPerformanceStatistic performanceStatistic; | ||
|
||
public DiskTransfersPerSecondStatistic() | ||
{ | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
performanceStatistic = new PerformanceCounterStatistic("PhysicalDisk", "Disk Transfers/sec", "_Total"); | ||
} | ||
else | ||
{ | ||
performanceStatistic = new PerSecondStatistic(new LinuxTotalDiskTransfers()); | ||
} | ||
} | ||
|
||
public float GetNextValue() => performanceStatistic.GetNextValue(); | ||
} | ||
|
||
#if NET | ||
[UnsupportedOSPlatform("Windows")] | ||
#endif | ||
internal class LinuxTotalDiskTransfers : IPerformanceStatistic | ||
{ | ||
public float GetNextValue() | ||
{ | ||
var diskstats = File.ReadAllText("/proc/diskstats"); | ||
var transferCount = 0L; | ||
foreach (var line in diskstats.Split('\n')) | ||
{ | ||
var columns = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); | ||
if (columns.Length < 14) continue; | ||
var deviceName = columns[2]; | ||
if (char.IsDigit(deviceName[deviceName.Length - 1])) continue; | ||
|
||
var readIO = Convert.ToInt64(columns[3]); | ||
var writeIO = Convert.ToInt64(columns[7]); | ||
var discardIO = 0L; | ||
if (columns.Length >= 18) discardIO = Convert.ToInt64(columns[14]); | ||
transferCount += (readIO + writeIO + discardIO); | ||
} | ||
return transferCount; | ||
} | ||
} | ||
} |
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,7 @@ | ||
namespace DOL.PerformanceStatistics | ||
{ | ||
public interface IPerformanceStatistic | ||
{ | ||
float GetNextValue(); | ||
} | ||
} |
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,52 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.Versioning; | ||
|
||
namespace DOL.PerformanceStatistics | ||
{ | ||
public class PageFaultsPerSecondStatistic : IPerformanceStatistic | ||
{ | ||
IPerformanceStatistic performanceStatistic; | ||
|
||
public PageFaultsPerSecondStatistic() | ||
{ | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
performanceStatistic = new PerformanceCounterStatistic("Memory", "Pages/sec", null); | ||
} | ||
else | ||
{ | ||
performanceStatistic = new LinuxPageFaultsPerSecondStatistic(); | ||
} | ||
} | ||
|
||
public float GetNextValue() => performanceStatistic.GetNextValue(); | ||
} | ||
|
||
#if NET | ||
[UnsupportedOSPlatform("Windows")] | ||
#endif | ||
internal class LinuxPageFaultsPerSecondStatistic : IPerformanceStatistic | ||
{ | ||
private IPerformanceStatistic memoryFaultsPerSecondStatistic; | ||
|
||
public LinuxPageFaultsPerSecondStatistic() | ||
{ | ||
memoryFaultsPerSecondStatistic = new PerSecondStatistic(new LinuxTotalPageFaults()); | ||
} | ||
|
||
public float GetNextValue() => memoryFaultsPerSecondStatistic.GetNextValue(); | ||
} | ||
|
||
internal class LinuxTotalPageFaults : IPerformanceStatistic | ||
{ | ||
public float GetNextValue() | ||
{ | ||
return Convert.ToInt64(File.ReadAllText("/proc/vmstat").Split('\n') | ||
.Where(s => s.StartsWith("pgfault")) | ||
.First().Split(' ')[1]); | ||
} | ||
} | ||
} |
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,40 @@ | ||
using System; | ||
using System.Reflection; | ||
using log4net; | ||
|
||
namespace DOL.PerformanceStatistics | ||
{ | ||
internal class PerSecondStatistic : IPerformanceStatistic | ||
{ | ||
private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
|
||
DateTime lastMeasurementTime; | ||
float lastTotal; | ||
IPerformanceStatistic totalValueStatistic; | ||
float cachedLastStatisticValue = -1; | ||
|
||
public PerSecondStatistic(IPerformanceStatistic totalValueStatistic) | ||
{ | ||
lastMeasurementTime = DateTime.UtcNow; | ||
this.totalValueStatistic = totalValueStatistic; | ||
lastTotal = totalValueStatistic.GetNextValue(); | ||
} | ||
|
||
public float GetNextValue() | ||
{ | ||
if (totalValueStatistic == null) return -1; | ||
var currentTime = DateTime.UtcNow; | ||
var secondsPassed = (currentTime - lastMeasurementTime).TotalSeconds; | ||
if (secondsPassed < 1) return cachedLastStatisticValue; | ||
|
||
var currentTotal = totalValueStatistic.GetNextValue(); | ||
var valuePerSecond = (currentTotal - lastTotal) / secondsPassed; | ||
|
||
lastMeasurementTime = currentTime; | ||
lastTotal = currentTotal; | ||
cachedLastStatisticValue = (float)valuePerSecond; | ||
return cachedLastStatisticValue; | ||
} | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
GameServer/PerformanceStatistics/PerformaceCounterStatistics.cs
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,21 @@ | ||
using System.Diagnostics; | ||
using System.Runtime.Versioning; | ||
|
||
namespace DOL.PerformanceStatistics | ||
{ | ||
#if NET | ||
[SupportedOSPlatform("Windows")] | ||
#endif | ||
public class PerformanceCounterStatistic : IPerformanceStatistic | ||
{ | ||
private PerformanceCounter performanceCounter; | ||
|
||
public PerformanceCounterStatistic(string categoryName, string counterName, string instanceName) | ||
{ | ||
performanceCounter = new PerformanceCounter(categoryName, counterName, instanceName); | ||
performanceCounter.NextValue(); | ||
} | ||
|
||
public float GetNextValue() => performanceCounter.NextValue(); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
GameServer/PerformanceStatistics/SystemCpuUsageStatistics.cs
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,77 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.Versioning; | ||
|
||
namespace DOL.PerformanceStatistics | ||
{ | ||
public class SystemCpuUsagePercent : IPerformanceStatistic | ||
{ | ||
private IPerformanceStatistic processorTimeRatioStatistic; | ||
|
||
public SystemCpuUsagePercent() | ||
{ | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
processorTimeRatioStatistic = new PerformanceCounterStatistic("Processor", "% processor time", "_total"); | ||
} | ||
else | ||
{ | ||
processorTimeRatioStatistic = new LinuxSystemCpuUsagePercent(); | ||
} | ||
} | ||
|
||
public float GetNextValue() | ||
=> processorTimeRatioStatistic.GetNextValue(); | ||
} | ||
|
||
#if NET | ||
[UnsupportedOSPlatform("Windows")] | ||
#endif | ||
internal class LinuxSystemCpuUsagePercent : IPerformanceStatistic | ||
{ | ||
private IPerformanceStatistic processorTimeStatistic; | ||
private IPerformanceStatistic idleTimeStatistic; | ||
|
||
public LinuxSystemCpuUsagePercent() | ||
{ | ||
processorTimeStatistic = new PerSecondStatistic(new LinuxTotalProcessorTimeInSeconds()); | ||
idleTimeStatistic = new PerSecondStatistic(new LinuxSystemIdleProcessorTimeInSeconds()); | ||
} | ||
|
||
public float GetNextValue() | ||
{ | ||
var cpuUsage = (1 - (idleTimeStatistic.GetNextValue() / processorTimeStatistic.GetNextValue())); | ||
return cpuUsage * 100; | ||
} | ||
} | ||
|
||
#if NET | ||
[UnsupportedOSPlatform("Windows")] | ||
#endif | ||
internal class LinuxTotalProcessorTimeInSeconds : IPerformanceStatistic | ||
{ | ||
public float GetNextValue() | ||
{ | ||
var cpuTimeInSeconds = File.ReadAllText("/proc/stat").Split('\n') | ||
.First().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) | ||
.Skip(1).Select(c => Convert.ToInt64(c)).Aggregate(0L, (a, b) => a + b) * 0.001f; | ||
return cpuTimeInSeconds; | ||
} | ||
} | ||
|
||
#if NET | ||
[UnsupportedOSPlatform("Windows")] | ||
#endif | ||
internal class LinuxSystemIdleProcessorTimeInSeconds : IPerformanceStatistic | ||
{ | ||
public float GetNextValue() | ||
{ | ||
var cpuIdleTimeString = File.ReadAllText("/proc/stat").Split('\n') | ||
.First().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)[4]; | ||
var cpuIdleTimeInSeconds = Convert.ToInt64(cpuIdleTimeString) * 0.001f; | ||
return cpuIdleTimeInSeconds; | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.