Index: tools/kilobench/kilobench.cpp |
diff --git a/tools/kilobench/kilobench.cpp b/tools/kilobench/kilobench.cpp |
index 438e582324fb2e8c97f1da061e7d9a3f8760d870..d3553f2ac604165000966c8d1f8fa2a9addb3162 100644 |
--- a/tools/kilobench/kilobench.cpp |
+++ b/tools/kilobench/kilobench.cpp |
@@ -8,6 +8,7 @@ |
#include "GrCaps.h" |
#include "GrContextFactory.h" |
#include "Benchmark.h" |
+#include "ResultsWriter.h" |
#include "SkCommandLineFlags.h" |
#include "SkOSFile.h" |
#include "SkStream.h" |
@@ -18,6 +19,11 @@ |
#include "VisualSKPBench.h" |
#include "gl/GrGLDefines.h" |
+// posix only for now |
+#include <unistd.h> |
+#include <sys/types.h> |
+#include <sys/wait.h> |
+ |
/* |
* This is an experimental GPU only benchmarking program. The initial implementation will only |
* support SKPs. |
@@ -327,7 +333,12 @@ static SkString humanize(double ms) { |
} |
#define HUMANIZE(ms) humanize(ms).c_str() |
-void benchmark_inner_loop(Benchmark* bench, GrContextFactory* ctxFactory) { |
+void benchmark_inner_loop(Benchmark* bench) { |
+ SkAutoTDelete<GrContextFactory> ctxFactory; |
+ |
+ GrContextOptions grContextOpts; |
+ ctxFactory.reset(new GrContextFactory(grContextOpts)); |
+ |
SkTArray<double> samples; |
GPUTarget target; |
SkAssertResult(target.init(bench, ctxFactory, false, |
@@ -374,11 +385,6 @@ void benchmark_inner_loop(Benchmark* bench, GrContextFactory* ctxFactory) { |
} // namespace kilobench |
int kilobench_main() { |
- SkAutoTDelete<GrContextFactory> ctxFactory; |
- |
- GrContextOptions grContextOpts; |
- ctxFactory.reset(new GrContextFactory(grContextOpts)); |
- |
kilobench::BenchmarkStream benchStream; |
SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n", |
@@ -386,12 +392,17 @@ int kilobench_main() { |
while (Benchmark* b = benchStream.next()) { |
SkAutoTDelete<Benchmark> bench(b); |
- kilobench::benchmark_inner_loop(bench.get(), ctxFactory.get()); |
- } |
- // Make sure we clean up the global GrContextFactory here, otherwise we might race with the |
- // SkEventTracer destructor |
- ctxFactory.reset(nullptr); |
+ // We fork off a new process to setup the grcontext and run the test while we wait |
+ int childPid = fork(); |
+ if (childPid) { |
+ int status; |
+ waitpid(childPid, &status, 0); |
+ } else { |
+ kilobench::benchmark_inner_loop(bench.get()); |
+ return 0; |
+ } |
+ } |
return 0; |
} |