Skip to content

Commit

Permalink
androidagent: use HTTP api to submit results
Browse files Browse the repository at this point in the history
  • Loading branch information
lewurm committed Feb 22, 2016
1 parent eddbed8 commit c7a19fa
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 13 deletions.
3 changes: 3 additions & 0 deletions http-api/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func githubRepoForProduct(name string) (string, string) {
if name == "benchmarker" {
return "xamarin", "benchmarker"
}
if name == "monodroid" {
return "xamarin", "monodroid"
}
return "", ""
}

Expand Down
1 change: 1 addition & 0 deletions performancebot/utils/submit2xtc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ submitjob () {
XTCJOBID=$(grep -E -o '[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}' "$XTCUPLOADLOG")
rm -f "$XTCUPLOADLOG"
echo "submitted job has id $XTCJOBID"
echo "TODO: add xtc job id as log url to existing runset"
}

nuget restore tools.sln
Expand Down
4 changes: 4 additions & 0 deletions tools/AndroidAgent.UITests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,15 @@ public void RunBenchmarkHelper (string benchmark)
using (StreamReader reader = new StreamReader (stream)) {
dynamic json = JsonConvert.DeserializeObject (reader.ReadToEnd ());
string githubAPIKey = json.githubAPIKey;
string httpAPITokens = json.httpAPITokens;
string runSetId = json.runSetId;

app.Screenshot ("init");

clearAndSetTextField ("benchmark", benchmark);
clearAndSetTextField ("githubAPIKey", githubAPIKey);
clearAndSetTextField ("httpAPITokens", httpAPITokens);
clearAndSetTextField ("runSetId", runSetId);

app.Tap (c => c.Marked ("myButton"));
app.Screenshot ("after tap");
Expand Down
1 change: 1 addition & 0 deletions tools/AndroidAgent/AndroidAgent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
</ItemGroup>
<Import Project="..\libgithub\libgithub.projitems" Label="Shared" Condition="Exists('..\libgithub\libgithub.projitems')" />
<Import Project="..\liblogging\logging.projitems" Label="Shared" Condition="Exists('..\liblogging\logging.projitems')" />
<Import Project="..\libdbmodel\common.projitems" Label="Shared" Condition="Exists('..\libdbmodel\common.projitems')" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<ItemGroup>
Expand Down
59 changes: 49 additions & 10 deletions tools/AndroidAgent/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Android.OS;

using Benchmarker;
using models = Benchmarker.Models;
using System.Reflection;
using System.Diagnostics;

Expand Down Expand Up @@ -70,7 +71,7 @@ void SetStartButtonText (string text)
button.Text = text;
}

void Iteration (string benchmark, int iteration, bool isDryRun)
private models.Run Iteration (string benchmark, int iteration, bool isDryRun)
{
var dryRun = isDryRun ? " dryrun" : "";
Logging.GetLogging ().InfoFormat ("Benchmarker | Benchmark{0} \"{1}\": start iteration {2}", dryRun, benchmark, iteration);
Expand Down Expand Up @@ -159,9 +160,17 @@ void Iteration (string benchmark, int iteration, bool isDryRun)
}
sw.Stop ();
Logging.GetLogging ().InfoFormat ("Benchmarker | Benchmark{0} \"{1}\": finished iteration {2}, took {3}ms", dryRun, benchmark, iteration, sw.ElapsedMilliseconds);
var run = new models.Run { Benchmark = new models.Benchmark { Name = benchmark } };
run.RunMetrics.Add (
new models.RunMetric {
Metric = models.RunMetric.MetricType.Time,
Value = TimeSpan.FromMilliseconds (sw.ElapsedMilliseconds)
}
);
return run;
}

private static void PrintCommit ()
private static models.Commit DetermineCommit ()
{
// e.g.: "4.3.0 (master/[a-f0-9A-F]{7..40})"
var regex = new Regex ("^[0-9].*\\((.*)/([0-9a-f]+)\\)");
Expand Down Expand Up @@ -195,24 +204,51 @@ private static void PrintCommit ()
}

