Created
April 19, 2016 07:25
-
-
Save margusmartsepp/b40cdd866e3f2cfc927ae6566bf94283 to your computer and use it in GitHub Desktop.
LINQPad load test statistics aggregation example
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
(localdb)\MSSQLLocalDb.LoadTest2010 |
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
void Main() | |
{ | |
foreach(var run in LoadTestRuns | |
.Where(o=> o.LoadTestName == "baseline" && o.RunDuration == 7200) | |
.Select(o=> new {o.LoadTestRunId, o.StartTime, o.EndTime}) | |
){ | |
run.Dump(); | |
var testruns = run.LoadTestRunId; | |
var failedTests = LoadTestMessageView2 | |
.Where(o=>o.LoadTestRunId==testruns && o.TestCaseName!=null) | |
.Select(o=>new { | |
o.TestCaseName, | |
o.MessageTimeStamp, | |
o.MessageText, | |
o.StackTrace, | |
o.TestLogId | |
}) | |
.ToList() | |
.Select(o=>new { | |
o.MessageTimeStamp, | |
o.TestCaseName, | |
IdCode = ExtractIdCode(GetLog(o.TestLogId,testruns)), | |
o.MessageText, | |
o.StackTrace, | |
o.TestLogId | |
}) | |
.OrderBy(o=>o.TestCaseName) | |
.ThenBy(o=>o.MessageText) | |
.ThenBy(o=>o.IdCode); | |
var testdata = failedTests | |
.Select(o=>new { | |
o.TestCaseName, | |
o.MessageText, | |
o.IdCode | |
}) | |
.GroupBy(x => new {x.TestCaseName, x.MessageText}) | |
.Select(y => | |
new { | |
TestCaseName = y.Key.TestCaseName, | |
ErrorMessage = y.Key.MessageText, | |
Count = y.ToList().Count, | |
IdCodes = y.ToList().Where(o=>o.IdCode!="").Select(o=>o.IdCode).OrderBy(o=>o) | |
} | |
).Dump(); | |
} | |
} | |
public string GetLog(int? log, int runid){ | |
if(log == null) | |
return ""; | |
return Encoding.UTF8.GetString( | |
LoadTestTestLogs | |
.FirstOrDefault(k=>k.LoadTestRunId==runid && k.TestLogId==log) | |
.TestLog | |
.ToArray()); | |
} | |
public string ExtractIdCode(string log){ | |
var startTag ="user['"; | |
var start = log.IndexOf("user['"); | |
if(start < 0) | |
return ""; | |
return log.Substring(start+startTag.Length, 11); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment