Esempio n. 1
0
        internal async Task <int> UploadAsync(List <PerfSummary> summaries)
        {
            if (this.CosmosDatabase is null)
            {
                await this.Connect();
            }

            if (this.CosmosDatabase is null)
            {
                return(0);
            }

            if (this.SummaryContainer is null)
            {
                var response = await this.CosmosDatabase.CreateContainerIfNotExistsAsync(SummaryTableName, "/PartitionKey");

                this.SummaryContainer = response.Container;
            }

            int count = 0;

            foreach (var s in summaries)
            {
                bool better = true;
                try
                {
                    var response = await this.SummaryContainer.ReadItemAsync <PerfSummary>(s.Id, new PartitionKey(s.PartitionKey));

                    PerfSummary old = response.Resource;
                    if (old.TimeMean < s.TimeMean)
                    {
                        better = false;
                    }
                }
                catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
                {
                }

                if (better)
                {
                    Console.WriteLine("===> Uploading summary for {0}...", s.TestName);
                    await this.SummaryContainer.UpsertItemAsync(s, new PartitionKey(s.PartitionKey));

                    count++;
                }
                else
                {
                    Console.WriteLine("===> Existing record is better for {0}...", s.TestName);
                }
            }

            return(count);
        }
Esempio n. 2
0
        private async Task DowwnloadResults()
        {
            foreach (var file in Directory.GetFiles(this.OutputDir))
            {
                File.Delete(file);
            }

            Storage storage = new Storage();

            foreach (var b in Benchmarks)
            {
                var           metadata = new TestMetadata(b.Test);
                object        target   = metadata.InstantiateTest();
                List <string> rowKeys  = new List <string>();
                foreach (var comboList in metadata.EnumerateParamCombinations(0, new Stack <ParamInfo>()))
                {
                    foreach (var test in metadata.TestMethods)
                    {
                        string name = test.ApplyParams(target, comboList);
                        rowKeys.Add(this.CommitId + "." + b.Test.Name + "." + name);
                    }
                }

                Console.WriteLine("Downloading results for test {0}...", b.Name);

                string summaryFile  = Path.Combine(this.OutputDir, "summary.csv");
                bool   writeHeaders = !File.Exists(summaryFile);
                using (var file = new StreamWriter(summaryFile, true, Encoding.UTF8))
                {
                    if (writeHeaders)
                    {
                        PerfSummary.WriteHeaders(file);
                    }

                    foreach (var summary in await storage.DownloadAsync(this.DownloadPartition, rowKeys))
                    {
                        if (summary is null)
                        {
                            Console.WriteLine("Summary missing for {0}", b.Name);
                        }
                        else
                        {
                            summary.CommitId = this.CommitId;
                            summary.SetPartitionKey(this.DownloadPartition);
                            summary.WriteCsv(file);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void SaveSummary(List <PerfSummary> report)
        {
            string filename     = Path.Combine(this.OutputDir, "summary.csv");
            bool   writeHeaders = !File.Exists(filename);

            using (StreamWriter writer = new StreamWriter(filename, true, Encoding.UTF8))
            {
                if (writeHeaders)
                {
                    PerfSummary.WriteHeaders(writer);
                }

                foreach (var item in report)
                {
                    item.WriteCsv(writer);
                }
            }
        }