Commit 847dd159 authored by nfullagar's avatar nfullagar Committed by Commit bot

Benchmark sample for SDK

BUG=https://code.google.com/p/nativeclient/issues/detail?id=3987
TEST=NaCl SDK example and run on NaCl Perf Bots

R=bradnelson@chromium.org

Review URL: https://codereview.chromium.org/664543003

Cr-Commit-Position: refs/heads/master@{#302183}
parent b43e0d0b
...@@ -118,8 +118,9 @@ def main(args): ...@@ -118,8 +118,9 @@ def main(args):
filters['DISABLE_PACKAGE'] = False filters['DISABLE_PACKAGE'] = False
filters['EXPERIMENTAL'] = False filters['EXPERIMENTAL'] = False
filters['TOOLS'] = toolchains filters['TOOLS'] = toolchains
filters['DEST'] = ['examples/api', 'examples/getting_started', filters['DEST'] = ['examples/api', 'examples/benchmarks',
'examples/demo', 'examples/tutorial'] 'examples/getting_started', 'examples/demo',
'examples/tutorial']
tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters) tree = parse_dsc.LoadProjectTree(SDK_SRC_DIR, include=filters)
build_projects.UpdateHelpers(app_dir, clobber=True) build_projects.UpdateHelpers(app_dir, clobber=True)
build_projects.UpdateProjects(app_dir, tree, clobber=False, build_projects.UpdateProjects(app_dir, tree, clobber=False,
......
...@@ -177,7 +177,7 @@ def UpdateProjects(pepperdir, project_tree, toolchains, ...@@ -177,7 +177,7 @@ def UpdateProjects(pepperdir, project_tree, toolchains,
fh.write(out) fh.write(out)
# Generate top Make for examples # Generate top Make for examples
targets = ['api', 'demo', 'getting_started', 'tutorial'] targets = ['api', 'benchmarks', 'demo', 'getting_started', 'tutorial']
targets = [x for x in targets if 'examples/'+x in project_tree] targets = [x for x in targets if 'examples/'+x in project_tree]
branch_name = 'examples' branch_name = 'examples'
generate_make.GenerateMasterMakefile(pepperdir, generate_make.GenerateMasterMakefile(pepperdir,
......
...@@ -666,6 +666,7 @@ def BuildStepUpdateUserProjects(pepperdir, toolchains, ...@@ -666,6 +666,7 @@ def BuildStepUpdateUserProjects(pepperdir, toolchains,
filters['DEST'] = [ filters['DEST'] = [
'getting_started', 'getting_started',
'examples/api', 'examples/api',
'examples/benchmarks',
'examples/demo', 'examples/demo',
'examples/tutorial', 'examples/tutorial',
'src' 'src'
......
...@@ -11,7 +11,8 @@ def CmpByName(x, y): ...@@ -11,7 +11,8 @@ def CmpByName(x, y):
class LandingPage(object): class LandingPage(object):
def __init__(self): def __init__(self):
self.section_list = ['Getting Started', 'API', 'Demo', 'Tutorial'] self.section_list = ['Getting Started', 'API', 'Benchmarks', 'Demo',
'Tutorial']
self.section_map = collections.defaultdict(list) self.section_map = collections.defaultdict(list)
def GeneratePage(self, template_path): def GeneratePage(self, template_path):
......
...@@ -56,7 +56,7 @@ DSC_FORMAT = { ...@@ -56,7 +56,7 @@ DSC_FORMAT = {
'SEARCH': (list, '', False), 'SEARCH': (list, '', False),
'POST': (str, '', False), 'POST': (str, '', False),
'PRE': (str, '', False), 'PRE': (str, '', False),
'DEST': (str, ['getting_started', 'examples/api', 'DEST': (str, ['getting_started', 'examples/api', 'examples/benchmarks',
'examples/demo', 'examples/tutorial', 'examples/demo', 'examples/tutorial',
'src', 'tests'], True), 'src', 'tests'], True),
'NAME': (str, '', False), 'NAME': (str, '', False),
......
...@@ -20,6 +20,7 @@ examples/api/var_array_buffer/* ...@@ -20,6 +20,7 @@ examples/api/var_array_buffer/*
examples/api/var_dictionary/* examples/api/var_dictionary/*
examples/api/video_decode/* examples/api/video_decode/*
examples/api/websocket/* examples/api/websocket/*
examples/benchmarks/*
examples/button_close.png examples/button_close.png
examples/button_close_hover.png examples/button_close_hover.png
examples/demo/drive/* examples/demo/drive/*
......
{
'TOOLS': ['pnacl'],
'SEARCH': [
'.',
'../../resources',
'../../../../native_client/tests/benchmark',
'../../../../native_client/src',
],
'TARGETS': [
{
'NAME' : 'benchmarks',
'TYPE' : 'main',
'SOURCES' : [
'benchmark_binarytrees_c.c',
'benchmark_binarytrees.cc',
'benchmark_chameneos_c.c',
'benchmark_chameneos.cc',
'benchmark_life.cc',
'benchmark_nbody_c.c',
'benchmark_nbody.cc',
'framework.cc',
'framework.h',
'framework_ppapi.cc',
'thread_pool.h',
'thread_pool.cc'
],
'DEPS': ['ppapi_simple', 'nacl_io'],
'LIBS': ['ppapi_simple', 'nacl_io', 'sdk_util', 'ppapi_cpp', 'ppapi', 'pthread']
}
],
'DATA': [
'example.js',
'third_party/computer_language_benchmarks_game/binarytrees.c',
'third_party/computer_language_benchmarks_game/chameneos.c',
'third_party/computer_language_benchmarks_game/nbody.c',
],
'DEST': 'examples/benchmarks',
'NAME': 'benchmarks',
'TITLE': "Benchmark Suite",
'GROUP': 'Benchmarks'
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function moduleDidLoad() {
}
// Add event listeners after the NaCl module has loaded. These listeners will
// forward messages to the NaCl module via postMessage()
function attachListeners() {
setTimeout(function() { common.updateStatus('READY TO RUN'); }, 200);
document.getElementById('benchmark').addEventListener('click',
function() {
common.naclModule.postMessage({'message' : 'run_benchmark'});
common.updateStatus('BENCHMARKING... (please wait)');
var window = document.getElementById('result').contentWindow;
window.document.writeln('<samp>Starting Benchmark Suite<br>');
window.document.writeln('<table>');
});
}
// Handle a message coming from the NaCl module.
function handleMessage(message_event) {
if (message_event.data.message == 'benchmark_result') {
// benchmark result
var name = message_event.data.benchmark.name;
var result = message_event.data.benchmark.result;
var text = '<tr><th>' + name + ': </th><th>' + result + '</th></tr>';
console.log(text);
var window = document.getElementById('result').contentWindow;
window.document.writeln(text);
}
if (message_event.data.message == 'benchmark_finish') {
common.updateStatus('READY TO RUN');
var window = document.getElementById('result').contentWindow;
window.document.writeln('</table>');
window.document.writeln('Finished.<br><br></samp>');
}
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <ppapi/cpp/input_event.h>
#include <ppapi/cpp/instance.h>
#include <ppapi/cpp/module.h>
#include <ppapi/cpp/point.h>
#include <ppapi/cpp/var.h>
#include <ppapi/cpp/var_array.h>
#include <ppapi/cpp/var_dictionary.h>
#include <ppapi/utility/completion_callback_factory.h>
#include <stdint.h>
#include <sys/time.h>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include "framework.h"
void BenchmarkPost(Benchmark* b, double median, double range, void* data) {
pp::VarDictionary benchmark;
benchmark.Set("name", b->Name());
std::ostringstream result;
result << std::fixed << std::setw(8) << std::setprecision(5) <<
median << " seconds";
benchmark.Set("result", result.str());
pp::VarDictionary message;
message.Set("message", "benchmark_result");
message.Set("benchmark", benchmark);
pp::Instance* instance = static_cast<pp::Instance*>(data);
instance->PostMessage(message);
}
// Pepper framework
class BenchmarksInstance : public pp::Instance {
public:
explicit BenchmarksInstance(PP_Instance instance)
: pp::Instance(instance),
callback_factory_(this) {}
~BenchmarksInstance() {}
virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
return true;
}
virtual void HandleMessage(const pp::Var& var) {
if (var.is_dictionary()) {
pp::VarDictionary dictionary(var);
std::string message = dictionary.Get("message").AsString();
if (message == "run_benchmark") {
BenchmarkSuite::Run("", BenchmarkPost, this);
pp::VarDictionary message;
message.Set("message", "benchmark_finish");
PostMessage(message);
}
}
}
private:
pp::CompletionCallbackFactory<BenchmarksInstance> callback_factory_;
};
class BenchmarksModule : public pp::Module {
public:
BenchmarksModule() : pp::Module() {}
virtual ~BenchmarksModule() {}
virtual pp::Instance* CreateInstance(PP_Instance instance) {
return new BenchmarksInstance(instance);
}
};
namespace pp {
Module* CreateModule() { return new BenchmarksModule(); }
} // namespace pp
<!DOCTYPE html>
<html>
<!--
Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<title>{{title}}</title>
<script type="text/javascript" src="common.js"></script>
<script type="text/javascript" src="example.js"></script>
</head>
<body data-width="0" data-height="0" {{attrs}}>
<h1>{{title}}</h1>
<h2>Status: <code id="statusField">NO-STATUS</code></h2>
<!-- The NaCl plugin will be embedded inside the element with id "listener".
See common.js.-->
<div>
A benchmark suite for Native Client.
<br>
<input type="submit" id="benchmark" value="Run Benchmarks">
<br>
<iframe width="640" height="200" id="result" name="result"> </iframe>
<br>
BinaryTrees, Chameneos, and NBody can be found on the
<a href="http://benchmarksgame.alioth.debian.org/">
Computer Language Benchmark Game site.
</a>
</div>
<div id="listener"></div>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment