<commit_before>﻿#region Copyright (c) Lokad 2009
// This code is released under the terms of the new BSD licence.
// URL: http://www.lokad.com/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Caching;
using System.Web.UI.WebControls;
using Lokad.Cloud.Diagnostics;
using Lokad.Cloud.Management;

namespace Lokad.Cloud.Web
{
	public partial class Monitoring : System.Web.UI.Page
	{
		readonly TimeSpan _cacheRefreshPeriod = 2.Minutes();
		readonly CloudStatistics _cloudStatistics = GlobalSetup.Container.Resolve<CloudStatistics>();

		protected void Page_Load(object sender, EventArgs e)
		{
			PartitionView.DataBind();
			ServiceView.DataBind();
			ProfilesView.DataBind();
			ExceptionsView.DataBind();
		}

		object ToPresentationModel(IEnumerable<PartitionStatistics> partitionStatistics)
		{
			return partitionStatistics
				.Select<PartitionStatistics, object>(s => new
					{
						Partition = s.PartitionKey,
						//OS = PrettyFormatOperatingSystem(s.OperatingSystem),
						Runtime = s.Runtime,
						Cores = s.ProcessorCount,
						Threads = s.ThreadCount,
						CPU = s.TotalProcessorTime.PrettyFormat(),
						//Kernel = (s.TotalProcessorTime - s.UserProcessorTime).PrettyFormat(),
						Active = PrettyFormatActiveTime(s.ActiveTime, s.StartCount),
						Usage = PrettyFormatUsage(s.TotalProcessorTime, s.ActiveTime),
						Memory = PrettyFormatMemoryMB(s.MemoryPrivateSize),
					})
				.Take(50)
				.ToList();
		}

		object ToPresentationModel(IEnumerable<ServiceStatistics> serviceStatistics)
		{
			return serviceStatistics
				.Select<ServiceStatistics, object>(s => new
					{
						Service = s.Name,
						Count = s.Count,
						CPU = s.TotalProcessorTime.PrettyFormat(),
						//Kernel = (s.TotalProcessorTime - s.UserProcessorTime).PrettyFormat()
						Total = s.AbsoluteTime.PrettyFormat(),
						Average = s.Count == 0 ? "N/A" : TimeSpan.FromTicks(s.AbsoluteTime.Ticks / s.Count).PrettyFormat(),
						Max = s.MaxAbsoluteTime.PrettyFormat(),
					})
				.Take(50)
				.ToList();
		}

		object ToPresentationModel(IEnumerable<ExecutionProfilingStatistics> profilingStatisticses)
		{
			return profilingStatisticses
				.SelectMany(s => s.Statistics<commit_msg>Cloud: minor: rendering cpu usage instead of average time for cloud service statistics (average was misleading)<commit_after>﻿#region Copyright (c) Lokad 2009
// This code is released under the terms of the new BSD licence.
// URL: http://www.lokad.com/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Caching;
using System.Web.UI.WebControls;
using Lokad.Cloud.Diagnostics;
using Lokad.Cloud.Management;

namespace Lokad.Cloud.Web
{
	public partial class Monitoring : System.Web.UI.Page
	{
		readonly TimeSpan _cacheRefreshPeriod = 2.Minutes();
		readonly CloudStatistics _cloudStatistics = GlobalSetup.Container.Resolve<CloudStatistics>();

		protected void Page_Load(object sender, EventArgs e)
		{
			PartitionView.DataBind();
			ServiceView.DataBind();
			ProfilesView.DataBind();
			ExceptionsView.DataBind();
		}

		object ToPresentationModel(IEnumerable<PartitionStatistics> partitionStatistics)
		{
			return partitionStatistics
				.Select<PartitionStatistics, object>(s => new
					{
						Partition = s.PartitionKey,
						//OS = PrettyFormatOperatingSystem(s.OperatingSystem),
						Runtime = s.Runtime,
						Cores = s.ProcessorCount,
						Threads = s.ThreadCount,
						CPU = s.TotalProcessorTime.PrettyFormat(),
						//Kernel = (s.TotalProcessorTime - s.UserProcessorTime).PrettyFormat(),
						Active = PrettyFormatActiveTime(s.ActiveTime, s.StartCount),
						Usage = PrettyFormatUsage(s.TotalProcessorTime, s.ActiveTime),
						Memory = PrettyFormatMemoryMB(s.MemoryPrivateSize),
					})
				.Take(50)
				.ToList();
		}

		object ToPresentationModel(IEnumerable<ServiceStatistics> serviceStatistics)
		{
			return serviceStatistics
				.Select<ServiceStatistics, object>(s => new
					{
						Service = s.Name,
						Count = s.Count,
						CPU = s.TotalProcessorTime.PrettyFormat(),
						//Kernel = (s.TotalProcessorTime - s.UserProcessorTime).PrettyFormat()
						Total = s.AbsoluteTime.PrettyFormat(),
						//Average = s.Count == 0 ? "N/A" : TimeSpan.FromTicks(s.AbsoluteTime.Ticks / s.Count).PrettyFormat(),
						Max = s.MaxAbsoluteTime.PrettyFormat(),
						Usage = PrettyFormatUsage(s.TotalProcessorTime, s.AbsoluteTime),
					})
				.Take(50)
				.ToList();
		}

		object ToPresentationModel(IEnumerable<ExecutionProfilingStatistics> profilingStatisticses)
		{
			return profilingStatisticses
				.SelectMany(s => s.Statistics
{'fraction_non_alphanumeric': 0.10972192282819573, 'fraction_numerical': 0.004311273981461522, 'mean_word_length': 3.8842105263157896, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1855', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1322, 'n_words': 273}