Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added extra error handling + start of availability charts + sortable …
…tables
  • Loading branch information
KBomba committed Dec 28, 2014
1 parent 3034cba commit 9a66719
Show file tree
Hide file tree
Showing 19 changed files with 558 additions and 129 deletions.
10 changes: 9 additions & 1 deletion ccMonitor.sln
@@ -1,10 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ccMonitor", "ccMonitor\ccMonitor.csproj", "{35A80F48-FF06-40FC-B048-DBBD911C2FA9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{57664A89-6876-4345-A9D9-1FD64A128E49}"
ProjectSection(SolutionItems) = preProject
Performance1.psess = Performance1.psess
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -19,4 +24,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal
19 changes: 18 additions & 1 deletion ccMonitor/Api/PruvotApi.cs
Expand Up @@ -44,6 +44,7 @@ public static T GetDictValue<T>(Dictionary<string, string> dictionary, string ke
return (T) Convert.ChangeType(value, typeof (T), CultureInfo.InvariantCulture);
}

// Unsigneds can't be negative
if (typeof(T) == typeof(uint)) return (T)Convert.ChangeType(9001, typeof(T), CultureInfo.InvariantCulture);
return (T) Convert.ChangeType(-1, typeof (T), CultureInfo.InvariantCulture);
}
Expand Down Expand Up @@ -83,7 +84,23 @@ public static string GetDictValue(Dictionary<string, string> dictionary, string

public static Dictionary<string, string>[] GetHistory(string ip = "127.0.0.1", int port = 4068, int minerMap = -1)
{
return minerMap == -1 ? Request(ip, port, "histo") : Request(ip, port, "histo|" + minerMap);
Dictionary<string, string>[] histo = Request(ip, port, "histo");

if (histo == null) return null;

bool existsInHisto = false;
foreach (Dictionary<string, string> log in histo)
{
if (GetDictValue<int>(log, "GPU") == minerMap)
{
existsInHisto = true;
break;
}
}

if(existsInHisto) return minerMap == -1 ? histo : Request(ip, port, "histo|" + minerMap);

return null;
}

public static Dictionary<string, string>[] GetPoolInfo(string ip = "127.0.0.1", int port = 4068)
Expand Down
30 changes: 28 additions & 2 deletions ccMonitor/GpuLogger.cs
Expand Up @@ -18,8 +18,34 @@ public class GpuInfo
public int MinerMap { get; set; }

public uint ComputeCapability { get; set; }

public bool Available { get; set; }

private bool _available;
public List<Tuple<long,bool>> AvailableTimeStamps { get; set; }
// long: unix timestamp, bool: availability
public bool Available
{
get { return _available; }
set
{
long unixTimeStamp = UnixTimeStamp();
if (AvailableTimeStamps == null)
{
AvailableTimeStamps = new List<Tuple<long, bool>>()
{
new Tuple<long, bool>(unixTimeStamp, value)
};
}
else
{
Tuple<long, bool> prevAvailableTimeStamp = AvailableTimeStamps[AvailableTimeStamps.Count - 1];
if (prevAvailableTimeStamp.Item1 != unixTimeStamp && prevAvailableTimeStamp.Item2 != value)
{
AvailableTimeStamps.Add(new Tuple<long, bool>(unixTimeStamp, value));
}
}
_available = value;
}
}

public override string ToString()
{
Expand Down
4 changes: 4 additions & 0 deletions ccMonitor/Gui/BenchmarkDetails.cs
@@ -1,5 +1,6 @@
using System;
using System.Globalization;
using System.IO;
using System.Windows.Forms;

namespace ccMonitor.Gui
Expand All @@ -12,10 +13,12 @@ public partial class BenchmarkDetails : UserControl

public BenchmarkDetails(GpuLogger.GpuInfo gpuInfo ,int rowsInLogViews = 5)
{

GpuInfo = gpuInfo;
_rowsInLogViews = rowsInLogViews;
InitializeComponent();
InitHashesAndSensors();

}

private void InitHashesAndSensors()
Expand All @@ -26,6 +29,7 @@ private void InitHashesAndSensors()

public void UpdateStats(GpuLogger.Benchmark benchmark)
{
if (benchmark == null) return;
UpdateSpread(benchmark.Statistic);
UpdateLogs(benchmark);
UpdateTextBoxes(benchmark);
Expand Down
2 changes: 1 addition & 1 deletion ccMonitor/Gui/BenchmarkOverview.cs
Expand Up @@ -18,7 +18,7 @@ public BenchmarkOverview(GpuLogger.Benchmark benchmark, GpuLogger.GpuInfo gpuInf
tabHashCharts.Controls.Add(hashChart);

SensorChart sensorChart = new SensorChart(9001) {Dock = DockStyle.Fill};
sensorChart.UpdateCharts(benchmark.SensorLog, benchmark.MinerSetup.OperatingSystem);
sensorChart.UpdateCharts(benchmark.SensorLog, gpuInfo.AvailableTimeStamps, benchmark.MinerSetup.OperatingSystem);
tabSensorCharts.Controls.Add(sensorChart);

}
Expand Down
53 changes: 28 additions & 25 deletions ccMonitor/Gui/GpuTab.cs
Expand Up @@ -48,31 +48,34 @@ private void InitGpuDetails()

public void UpdateGui()
{
UpdateInternalControls();

UserFriendlyBenchmarks = new List<UserFriendlyBenchmark>(Gpu.BenchLogs.Count);
foreach (GpuLogger.Benchmark benchmark in Gpu.BenchLogs)
if (Gpu.CurrentBenchmark != null && Gpu.BenchLogs != null && Gpu.BenchLogs.Count > 0)
{
UserFriendlyBenchmark userFriendlyBenchmark = new UserFriendlyBenchmark
UpdateInternalControls();

UserFriendlyBenchmarks = new List<UserFriendlyBenchmark>(Gpu.BenchLogs.Count);
foreach (GpuLogger.Benchmark benchmark in Gpu.BenchLogs)
{
TimeStarted = GuiHelper.UnixTimeStampToDateTime(benchmark.TimeStamp).ToString("g"),
TimeLastUpdate = GuiHelper.UnixTimeStampToDateTime(benchmark.SensorLog
[benchmark.SensorLog.Count - 1].TimeStamp).ToString("g"),
Algorithm = benchmark.Algorithm,
AverageHashRate = GuiHelper.GetRightMagnitude(benchmark.Statistic.AverageHashRate, "H"),
StandardDeviation = GuiHelper.GetRightMagnitude(benchmark.Statistic.StandardDeviation, "H"),
HashCount = GuiHelper.GetRightMagnitude(benchmark.Statistic.TotalHashCount),
AverageTemperature = benchmark.Statistic.AverageTemperature.ToString("##.##") + " °C",
MinerNameVersion = benchmark.MinerSetup.ToString(),
Stratum = benchmark.MinerSetup.MiningUrl
};
UserFriendlyBenchmark userFriendlyBenchmark = new UserFriendlyBenchmark
{
TimeStarted = GuiHelper.UnixTimeStampToDateTime(benchmark.TimeStamp).ToString("g"),
TimeLastUpdate = GuiHelper.UnixTimeStampToDateTime(benchmark.SensorLog
[benchmark.SensorLog.Count - 1].TimeStamp).ToString("g"),
Algorithm = benchmark.Algorithm,
AverageHashRate = GuiHelper.GetRightMagnitude(benchmark.Statistic.AverageHashRate, "H"),
StandardDeviation = GuiHelper.GetRightMagnitude(benchmark.Statistic.StandardDeviation, "H"),
HashCount = GuiHelper.GetRightMagnitude(benchmark.Statistic.TotalHashCount),
AverageTemperature = benchmark.Statistic.AverageTemperature.ToString("##.##") + " °C",
MinerNameVersion = benchmark.MinerSetup.ToString(),
Stratum = benchmark.MinerSetup.MiningUrl
};

UserFriendlyBenchmarks.Insert(0, userFriendlyBenchmark);
}
UserFriendlyBenchmarks.Insert(0, userFriendlyBenchmark);
}

int rowIndex = dgvBenchmarks.SelectedRows.Count > 0 ? dgvBenchmarks.SelectedRows[0].Index : 0;
dgvBenchmarks.DataSource = UserFriendlyBenchmarks;
if(dgvBenchmarks.Rows.Count > 0) dgvBenchmarks.CurrentCell = dgvBenchmarks.Rows[rowIndex].Cells[0];
int rowIndex = dgvBenchmarks.SelectedRows.Count > 0 ? dgvBenchmarks.SelectedRows[0].Index : 0;
dgvBenchmarks.DataSource = new SortableBindingList<UserFriendlyBenchmark>(UserFriendlyBenchmarks);
if (dgvBenchmarks.Rows.Count > 0) dgvBenchmarks.CurrentCell = dgvBenchmarks.Rows[rowIndex].Cells[0];
}
}

private void UpdateInternalControls()
Expand All @@ -94,10 +97,11 @@ private void UpdateInternalControls()

foreach (object control in tabSensorCharts.Controls)
{
SensorChart hashChart = control as SensorChart;
if (hashChart != null)
SensorChart sensorChartChart = control as SensorChart;
if (sensorChartChart != null)
{
hashChart.UpdateCharts(Gpu.CurrentBenchmark.SensorLog, Gpu.CurrentBenchmark.MinerSetup.OperatingSystem);
sensorChartChart.UpdateCharts(Gpu.CurrentBenchmark.SensorLog,
Gpu.Info.AvailableTimeStamps, Gpu.CurrentBenchmark.MinerSetup.OperatingSystem);
}
}
}
Expand All @@ -106,7 +110,6 @@ private void dgvBenchmarks_CellMouseDoubleClick(object sender, DataGridViewCellM
{
int rowIndex = e.RowIndex;
if(rowIndex<0) return;


BenchmarkOverview form = new BenchmarkOverview(Gpu.BenchLogs[Gpu.BenchLogs.Count - rowIndex - 1], Gpu.Info)
{
Expand Down
13 changes: 10 additions & 3 deletions ccMonitor/Gui/GuiHelper.cs
@@ -1,6 +1,4 @@
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace ccMonitor.Gui
{
Expand Down Expand Up @@ -31,7 +29,7 @@ public static long GetCurrentUnixTimeStamp()
return (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
}

[DllImport("user32.dll")]
/*[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);
private const int WmSetredraw = 11;
Expand All @@ -46,5 +44,14 @@ public static void ResumeDrawing(Control parent)
SendMessage(parent.Handle, WmSetredraw, true, 0);
parent.Refresh();
}
public static void ApplyAll(Control control, Action<Control> action)
{
action(control);
foreach (Control child in control.Controls)
{
ApplyAll(child, action);
}
}*/
}
}
5 changes: 3 additions & 2 deletions ccMonitor/Gui/HashChart.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions ccMonitor/Gui/HashChart.cs
Expand Up @@ -43,6 +43,38 @@ public void UpdateCharts(HashSet<GpuLogger.Benchmark.HashEntry> hashLogs)

chartHash.DataSource = chartFriendlyHashEntries;
chartHash.DataBind();

AutoFormatXAxis(chartFriendlyHashEntries);
}

private void AutoFormatXAxis(List<ChartFriendlyHashEntry> chartHashEntries)
{
int hours = _hours;
if (hours > 9000)
{
hours = (int)Math.Round((chartHashEntries[chartHashEntries.Count - 1].TimeStamp -
chartHashEntries[0].TimeStamp).TotalHours, MidpointRounding.AwayFromZero);
}

foreach (ChartArea chartArea in chartHash.ChartAreas)
{
if (hours < 6)
{
chartArea.AxisX.LabelStyle.Format = "ddd HH:mm:ss";
}
else if (hours < 320)
{
chartArea.AxisX.LabelStyle.Format = "MMM dd HH:mm";
}
else if (hours < 4600)
{
chartArea.AxisX.LabelStyle.Format = "MMM dd YY HH";
}
else
{
chartArea.AxisX.LabelStyle.Format = "MMM dd YYYY";
}
}
}

private void chart_MouseWheel(object sender, MouseEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion ccMonitor/Gui/HashLogView.cs
Expand Up @@ -55,7 +55,7 @@ public void UpdateLogs(HashSet<GpuLogger.Benchmark.HashEntry> hashLogs)
userFriendlyHashEntries.Add(userFriendlyHashEntry);
}

dgvHashLogs.DataSource = userFriendlyHashEntries;
dgvHashLogs.DataSource = new SortableBindingList<UserFriendlyHashEntry>(userFriendlyHashEntries);
}
}
}

0 comments on commit 9a66719

Please sign in to comment.