Logging.GetLogging ().InfoFormat ("Benchmarker | commit \"{0}\" on branch \"{1}\"", hash, branch);
return new models.Commit {
Hash = hash,
Branch = branch,
Product = new models.Product {
Name = "mono",
GitHubUser = "mono",
GitHubRepo = "mono"
}
};
}


AndroidCPUManagment CpuManager;

void RunBenchmark (string benchmarkName, string hostname, string architecture)
void RunBenchmark (long runSetId, string benchmarkName, string hostname, string architecture)
{
const int DRY_RUNS = 3;
const int ITERATIONS = 10;

PrintCommit ();

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

models.Commit mainCommit = DetermineCommit ();
models.Machine machine = new models.Machine { Name = hostname, 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++) {
Iteration (benchmarkName, i, i < DRY_RUNS);
var run = Iteration (benchmarkName, i, i < DRY_RUNS);
if (i >= DRY_RUNS) {
runSet.Runs.Add (run);
}
}
AsyncContext.Run (() => runSet.Upload ());
RunOnUiThread (() => SetStartButtonText ("start"));
} catch (Exception e) {
RunOnUiThread (() => SetStartButtonText ("failed"));
Expand All @@ -225,9 +261,10 @@ void RunBenchmark (string benchmarkName, string hostname, string architecture)
}).Start ();
}

private static void InitCommons (string githubAPIKey)
private static void InitCommons (string githubAPIKey, string httpAPITokens)
{
GitHubInterface.githubCredentials = githubAPIKey;
models.HttpApi.AuthToken = httpAPITokens;
}

protected override void OnCreate (Bundle savedInstanceState)
Expand All @@ -238,11 +275,13 @@ protected override void OnCreate (Bundle savedInstanceState)
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
FindViewById<Button> (Resource.Id.myButton).Click += delegate {
var benchmarkName = FindViewById<TextView> (Resource.Id.benchmark).Text;
var githubAPIKey = FindViewById<TextView> (Resource.Id.githubAPIKey).Text;
InitCommons (githubAPIKey);
string benchmarkName = FindViewById<TextView> (Resource.Id.benchmark).Text;
string githubAPIKey = FindViewById<TextView> (Resource.Id.githubAPIKey).Text;
string httpAPITokens = FindViewById<TextView> (Resource.Id.httpAPITokens).Text;
long runSetId = Int64.Parse (FindViewById<TextView> (Resource.Id.runSetId).Text);
InitCommons (githubAPIKey, httpAPITokens);
SetStartButtonText ("running");
RunBenchmark (benchmarkName, hostname, architecture);
RunBenchmark (runSetId, benchmarkName, hostname, architecture);
};
string v = ".NET version:\n" + System.Environment.Version.ToString ();
v += "\n\nMonoVersion:\n" + GetMonoVersion ();
Expand Down
10 changes: 8 additions & 2 deletions tools/AndroidAgent/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tools/AndroidAgent/Resources/layout/Main.axml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
android:layout_height="wrap_content"
android:id="@+id/githubAPIKey"
android:text="github API Key" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/httpAPITokens"
android:hint="httpAPITokens" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/runSetId"
android:hint="RunSetID" />
<Button
android:id="@+id/myButton"
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion tools/libdbmodel/RunSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static async Task<RunSet> FromId (Machine machine, long id, Config config
// The `StartsWith` case here is a weird exception we need for TestCloud devices,
// which have a common prefix, and we treat them as the same machine.
if ((machine.Name != machineName && !machineName.StartsWith (machine.Name)) || machine.Architecture != result ["Machine"] ["Architecture"].ToObject<string> ())
throw new Exception ("Machine does not match the one in the database.");
throw new Exception ("Machine does not match the one in the database. \"" + machineName + "\" vs. \"" + machine.Name + "\"");

if (!config.EqualsApiObject (result ["Config"]))
throw new Exception ("Config does not match the one in the database.");
Expand Down

0 comments on commit c7a19fa

Please sign in to comment.