Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Web/Hive-3.4/Status.aspx.cs @ 6721

Last change on this file since 6721 was 6721, checked in by ascheibe, 13 years ago

#1233 Review comments: renamed Job to Task

File size: 5.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Web;
5using System.Web.UI;
6using System.Web.UI.WebControls;
7using HeuristicLab.Services.Hive.DataAccess;
8using HeuristicLab.Services.Hive;
9using HeuristicLab.Services.Hive.DataTransfer;
10using System.Text;
11using System.Web.UI.DataVisualization.Charting;
12using DA = HeuristicLab.Services.Hive.DataAccess;
13
14public partial class Status : System.Web.UI.Page {
15  protected void Page_Load(object sender, EventArgs e) {
16    var dao = ServiceLocator.Instance.HiveDao;
17    var resourceName = Request.QueryString["resource"];
18    IEnumerable<Guid> resourceIds;
19    if (!string.IsNullOrEmpty(resourceName)) {
20      var resId = dao.GetResources(x => x.Name == resourceName).Single().Id;
21      resourceIds = dao.GetChildResources(resId).Select(x => x.Id).Union(new List<Guid> { resId });
22      speedupChartHours.Visible = false;
23      speedupChartMinutes.Visible = false;
24    } else {
25      resourceIds = dao.GetResources(x => true).Select(y => y.Id);
26      speedupChartHours.Visible = true;
27      speedupChartMinutes.Visible = true;
28    }
29                                 
30    var onlineSlaves = dao.GetSlaves(x => (x.SlaveState == DA.SlaveState.Calculating || x.SlaveState == DA.SlaveState.Idle) && resourceIds.Contains(x.ResourceId));
31
32    int currentlyAvailableCores = onlineSlaves.Sum(s => s.Cores.Value);
33    int currentlyUsedCores = currentlyAvailableCores - onlineSlaves.Sum(s => s.FreeCores.Value);
34    int currentlyJobsWaiting = ServiceLocator.Instance.HiveDao.GetJobs(x => x.State == DA.TaskState.Waiting).Count();
35
36    this.availableCoresLabel.Text = currentlyAvailableCores.ToString();
37    this.usedCoresLabel.Text = currentlyUsedCores.ToString();
38    this.waitingJobsLabel.Text = currentlyJobsWaiting.ToString();
39
40    slavesLabel.Text = string.Join(", ", onlineSlaves.Select(x => string.Format("<a href=\"?resource={0}\">{0}</a> ({1} %)", x.Name, Math.Round(x.CpuUtilization, 2))));
41
42    cpuUtilizationLabel.Text = (onlineSlaves.Count() > 0 ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
43
44    HeuristicLab.Services.Hive.DataTransfer.Statistics[] stats;
45    if (daysDropDownList.SelectedValue == "All")
46      stats = dao.GetStatistics(x => true).OrderBy(x => x.TimeStamp).ToArray();
47    else
48      stats = dao.GetStatistics(x => x.Timestamp >= DateTime.Now.Subtract(TimeSpan.FromDays(int.Parse(daysDropDownList.SelectedValue)))).OrderBy(x => x.TimeStamp).ToArray();
49
50    var firstStatisticsDate = DateTime.Parse("2011-05-24 17:16:40");
51    var statisticsSince = DateTime.Now - firstStatisticsDate;
52    if (stats.Length != 0) {
53      totalExecutionTimeLabel.Text = new TimeSpan(stats.Last().UserStatistics.Sum(x => x.ExecutionTime.Ticks)).ToString() + " (since " + Math.Round(statisticsSince.TotalDays, 2) + " days)";
54    } else {
55      totalExecutionTimeLabel.Text = "00:00:00.00";
56    }
57   
58    for (int i = 0; i < stats.Length; i++) {
59      var s = stats[i];
60      var slaveStats = s.SlaveStatistics.Where(x => resourceIds.Contains(x.SlaveId));
61
62      var averageCpuUtilization = slaveStats.Count() > 0 ? slaveStats.Average(x => x.CpuUtilization) : 0.0;
63      cpuUtilizationChart.Series[0].Points.Add(new DataPoint(s.TimeStamp.ToOADate(), averageCpuUtilization));
64
65      var cores = slaveStats.Sum(x => x.Cores);
66
67      var usedCores = cores - slaveStats.Sum(x => x.FreeCores);
68      coresChart.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), cores);
69      coresChart.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), usedCores);
70
71      var memory = slaveStats.Sum(x => x.Memory);
72      var usedMemory = memory - slaveStats.Sum(x => x.FreeMemory);
73      memoryChart.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), memory / 1024.0);
74      memoryChart.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), usedMemory / 1024.0);
75
76      if (i > 0) {
77        var execTime = new TimeSpan(s.UserStatistics.Sum(x => x.ExecutionTime.Ticks));
78        var execTimePrev = new TimeSpan(stats[i - 1].UserStatistics.Sum(x => x.ExecutionTime.Ticks));
79        var execTimeDifference = execTimePrev - execTime;
80
81        var timeDifference = stats[i - 1].TimeStamp - s.TimeStamp; // the difference between statistic entries is not alway exactly 1 minute
82        var speedup = execTimeDifference.TotalMinutes / timeDifference.TotalMinutes;
83        speedupChartMinutes.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), speedup);
84        speedupChartMinutes.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), cores);
85      }
86      if (i - 60 >= 0) {
87        var execTime = new TimeSpan(s.UserStatistics.Sum(x => x.ExecutionTime.Ticks));
88        var execTimePrev = new TimeSpan(stats[i - 60].UserStatistics.Sum(x => x.ExecutionTime.Ticks));
89        var execTimeDifference = execTimePrev - execTime;
90
91        var timeDifference = stats[i - 60].TimeStamp - s.TimeStamp; // the difference between statistic entries is not alway exactly 1 minute
92        var speedup = execTimeDifference.TotalMinutes / timeDifference.TotalMinutes;
93        speedupChartHours.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), speedup);
94        speedupChartHours.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), cores);
95      }
96    }
97  }
98
99  protected void daysDropDownList_SelectedIndexChanged(object sender, EventArgs e) {
100
101  }
102}
Note: See TracBrowser for help on using the repository browser.