Esempio n. 1
0
		public static async Task<RunSet> FromId (Machine local_machine, long local_runsetid, Config local_config, Commit local_mainCommit, List<Commit> local_secondaryCommits, string local_buildURL, string local_logURL)
		{
			using (var client = new HttpClient ()) {
				JObject db_result = await HttpApi.GetRunset (local_runsetid);
				if (db_result == null) {
					return null;
				}

				var runSet = new RunSet {
					Id = local_runsetid,
					StartDateTime = db_result ["StartedAt"].ToObject<DateTime> (),
					FinishDateTime = db_result ["FinishedAt"].ToObject<DateTime> (),
					BuildURL = db_result ["BuildURL"].ToObject<string> (),
					Machine = local_machine,
					LogURL = local_logURL,
					Config = local_config,
					Commit = local_mainCommit,
					TimedOutBenchmarks = db_result ["TimedOutBenchmarks"].ToObject<List<string>> (),
					CrashedBenchmarks = db_result ["CrashedBenchmarks"].ToObject<List<string>> ()
				};

				var db_mainProductCommit = db_result ["MainProduct"] ["Commit"].ToObject<string> ();
				if (local_mainCommit.Hash != db_mainProductCommit)
					throw new Exception (String.Format ("Commit ({0}) does not match the one in the database ({1}).", local_mainCommit.Hash, db_mainProductCommit));

				var db_secondaryCommits = new List<Commit> ();
				foreach (var sc in db_result ["SecondaryProducts"]) {
					db_secondaryCommits.Add (new Commit {
						Hash = sc ["Commit"].ToObject<string> (),
						Product = new Product { Name = sc ["Name"].ToObject<string> () }
					});
				}
				if (local_secondaryCommits != null) {
					if (local_secondaryCommits.Count != db_secondaryCommits.Count)
						throw new Exception ("Secondary commits don't match the database.");
					foreach (var sc in db_secondaryCommits) {
						if (!local_secondaryCommits.Any (c => c.Hash == sc.Hash && c.Product.Name == sc.Product.Name))
							throw new Exception ("Secondary commits don't match the database.");
					}
					// local commits have more information (e.g. datetime)
					runSet.SecondaryCommits = local_secondaryCommits;
				} else {
					runSet.SecondaryCommits = db_secondaryCommits;
				}


				if (local_buildURL != null && local_buildURL != runSet.BuildURL)
					throw new Exception ("Build URL does not match the one in the database.");
				
				var db_machineName = db_result ["Machine"] ["Name"].ToObject<string> ();
				var db_machineArchitecture = db_result ["Machine"] ["Architecture"].ToObject<string> ();
				if (local_machine.Name != db_machineName || local_machine.Architecture != db_machineArchitecture)
					throw new Exception ("Machine does not match the one in the database. \"" + db_machineName + "\" vs. \"" + local_machine.Name + "\"");

				if (!local_config.EqualsApiObject (db_result ["Config"]))
					throw new Exception ("Config does not match the one in the database.");

				return runSet;
			}
		}
