Files
linqpad/CCI Timings.linq
T

220 lines
7.8 KiB
C#

<Query Kind="Program">
<Connection>
<ID>4f885e7e-d8bb-427c-a54e-8e3e1c3137a7</ID>
<Persist>true</Persist>
<Server>IOAK-SQL-LOG-01.sdt.local</Server>
<Database>jazz log prod</Database>
<ShowServer>true</ShowServer>
</Connection>
<Reference>&lt;ProgramFilesX64&gt;\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics\Newtonsoft.Json.dll</Reference>
<NuGetReference>Amazon.Lambda.S3Events</NuGetReference>
<NuGetReference>AWSSDK.Core</NuGetReference>
<NuGetReference>AWSSDK.S3</NuGetReference>
<Namespace>Amazon</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy</Namespace>
<Namespace>Amazon.Auth.AccessControlPolicy.ActionIdentifiers</Namespace>
<Namespace>Amazon.Internal</Namespace>
<Namespace>Amazon.Lambda.S3Events</Namespace>
<Namespace>Amazon.MissingTypes</Namespace>
<Namespace>Amazon.Runtime</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement</Namespace>
<Namespace>Amazon.Runtime.CredentialManagement.Internal</Namespace>
<Namespace>Amazon.Runtime.EventStreams</Namespace>
<Namespace>Amazon.Runtime.EventStreams.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal</Namespace>
<Namespace>Amazon.Runtime.Internal.Auth</Namespace>
<Namespace>Amazon.Runtime.Internal.Settings</Namespace>
<Namespace>Amazon.Runtime.Internal.Transform</Namespace>
<Namespace>Amazon.Runtime.Internal.Util</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces</Namespace>
<Namespace>Amazon.Runtime.SharedInterfaces.Internal</Namespace>
<Namespace>Amazon.S3</Namespace>
<Namespace>Amazon.S3.Encryption</Namespace>
<Namespace>Amazon.S3.Encryption.Internal</Namespace>
<Namespace>Amazon.S3.Internal</Namespace>
<Namespace>Amazon.S3.IO</Namespace>
<Namespace>Amazon.S3.Model</Namespace>
<Namespace>Amazon.S3.Model.Internal.MarshallTransformations</Namespace>
<Namespace>Amazon.S3.Transfer</Namespace>
<Namespace>Amazon.S3.Util</Namespace>
<Namespace>Amazon.Util</Namespace>
<Namespace>Amazon.Util.Internal</Namespace>
<Namespace>Amazon.Util.Internal.PlatformServices</Namespace>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Converters</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>Newtonsoft.Json.Schema</Namespace>
<Namespace>Newtonsoft.Json.Serialization</Namespace>
<Namespace>System</Namespace>
<Namespace>System.Diagnostics</Namespace>
<Namespace>System.Diagnostics.Tracing</Namespace>
<Namespace>System.IO.Compression</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1</Namespace>
<Namespace>ThirdParty.BouncyCastle.Asn1.Utilities</Namespace>
<Namespace>ThirdParty.BouncyCastle.Math</Namespace>
<Namespace>ThirdParty.BouncyCastle.OpenSsl</Namespace>
<Namespace>ThirdParty.BouncyCastle.Utilities.IO.Pem</Namespace>
<Namespace>ThirdParty.Ionic.Zlib</Namespace>
<Namespace>ThirdParty.Json.LitJson</Namespace>
<Namespace>ThirdParty.MD5</Namespace>
</Query>
public static string PrimaryUrl => "Opportunities.aspx";
public static string UrlGroup => "/CCI";
public static DateTime cutoff { get; set; } = DateTime.Now.AddDays((((int)DateTime.Now.DayOfWeek) * -1) + 1).Date;
void Main()
{
RunTimings();
}
public void RunTimings()
{
cutoff = DateTime.Now.AddDays(-30);
var timings = GetTimings(cutoff)
.Where(t => t.Key.Group == 0 && t.Data.Any());
var outliers = timings.SelectMany(t => t.Data.Where(d => d.ClientTimeData / 1000.0d > 4.0d));
outliers.Dump(nameof(outliers));
timings
.OrderByDescending(t => t.Key.ClientTimeMax > 4 ? t.Key.ClientTimeMax : 0)
.ThenBy(t => t.Key.Group)
.ThenBy(t => t.Key.Url.Contains(PrimaryUrl) ? "!" : t.Key.Url)
.ThenBy(t => t.Key.Application)
.ThenByDescending(t => t.Key.Date)
.ThenBy(t => t.Key.Browser.StartsWith("IE") ? 0 : 1)
.Dump();
}
public IEnumerable<MetricData> GetTimings(DateTime cutoff)
{
return from log in Archive_PageLogs
where (log.Url.StartsWith(UrlGroup))
&& log.DateTimeStamp > cutoff
group log by new { Group = (log.UserName.StartsWith("sdt\\") ? 1 : 0), log.Url, log.Browser, Date = log.DateTimeStamp.Value.Date, log.Application } into grp
//join dbs in ViewActiveDatabases on grp.FirstOrDefault().DatabaseGuid equals dbs.DatabaseGUID
orderby grp.Key.Group, (grp.FirstOrDefault().ClientTime / 1000) descending, grp.Key.Date descending
select new MetricData
{
Key = new MetricKey
{
Application = grp.Key.Application,
Group = grp.Key.Group,
Url = grp.Key.Url,
Browser = grp.Key.Browser,
Date = grp.Key.Date,
ClientTimeAvg = grp.ToList().Average(g => (g.ClientTime / 1000.0d)) ?? 0.0d,
ClientTimeMin = grp.ToList().Min(g1 => (g1.ClientTime / 1000.0d)) ?? 0.0d,
ClientTimeMax = grp.ToList().Max(g1 => (g1.ClientTime / 1000.0d)) ?? 0.0d,
Count = grp.ToList().Count
},
Data = grp
.Select(g => new Metric(g.DatabaseGuid.Value, ViewActiveDatabases)
{
UrlParams = g.UrlParams,
UserName = g.UserName,
WebServer = g.WebServer,
ServerTimeData = g.ServerTime ?? 0,
ClientTimeData = g.ClientTime ?? 0,
DatabaseName = g.DatabaseName,
ClientTime = g.ClientTime ?? 0 / 1000.0d,
ClientTimeAvg = grp.ToList().Average(g1 => g1.ClientTime ?? 0.0d / 1000.0d),
ClientTimeMin = grp.ToList().Min(g1 => g1.ClientTime ?? 0.0d / 1000.0d),
ClientTimeMax = grp.ToList().Max(g1 => g1.ClientTime ?? 0.0d / 1000.0d)
}).Where(x => (x.ClientTimeData / 1000.0d) > x.ClientTimeAvg || ((x.ClientTimeData / 1000.0d) > 4.0d))
};
}
// Define other methods and classes here
public class Metric
{
public double ClientTime { get; set; }
public double ClientTimeData { get; set; }
public double ClientTimeAvg { get; set; }
public double ClientTimeMin { get; set; }
public double ClientTimeMax { get; set; }
public string WebServer { get; set; }
public string PhysicalName { get; set; }
public Guid DatabaseGuid { get; set; }
public string DatabaseName { get; set; }
public string UserName { get; set; }
public string UrlParams { get; set; }
public int ServerTimeData { get; set; }
public string OrgPin { get; set; }
public Metric()
{
}
public Metric(Guid databaseGuid, Table<ViewActiveDatabases> activeDatabases)
{
DatabaseGuid = databaseGuid;
var activeDatabase = activeDatabases.SingleOrDefault(vad => vad.DatabaseGUID == databaseGuid);
PhysicalName = activeDatabase?.PhysicalName ?? string.Empty;
OrgPin = activeDatabase?.OrgPin ?? string.Empty;
}
object ToDump() => new
{
ClientTimeMax = new XElement("LINQPad.HTML",
new XElement("div",
new XAttribute("align", "right"),
new XAttribute("style", $"background-color:{(ClientTimeMax > 4.0d ? "red" : (ClientTimeAvg < (ClientTimeData / 1000.0d)) ? "violet" : "white")};"),
$"{ClientTimeMax:n}".PadLeft(10))),
ClientTimeAvg,
ClientTimeMin,
WebServer,
OrgPin,
DatabaseName,
PhysicalName,
UserName,
UrlParams,
ServerTime = $"{ServerTimeData:n0}".PadLeft(10)
};
}
public class MetricKey
{
public string Application { get; set; }
public int Group { get; set; }
public string Browser { get; set; }
public string Url { get; set; }
//public int UrlLength { get; set; }
public DateTime Date { get; set; }
public double ClientTimeAvg { get; set; }
public double ClientTimeMin { get; set; }
public double ClientTimeMax { get; set; }
public int Count { get; set; }
object ToDump() => new
{
Application,
GroupName = Group == 0 ? "Clients" : "Strata",
Browser,
URL = Url, //.PadRight(UrlLength),
OnDate = Date.ToShortDateString(),
Avg_ClientTime = $"{ClientTimeAvg:N2}",
Min_ClientTime = $"{ClientTimeMin:N2}",
Max_ClientTime = $"{ClientTimeMax:N2}",
Count
};
}
public class MetricData
{
public MetricKey Key { get; set; }
public IEnumerable<Metric> Data { get; set; }
object ToDump() => new
{
Group = Key,
Statistics = Data
.OrderBy(d => d.WebServer)
.ThenBy(d => d.DatabaseName)
.ThenBy(d => d.UserName)
.ThenBy(d => d.ClientTimeData)
};
}