Esempio n. 2
0
        void RunBenchmark(long runSetId, string benchmarkName, string machineName, string architecture)
        {
            const int DRY_RUNS   = 3;
            const int ITERATIONS = 10;


            Logging.GetLogging().InfoFormat("Benchmarker | hostname \"{0}\" architecture \"{1}\"", machineName, architecture);
            Logging.GetLogging().InfoFormat("Benchmarker | configname \"{0}\"", "default");

            models.Commit  mainCommit = DetermineCommit();
            models.Machine machine    = new models.Machine {
                Name = machineName, Architecture = architecture
            };
            models.Config config = new models.Config {
                Name        = "default", Mono = String.Empty,
                MonoOptions = new string[0],
                MonoEnvironmentVariables = new Dictionary <string, string> (),
                Count = ITERATIONS
            };
            models.RunSet runSet = AsyncContext.Run(() => models.RunSet.FromId(machine, runSetId, config, mainCommit, null, null, null /* TODO: logURL? */));

            if (runSet == null)
            {
                Logging.GetLogging().Warn("RunSetID " + runSetId + " not found");
                return;
            }
            new Task(() => {
                try {
                    for (var i = 0; i < (ITERATIONS + DRY_RUNS); i++)
                    {
                        var run = Iteration(benchmarkName, i, i < DRY_RUNS);
                        if (i >= DRY_RUNS)
                        {
                            runSet.Runs.Add(run);
                        }
                    }
                    var result = AsyncContext.Run(() => runSet.Upload());
                    if (result == null)
                    {
                        RunOnUiThread(() => SetStartButtonText("failed"));
                    }
                    else
                    {
                        RunOnUiThread(() => SetStartButtonText("start"));
                    }
                } catch (Exception e) {
                    RunOnUiThread(() => SetStartButtonText("failed"));
                    Logging.GetLogging().Error(e);
                } finally {
                    if (AndroidCPUManagment.IsRooted())
                    {
                        CpuManager.RestoreCPUStates();
                    }
                }
            }).Start();
        }
Esempio n. 3
0
		internal static string GatherBenchViewData(string submissionType, string submissionName, string cuid, Commit commit)
        {
            Console.WriteLine("Gathering BenchView data...");

            // Always start fresh for a new set of results.
            if (Directory.Exists(s_outputDirectory))
                Directory.Delete(s_outputDirectory, true);
            Directory.CreateDirectory(s_outputDirectory);

            if (string.IsNullOrWhiteSpace(submissionName))
            {
                if (submissionType == "rolling")
					submissionName = $"{s_group} {submissionType} {commit.Branch} {commit.Hash}";
                else
                    throw new Exception($"submissionName was not provided, but submission type is {submissionType}");
            }

			var giturl = commit.Product.GitRepositoryUrl;
			string git_suffix = ".git";
			if (giturl.EndsWith (git_suffix ,StringComparison.Ordinal)) {
				giturl = giturl.Substring (0, giturl.Length - git_suffix.Length);
			}

			string metaargs = $"\"{s_submissionMetadataPy}\" --name=\"{submissionName}\" --user-email={s_userEmail} -o=\"{s_submissionMetadataJson}\"";
			if (cuid != null) {
				metaargs += " --cuid=" + cuid;
			}
			ShellOutVital(s_pythonProcessName, metaargs);
			if (cuid == null) {
				var jObject = JObject.Parse (File.ReadAllText (s_submissionMetadataJson));
				var jTokenCuid = jObject.GetValue ("cuid");
				cuid = (string) jTokenCuid.ToObject (typeof (string));
				Console.Error.WriteLine ("CUID: " + cuid);
			}
			var branch = commit.Branch;
			if (string.IsNullOrEmpty (branch)) {
				branch = "master";
			}
			ShellOutVital(s_pythonProcessName, $"\"{s_buildPy}\" --type={submissionType} --repository=\"{giturl}\" --number=\"{commit.Hash}\" --branch=\"{branch}\" --source-timestamp=\"{DateTime.SpecifyKind (commit.CommitDate.Value, DateTimeKind.Utc).ToString (RunSet.DATETIME_FORMAT)}\" -o=\"{s_buildJson}\"");
            ShellOutVital(s_pythonProcessName, $"\"{s_machinedataPy}\" -o=\"{s_machinedataJson}\"");
			return cuid;
        }
Esempio n. 4
0
		private static async Task<Octokit.Commit> ResolveFullHashViaGithub (Commit commit) {
			if (commit == null) {
				return null;
			}

			Octokit.Commit gitHubCommit = null;
			Octokit.TreeResponse treeResponse = null;
			try {
				var gitHubClient = GitHubInterface.GitHubClient;
				treeResponse = await GitHubInterface.RunWithRetry (() => gitHubClient.GitDatabase.Tree.Get (commit.Product.GitHubUser, commit.Product.GitHubRepo, commit.Hash));
				gitHubCommit = await GitHubInterface.RunWithRetry (() => gitHubClient.GitDatabase.Commit.Get (commit.Product.GitHubUser, commit.Product.GitHubRepo, treeResponse.Sha));
			} catch (Octokit.NotFoundException) {
				Console.WriteLine ("Commit " + commit + " not found on GitHub");
			}

			return gitHubCommit;
		}
Esempio n. 5
0
		public async static Task<bool> CompleteCommit (Config cfg, Commit commit)
		{
			if (commit.Product.Name == "mono" && !cfg.NoMono) {
				var binaryProtocolFile = cfg.ProducesBinaryProtocol ? "/tmp/binprot.dummy" : null;
				var info = NewProcessStartInfo (cfg, binaryProtocolFile);
				if (!String.IsNullOrWhiteSpace (info.FileName)) {
					/* Run without timing with --version */
					info.Arguments = "--version";

					Console.Out.WriteLine ("\t$> {0} {1} {2}", PrintableEnvironmentVariables (info), info.FileName, info.Arguments);

					var process = Process.Start (info);
					var version = Task.Run (() => new StreamReader (process.StandardOutput.BaseStream).ReadToEnd ()).Result;
					var versionError = Task.Run (() => new StreamReader (process.StandardError.BaseStream).ReadToEnd ()).Result;

					process.WaitForExit ();
					process.Close ();

					var line = version.Split (new char[] { '\n' }, 2) [0];
					var regex = new Regex ("^Mono JIT.*\\((.*)/([0-9a-f]+) (.*)\\)");
					var match = regex.Match (line);

					if (match.Success) {
						commit.Branch = match.Groups [1].Value;
						var hash = match.Groups [2].Value;
						if (commit.Hash != null) {
							if (!commit.Hash.StartsWith (hash)) {
								Console.Error.WriteLine ("Error: Commit hash for mono specified on command line does not match the one reported with --version.");
								return false;
							}
						} else {
							commit.Hash = hash;
						}
						var date = match.Groups [3].Value;
						Console.WriteLine ("branch: " + commit.Branch + " hash: " + commit.Hash + " date: " + date);
					}
				}

				if (commit.Branch == "(detached")
					commit.Branch = null;

				try {
					var gitRepoDir = Path.GetDirectoryName (cfg.Mono);
					var repo = new Repository (gitRepoDir);
					var gitHash = repo.RevParse (commit.Hash);
					if (gitHash == null) {
						Console.WriteLine ("Could not get commit " + commit.Hash + " from repository");
					} else {
						Console.WriteLine ("Got commit " + gitHash + " from repository");

						if (commit.Hash != null && commit.Hash != gitHash) {
							Console.Error.WriteLine ("Error: Commit hash specified on command line does not match the one from the git repository.");
							return false;
						}

						commit.Hash = gitHash;
						commit.MergeBaseHash = repo.MergeBase (commit.Hash, "master");
						commit.CommitDate = repo.CommitDate (commit.Hash);

						if (commit.CommitDate == null) {
							Console.Error.WriteLine ("Error: Could not get commit date from the git repository.");
							return false;
						}

						Console.WriteLine ("Commit {0} merge base {1} date {2}", commit.Hash, commit.MergeBaseHash, commit.CommitDate);
					}
				} catch (Exception) {
					Console.WriteLine ("Could not get git repository");
				}
			}

			if (commit.Hash == null) {
				Console.Error.WriteLine ("Error: cannot parse mono version and no commit given.");
				return false;
			}

			Octokit.Commit gitHubCommit = await ResolveFullHashViaGithub (commit);

			if (gitHubCommit == null) {
				Console.WriteLine ("Could not get commit " + commit.Hash + " from GitHub");
			} else {
				commit.Hash = gitHubCommit.Sha;
				if (commit.CommitDate == null)
					commit.CommitDate = gitHubCommit.Committer.Date.DateTime.ToLocalTime ();
				Console.WriteLine ("Got commit " + commit.Hash + " from GitHub");
			}

			if (commit.CommitDate == null) {
				Console.Error.WriteLine ("Error: Could not get a commit date.");
				return false;
			}

			return true;
		}