summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--Android.mk32
-rw-r--r--AndroidManifest.xml144
-rw-r--r--build.properties2
-rw-r--r--build.xml67
-rw-r--r--default.properties11
-rw-r--r--native/Android.mk26
-rw-r--r--native/gl_finish/Android.mk34
-rw-r--r--native/gl_finish/gl_finish.cpp272
-rw-r--r--native/hello_bin/Android.mk13
-rw-r--r--native/hello_bin/hello.c106
-rw-r--r--native/hello_jni/Android.mk16
-rw-r--r--native/hello_jni/hellolib.c11
-rw-r--r--native/libMicro-0.4.0/Android.mk42
-rw-r--r--native/libMicro-0.4.0/Makefile95
-rw-r--r--native/libMicro-0.4.0/Makefile.Aix41
-rw-r--r--native/libMicro-0.4.0/Makefile.Linux43
-rw-r--r--native/libMicro-0.4.0/Makefile.SunOS61
-rw-r--r--native/libMicro-0.4.0/Makefile.benchmarks112
-rw-r--r--native/libMicro-0.4.0/Makefile.com127
-rw-r--r--native/libMicro-0.4.0/OPENSOLARIS.LICENSE385
-rw-r--r--native/libMicro-0.4.0/README85
-rw-r--r--native/libMicro-0.4.0/_Android.mk13
-rw-r--r--native/libMicro-0.4.0/_Executables.mk105
-rw-r--r--native/libMicro-0.4.0/atomic.c74
-rw-r--r--native/libMicro-0.4.0/bench.sh482
-rw-r--r--native/libMicro-0.4.0/benchmark_fini.c46
-rw-r--r--native/libMicro-0.4.0/benchmark_finibatch.c46
-rw-r--r--native/libMicro-0.4.0/benchmark_finirun.c45
-rw-r--r--native/libMicro-0.4.0/benchmark_finiworker.c46
-rw-r--r--native/libMicro-0.4.0/benchmark_init.c46
-rw-r--r--native/libMicro-0.4.0/benchmark_initbatch.c47
-rw-r--r--native/libMicro-0.4.0/benchmark_initrun.c45
-rw-r--r--native/libMicro-0.4.0/benchmark_initworker.c46
-rw-r--r--native/libMicro-0.4.0/benchmark_optswitch.c46
-rw-r--r--native/libMicro-0.4.0/benchmark_result.c47
-rw-r--r--native/libMicro-0.4.0/bind.c163
-rw-r--r--native/libMicro-0.4.0/cachetocache.c222
-rw-r--r--native/libMicro-0.4.0/cascade_cond.c278
-rw-r--r--native/libMicro-0.4.0/cascade_fcntl.c232
-rw-r--r--native/libMicro-0.4.0/cascade_flock.c228
-rw-r--r--native/libMicro-0.4.0/cascade_lockf.c223
-rw-r--r--native/libMicro-0.4.0/cascade_mutex.c227
-rw-r--r--native/libMicro-0.4.0/chdir.c132
-rw-r--r--native/libMicro-0.4.0/close.c141
-rw-r--r--native/libMicro-0.4.0/close_tcp.c241
-rw-r--r--native/libMicro-0.4.0/connection.c305
-rw-r--r--native/libMicro-0.4.0/dup.c139
-rw-r--r--native/libMicro-0.4.0/elided.c59
-rw-r--r--native/libMicro-0.4.0/exec.c101
-rw-r--r--native/libMicro-0.4.0/exec_bin.c65
-rw-r--r--native/libMicro-0.4.0/exit.c160
-rw-r--r--native/libMicro-0.4.0/exp.c73
-rw-r--r--native/libMicro-0.4.0/fcntl.c99
-rw-r--r--native/libMicro-0.4.0/fcntl_ndelay.c100
-rw-r--r--native/libMicro-0.4.0/file_lock.c106
-rw-r--r--native/libMicro-0.4.0/fork.c131
-rw-r--r--native/libMicro-0.4.0/getcontext.c74
-rw-r--r--native/libMicro-0.4.0/getenv.c126
-rw-r--r--native/libMicro-0.4.0/getpeername.c163
-rw-r--r--native/libMicro-0.4.0/getpid.c64
-rw-r--r--native/libMicro-0.4.0/getrusage.c73
-rw-r--r--native/libMicro-0.4.0/getsockname.c125
-rw-r--r--native/libMicro-0.4.0/gettimeofday.c72
-rw-r--r--native/libMicro-0.4.0/isatty.c110
-rw-r--r--native/libMicro-0.4.0/libmicro.c1612
-rw-r--r--native/libMicro-0.4.0/libmicro.h196
-rw-r--r--native/libMicro-0.4.0/libmicro_main.c44
-rw-r--r--native/libMicro-0.4.0/listen.c127
-rw-r--r--native/libMicro-0.4.0/localtime_r.c75
-rw-r--r--native/libMicro-0.4.0/log.c73
-rw-r--r--native/libMicro-0.4.0/longjmp.c65
-rw-r--r--native/libMicro-0.4.0/lrand48.c71
-rw-r--r--native/libMicro-0.4.0/lseek.c130
-rw-r--r--native/libMicro-0.4.0/malloc.c139
-rw-r--r--native/libMicro-0.4.0/memcpy.c160
-rw-r--r--native/libMicro-0.4.0/memmove.c160
-rw-r--r--native/libMicro-0.4.0/memrand.c146
-rw-r--r--native/libMicro-0.4.0/memset.c169
-rwxr-xr-xnative/libMicro-0.4.0/mk_tarball28
-rw-r--r--native/libMicro-0.4.0/mktime.c112
-rw-r--r--native/libMicro-0.4.0/mmap.c198
-rw-r--r--native/libMicro-0.4.0/mprotect.c200
-rw-r--r--native/libMicro-0.4.0/msync.c190
-rw-r--r--native/libMicro-0.4.0/multiview.sh201
-rw-r--r--native/libMicro-0.4.0/munmap.c192
-rw-r--r--native/libMicro-0.4.0/mutex.c194
-rw-r--r--native/libMicro-0.4.0/nop.c63
-rw-r--r--native/libMicro-0.4.0/open.c138
-rw-r--r--native/libMicro-0.4.0/pipe.c566
-rw-r--r--native/libMicro-0.4.0/poll.c218
-rw-r--r--native/libMicro-0.4.0/pread.c142
-rw-r--r--native/libMicro-0.4.0/pthread_create.c160
-rw-r--r--native/libMicro-0.4.0/pwrite.c154
-rw-r--r--native/libMicro-0.4.0/read.c143
-rw-r--r--native/libMicro-0.4.0/realpath.c85
-rw-r--r--native/libMicro-0.4.0/recurse.c110
-rw-r--r--native/libMicro-0.4.0/recurse2.c46
-rw-r--r--native/libMicro-0.4.0/select.c214
-rw-r--r--native/libMicro-0.4.0/semop.c103
-rw-r--r--native/libMicro-0.4.0/setcontext.c67
-rw-r--r--native/libMicro-0.4.0/setsockopt.c99
-rw-r--r--native/libMicro-0.4.0/sigaction.c95
-rw-r--r--native/libMicro-0.4.0/siglongjmp.c69
-rw-r--r--native/libMicro-0.4.0/signal.c100
-rw-r--r--native/libMicro-0.4.0/sigprocmask.c84
-rw-r--r--native/libMicro-0.4.0/socket.c157
-rw-r--r--native/libMicro-0.4.0/socketpair.c118
-rw-r--r--native/libMicro-0.4.0/stat.c88
-rw-r--r--native/libMicro-0.4.0/strcasecmp.c150
-rw-r--r--native/libMicro-0.4.0/strchr.c144
-rw-r--r--native/libMicro-0.4.0/strcmp.c147
-rw-r--r--native/libMicro-0.4.0/strcpy.c145
-rw-r--r--native/libMicro-0.4.0/strftime.c129
-rw-r--r--native/libMicro-0.4.0/strlen.c143
-rw-r--r--native/libMicro-0.4.0/strtol.c67
-rw-r--r--native/libMicro-0.4.0/system.c98
-rw-r--r--native/libMicro-0.4.0/tattle.c154
-rw-r--r--native/libMicro-0.4.0/time.c69
-rw-r--r--native/libMicro-0.4.0/times.c73
-rw-r--r--native/libMicro-0.4.0/wrapper.sh37
-rw-r--r--native/libMicro-0.4.0/write.c154
-rw-r--r--native/libMicro-0.4.0/writev.c149
-rw-r--r--res/drawable-hdpi/crate.bmpbin0 -> 66614 bytes
-rw-r--r--res/drawable-hdpi/glass.bmpbin0 -> 49220 bytes
-rw-r--r--res/drawable-hdpi/icon.pngbin0 -> 14512 bytes
-rw-r--r--res/drawable-hdpi/icon_auto.pngbin0 -> 17921 bytes
-rw-r--r--res/drawable-ldpi/crate.bmpbin0 -> 66614 bytes
-rw-r--r--res/drawable-ldpi/glass.bmpbin0 -> 49220 bytes
-rw-r--r--res/drawable-ldpi/icon.pngbin0 -> 14512 bytes
-rw-r--r--res/drawable-ldpi/icon_auto.pngbin0 -> 17921 bytes
-rw-r--r--res/drawable-mdpi/crate.bmpbin0 -> 66614 bytes
-rw-r--r--res/drawable-mdpi/glass.bmpbin0 -> 49220 bytes
-rw-r--r--res/drawable-mdpi/icon.pngbin0 -> 14512 bytes
-rw-r--r--res/drawable-mdpi/icon_auto.pngbin0 -> 17921 bytes
-rw-r--r--res/drawable/crate.bmpbin0 -> 66614 bytes
-rw-r--r--res/drawable/glass.bmpbin0 -> 49220 bytes
-rw-r--r--res/drawable/icon.pngbin0 -> 14512 bytes
-rw-r--r--res/drawable/icon_auto.pngbin0 -> 17921 bytes
-rw-r--r--res/layout/gc.xml28
-rw-r--r--res/layout/login_dialog.xml12
-rw-r--r--res/layout/main.xml57
-rw-r--r--res/layout/report.xml51
-rw-r--r--res/layout/upload.xml61
-rw-r--r--res/values/strings.xml25
-rw-r--r--src/com/nea/nehe/lesson08/Cube.java335
-rw-r--r--src/com/nea/nehe/lesson08/Lesson08.java339
-rw-r--r--src/com/nea/nehe/lesson08/Run.java93
-rw-r--r--src/com/nea/nehe/lesson16/Cube.java343
-rw-r--r--src/com/nea/nehe/lesson16/Lesson16.java366
-rw-r--r--src/com/nea/nehe/lesson16/Run.java92
-rw-r--r--src/jnt/scimark2/Constants.java37
-rw-r--r--src/jnt/scimark2/FFT.java192
-rw-r--r--src/jnt/scimark2/Jacobi.java40
-rw-r--r--src/jnt/scimark2/LU.java268
-rw-r--r--src/jnt/scimark2/MonteCarlo.java64
-rw-r--r--src/jnt/scimark2/README67
-rw-r--r--src/jnt/scimark2/Random.java257
-rw-r--r--src/jnt/scimark2/SOR.java41
-rw-r--r--src/jnt/scimark2/SparseCompRow.java42
-rw-r--r--src/jnt/scimark2/Stopwatch.java121
-rw-r--r--src/jnt/scimark2/commandline.java92
-rw-r--r--src/jnt/scimark2/kernel.java268
-rw-r--r--src/org/itri/teapot/MyGLSurfaceView.java43
-rw-r--r--src/org/itri/teapot/TeapotES.java80
-rw-r--r--src/org/itri/teapot/TeapotRenderer.java1921
-rw-r--r--src/org/opensolaris/hub/libmicro/NativeCaseMicro.java134
-rw-r--r--src/org/opensolaris/hub/libmicro/NativeTesterMicro.java429
-rw-r--r--src/org/zeroxlab/arithmetic/LinpackLoop.java577
-rw-r--r--src/org/zeroxlab/benchmark/Benchmark.java434
-rw-r--r--src/org/zeroxlab/benchmark/Case.java305
-rw-r--r--src/org/zeroxlab/benchmark/CaseArithmetic.java118
-rw-r--r--src/org/zeroxlab/benchmark/CaseCanvas.java95
-rw-r--r--src/org/zeroxlab/benchmark/CaseDrawCircle.java94
-rw-r--r--src/org/zeroxlab/benchmark/CaseGC.java106
-rw-r--r--src/org/zeroxlab/benchmark/CaseGLCube.java96
-rw-r--r--src/org/zeroxlab/benchmark/CaseNeheLesson08.java96
-rw-r--r--src/org/zeroxlab/benchmark/CaseNeheLesson16.java93
-rw-r--r--src/org/zeroxlab/benchmark/CaseScimark2.java136
-rw-r--r--src/org/zeroxlab/benchmark/CaseTeapot.java90
-rw-r--r--src/org/zeroxlab/benchmark/MicroBenchmark.java104
-rw-r--r--src/org/zeroxlab/benchmark/NativeTester.java336
-rw-r--r--src/org/zeroxlab/benchmark/Report.java86
-rw-r--r--src/org/zeroxlab/benchmark/Scenario.java59
-rw-r--r--src/org/zeroxlab/benchmark/Tester.java213
-rw-r--r--src/org/zeroxlab/benchmark/TesterArithmetic.java151
-rw-r--r--src/org/zeroxlab/benchmark/TesterCanvas.java98
-rw-r--r--src/org/zeroxlab/benchmark/TesterGC.java87
-rw-r--r--src/org/zeroxlab/benchmark/TesterScimark2.java253
-rw-r--r--src/org/zeroxlab/benchmark/Upload.java333
-rw-r--r--src/org/zeroxlab/gc/GCBench.java182
-rw-r--r--src/org/zeroxlab/gc/GCBenchmark.java201
-rw-r--r--src/org/zeroxlab/graphics/DrawCircle.java138
-rw-r--r--src/org/zeroxlab/kubench/Cube.java57
-rw-r--r--src/org/zeroxlab/kubench/GLColor.java48
-rw-r--r--src/org/zeroxlab/kubench/GLFace.java94
-rw-r--r--src/org/zeroxlab/kubench/GLShape.java102
-rw-r--r--src/org/zeroxlab/kubench/GLSurfaceView.java322
-rw-r--r--src/org/zeroxlab/kubench/GLVertex.java88
-rw-r--r--src/org/zeroxlab/kubench/GLWorld.java98
-rw-r--r--src/org/zeroxlab/kubench/Kubench.java388
-rw-r--r--src/org/zeroxlab/kubench/Layer.java101
-rw-r--r--src/org/zeroxlab/kubench/M4.java80
203 files changed, 28012 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ae97069
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+0xbench.keystore
+local.properties
+.*.swp
+.*.swo
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..2f9b2ac
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,32 @@
+#
+# Copyright (C) 2010 0xlab - http://0xlab.org/
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := user
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_PACKAGE_NAME := ZeroXBenchmark
+LOCAL_CERTIFICATE := shared
+
+LOCAL_JNI_SHARED_LIBRARIES := libhello
+
+include $(BUILD_PACKAGE)
+
+include $(LOCAL_PATH)/native/Android.mk
+
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
new file mode 100644
index 0000000..0572adc
--- /dev/null
+++ b/AndroidManifest.xml
@@ -0,0 +1,144 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.zeroxlab.benchmark"
+ android:versionCode="5"
+ android:versionName="1.0.1"
+ >
+
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
+
+ <application
+ android:debuggable="true"
+ android:icon="@drawable/icon"
+ >
+ <activity
+ android:name="Benchmark"
+ android:label="0xBenchmark"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="TesterCanvas"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+ <activity
+ android:name="org.zeroxlab.kubench.Kubench"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+ <activity
+ android:name="org.zeroxlab.graphics.DrawCircle"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="org.zeroxlab.benchmark.TesterGC"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="org.zeroxlab.benchmark.TesterArithmetic"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="org.zeroxlab.benchmark.TesterScimark2"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="org.zeroxlab.benchmark.Report"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="org.zeroxlab.benchmark.Upload"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="com.nea.nehe.lesson08.Run"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="com.nea.nehe.lesson16.Run"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="org.itri.teapot.TeapotES"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="org.zeroxlab.benchmark.NativeTesterPs"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="org.opensolaris.hub.libmicro.NativeTesterMicro"
+ android:screenOrientation="portrait"
+ >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ </intent-filter>
+ </activity>
+ </application>
+ <uses-sdk android:minSdkVersion="7" />
+</manifest>
+
diff --git a/build.properties b/build.properties
new file mode 100644
index 0000000..bb5acce
--- /dev/null
+++ b/build.properties
@@ -0,0 +1,2 @@
+key.store=0xbench.keystore
+key.alias=0xbench
diff --git a/build.xml b/build.xml
new file mode 100644
index 0000000..142913e
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="Benchmark" default="help">
+
+ <!-- The local.properties file is created and updated by the 'android' tool.
+ It contains the path to the SDK. It should *NOT* be checked in in Version
+ Control Systems. -->
+ <property file="local.properties" />
+
+ <!-- The build.properties file can be created by you and is never touched
+ by the 'android' tool. This is the place to change some of the default property values
+ used by the Ant rules.
+ Here are some properties you may want to change/update:
+
+ application.package
+ the name of your application package as defined in the manifest. Used by the
+ 'uninstall' rule.
+ source.dir
+ the name of the source directory. Default is 'src'.
+ out.dir
+ the name of the output directory. Default is 'bin'.
+
+ Properties related to the SDK location or the project target should be updated
+ using the 'android' tool with the 'update' action.
+
+ This file is an integral part of the build system for your application and
+ should be checked in in Version Control Systems.
+
+ -->
+ <property file="build.properties" />
+
+ <!-- The default.properties file is created and updated by the 'android' tool, as well
+ as ADT.
+ This file is an integral part of the build system for your application and
+ should be checked in in Version Control Systems. -->
+ <property file="default.properties" />
+
+ <!-- Custom Android task to deal with the project target, and import the proper rules.
+ This requires ant 1.6.0 or above. -->
+ <path id="android.antlibs">
+ <pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
+ <pathelement path="${sdk.dir}/tools/lib/sdklib.jar" />
+ <pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
+ <pathelement path="${sdk.dir}/tools/lib/apkbuilder.jar" />
+ <pathelement path="${sdk.dir}/tools/lib/jarutils.jar" />
+ </path>
+
+ <taskdef name="setup"
+ classname="com.android.ant.SetupTask"
+ classpathref="android.antlibs" />
+
+ <!-- Execute the Android Setup task that will setup some properties specific to the target,
+ and import the build rules files.
+
+ The rules file is imported from
+ <SDK>/platforms/<target_platform>/templates/android_rules.xml
+
+ To customize some build steps for your project:
+ - copy the content of the main node <project> from android_rules.xml
+ - paste it in this build.xml below the <setup /> task.
+ - disable the import by changing the setup task below to <setup import="false" />
+
+ This will ensure that the properties are setup correctly but that your customized
+ build steps are used.
+ -->
+ <setup />
+
+</project>
diff --git a/default.properties b/default.properties
new file mode 100644
index 0000000..9d79b12
--- /dev/null
+++ b/default.properties
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-4
diff --git a/native/Android.mk b/native/Android.mk
new file mode 100644
index 0000000..ea6ba77
--- /dev/null
+++ b/native/Android.mk
@@ -0,0 +1,26 @@
+#
+# Copyright (C) 2010 0xlab - http://0xlab.org/
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+TOP_LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+include $(TOP_LOCAL_PATH)/hello_jni/Android.mk
+
+include $(TOP_LOCAL_PATH)/gl_finish/Android.mk
+include $(TOP_LOCAL_PATH)/hello_bin/Android.mk
+
+include $(TOP_LOCAL_PATH)/libMicro-0.4.0/Android.mk
diff --git a/native/gl_finish/Android.mk b/native/gl_finish/Android.mk
new file mode 100644
index 0000000..820f3ef
--- /dev/null
+++ b/native/gl_finish/Android.mk
@@ -0,0 +1,34 @@
+#
+# Copyright (C) 2010 0xlab - http://0xlab.org/
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ gl_finish.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ libEGL \
+ libGLESv1_CM \
+ libui
+
+LOCAL_MODULE:= gl_finish_test
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_CFLAGS := -DGL_GLEXT_PROTOTYPES
+
+include $(BUILD_EXECUTABLE)
diff --git a/native/gl_finish/gl_finish.cpp b/native/gl_finish/gl_finish.cpp
new file mode 100644
index 0000000..a0d553d
--- /dev/null
+++ b/native/gl_finish/gl_finish.cpp
@@ -0,0 +1,272 @@
+/*
+ * Copyright (C) 2010 0xlab - htpp://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <sched.h>
+#include <sys/resource.h>
+
+#include <EGL/egl.h>
+#include <GLES/gl.h>
+#include <GLES/glext.h>
+
+#include <utils/Timers.h>
+
+#include <ui/FramebufferNativeWindow.h>
+#include <ui/EGLUtils.h>
+
+using namespace android;
+
+typedef struct {
+ int x;
+ int y;
+ int w;
+ int h;
+ int vertical;
+ int horizontal;
+} Paster;
+
+static void gl_textures_generate(int texNum, GLuint* texName,
+ char* texels,
+ int tex_width, int tex_height);
+static void fill_texture(char* dst,
+ int width, int height,
+ int space);
+static void init_paster(Paster* paster,
+ int w, int h,
+ int screen_w, int screen_h);
+static void update_pasters(Paster** paster,
+ int number,
+ int screen_width, int screen_height);
+static void update_paster_position(Paster* paster,
+ int screen_w, int screen_h);
+
+static void draw_paster(EGLDisplay dpy, EGLSurface surface,
+ Paster** paster, int paster_num, int round,
+ int screen_width, int screen_height,
+ int depth);
+
+int main(int argc, char** argv)
+{
+ EGLint configAttribs[] = {
+ EGL_DEPTH_SIZE, 0,
+ EGL_NONE
+ };
+
+ EGLint majorVersion;
+ EGLint minorVersion;
+ EGLContext context;
+ EGLConfig config;
+ EGLSurface surface;
+ EGLint width, height;
+ EGLDisplay dpy;
+ EGLint z = 0;
+
+ int texNum = 1; // how many textures we want to generate
+ char* texels; // Array for storing texel color
+ GLuint texName[texNum];
+ GLuint tex_width = 300;
+ GLuint tex_height = 200;
+ GLuint tex_space = 4; // 4 bytes RGBA
+
+ int paster_num = 10; // how many Paster we want to generate
+
+ int i; // temporary counter for loop
+ srand(time(NULL));
+ setpriority(PRIO_PROCESS, 0, -20);
+
+ /* Initialize window and context */
+ EGLNativeWindowType window = android_createDisplaySurface();
+
+ dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+ eglInitialize(dpy, &majorVersion, &minorVersion);
+
+ status_t err = EGLUtils::selectConfigForNativeWindow(
+ dpy, configAttribs, window, &config);
+ if (err) {
+ fprintf(stderr, "couldn't find an EGLConfig "
+ "matching the screen format\n");
+ return 0;
+ }
+
+ surface = eglCreateWindowSurface(dpy, config, window, NULL);
+ context = eglCreateContext(dpy, config, NULL, NULL);
+ eglMakeCurrent(dpy, surface, surface, context);
+ eglQuerySurface(dpy, surface, EGL_WIDTH, &width);
+ eglQuerySurface(dpy, surface, EGL_HEIGHT, &height);
+ GLint dim = width < height ? width : height;
+
+ /* fill color into texels and associate texture with texels */
+ texels = (char*)malloc(tex_width * tex_height * tex_space);
+ fill_texture(texels, tex_width, tex_height, tex_space);
+ gl_textures_generate(texNum, texName, texels, tex_width, tex_height);
+
+ Paster* paster[paster_num];
+ for(i = 0; i < paster_num; ++i) {
+ paster[i] = (Paster *) malloc(sizeof(Paster));
+ init_paster(paster[i], tex_width, tex_height, width, height);
+ }
+
+ draw_paster(dpy, surface, paster, paster_num, 100, width, height, z);
+
+ return 0;
+}
+
+static void gl_textures_generate(int texNum, GLuint* texName,
+ char* texels,
+ int tex_width, int tex_height)
+{
+ GLint crop[4] = {
+ 0,
+ tex_width, tex_height,
+ -1 * tex_width};
+ glGenTextures(texNum, texName);
+
+ /* Bind to first texture only */
+ glBindTexture(GL_TEXTURE_2D, texName[0]);
+ glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glColor4f(1,1,1,1);
+ glDisable(GL_DITHER);
+ glShadeModel(GL_FLAT);
+ glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
+ tex_width, tex_height, 0, GL_RGBA,
+ GL_UNSIGNED_BYTE, texels);
+}
+
+static void fill_texture(char* dst, int width, int height, int space)
+{
+ int i, j;
+ int abgr = 0x330000ff;
+ int *ptr = (int*) dst;
+
+ for (i = 0; i < width; i++) {
+ for (j = 0; j < height; j++) {
+ int c = (j * width + i);
+ *(ptr + c) = abgr;
+ }
+ }
+}
+
+static void init_paster(Paster* paster,
+ int w, int h,
+ int screen_w, int screen_h)
+{
+ int offset_w = 0;
+ int offset_h = 0;
+
+ if (screen_w > w) {
+ offset_w = screen_w - w;
+ }
+ if (screen_h > h) {
+ offset_h = screen_h - h;
+ }
+
+ paster->x = rand() % offset_w;
+ paster->y = rand() % offset_h;
+ paster->w = w;
+ paster->h = h;
+ paster->horizontal = rand() % 3 - 1;
+ paster->vertical = rand() % 3 - 1;
+ update_paster_position(paster, screen_w, screen_h);
+}
+
+void update_paster_position(Paster* paster,
+ int screen_w, int screen_h)
+{
+ int x = paster->x;
+ int y = paster->y;
+ int w = paster->w;
+ int h = paster->h;
+ int hV = paster->horizontal;
+ int vV = paster->vertical;
+
+ if (x + w + hV > screen_w) {
+ paster->horizontal = -1;
+ }
+ if (x + hV < 0) {
+ paster->horizontal = 1;
+ }
+ if (y + h + vV > screen_h) {
+ paster->vertical = -1;
+ }
+ if (y + vV < 0) {
+ paster->vertical= 1;
+ }
+
+ paster->x = x + paster->horizontal;
+ paster->y = y + paster->vertical;
+}
+
+static void update_pasters(Paster** paster,
+ int number,
+ int screen_width, int screen_height)
+{
+ int i = 0;
+ for (i = 0; i < number; ++i) {
+ update_paster_position(paster[i],
+ screen_width, screen_height);
+ }
+}
+
+static void draw_paster(EGLDisplay dpy, EGLSurface surface,
+ Paster** paster,
+ int paster_num, int round,
+ int screen_width, int screen_height, int depth)
+{
+ int r = 0;
+ int i = 0;
+
+ long long start_time;
+ long long end_time;
+ long long total_time;
+
+ glClear(GL_COLOR_BUFFER_BIT);
+ total_time = 0;
+
+ for (r = 0; r < round; r ++) {
+ glClear(GL_COLOR_BUFFER_BIT);
+ update_pasters(paster, paster_num, screen_width, screen_height);
+
+ start_time = systemTime();
+ for (i = 0; i<paster_num ; i++) {
+ glDrawTexiOES(paster[i]->x, paster[i]->y,
+ depth,
+ paster[i]->w, paster[i]->h);
+ }
+ glFinish();
+ eglSwapBuffers(dpy, surface);
+ end_time = systemTime();
+ total_time += (end_time - start_time);
+ }
+
+
+ long long total_us = total_time / 1000;
+ printf("Repeat drawing for %d times, spend %llu us, "
+ "average: %llu us per drawing\n",
+ round, total_us, total_us/round);
+ fflush(stdout);
+
+ return;
+}
+
+/* -*- Mode: C; tab-width: 4 -*- */
diff --git a/native/hello_bin/Android.mk b/native/hello_bin/Android.mk
new file mode 100644
index 0000000..2c7d201
--- /dev/null
+++ b/native/hello_bin/Android.mk
@@ -0,0 +1,13 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= hello.c
+
+LOCAL_MODULE:= hello
+LOCAL_MODULE_TAGS := optional
+
+
+LOCAL_C_INCLUDES := \
+ $(JNI_H_INCLUDE)
+
+include $(BUILD_EXECUTABLE)
diff --git a/native/hello_bin/hello.c b/native/hello_bin/hello.c
new file mode 100644
index 0000000..cd1bc82
--- /dev/null
+++ b/native/hello_bin/hello.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2010 0xlab - htpp://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <netinet/tcp.h>
+
+#define MESSAGE "SOCKET!!\n"
+#define SERVERHOST "localhost"
+uint16_t PORT = -1;
+
+
+void init_sockaddr (struct sockaddr_in *name, const char *hostname, uint16_t port)
+{
+ struct hostent *hostinfo;
+
+ name->sin_family = AF_INET;
+ name->sin_port = htons (port);
+ hostinfo = gethostbyname (hostname);
+ if (hostinfo == NULL) {
+ fprintf (stderr, "Unknown host %s.\n", hostname);
+ fflush(stderr);
+ exit (EXIT_FAILURE);
+ }
+ name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
+}
+
+int make_socket()
+{
+ PORT = atoi(getenv("ZXBENCH_PORT"));
+
+ int sock = socket (PF_INET, SOCK_STREAM, 0);
+ if (sock < 0) {
+ fprintf(stderr, "cannot create socket.\n");
+ fflush(stderr);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Disable Nagle buffering algo */
+ int flag = 1;
+ setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));
+
+ struct sockaddr_in servername;
+ /* Connect to the server. */
+ init_sockaddr (&servername, SERVERHOST, PORT);
+ if ( 0 > connect(sock, (struct sockaddr *) &servername, sizeof (servername)) ) {
+ fprintf (stderr, "cannot connect to server.");
+ fflush(stderr);
+ exit (EXIT_FAILURE);
+ }
+
+ return sock;
+}
+
+void write_to_server (int socket)
+{
+ int nbytes;
+
+ nbytes = write (socket, MESSAGE, strlen (MESSAGE));
+ if (nbytes < 0) {
+ fprintf (stderr, "write failed.");
+ fflush(stderr);
+ exit (EXIT_FAILURE);
+ }
+}
+
+
+int main(int argc, char** argv)
+{
+ printf("HHHEEELLLLOOOOOOOO\n");
+
+ int sock = make_socket();
+
+ int i;
+ for (i=0; i<20; i++) {
+ fprintf(stdout, "stdout %d\n", i);
+ fflush(stdout);
+ fprintf(stderr, "srderr %d\n", i);
+ fflush(stderr);
+ write_to_server(sock);
+ sleep(1);
+ }
+
+ close(sock);
+ return EXIT_SUCCESS;
+}
+
+
+/* -*- Mode: C; tab-width: 4 -*- */
diff --git a/native/hello_jni/Android.mk b/native/hello_jni/Android.mk
new file mode 100644
index 0000000..3b6533e
--- /dev/null
+++ b/native/hello_jni/Android.mk
@@ -0,0 +1,16 @@
+LOCAL_PATH:= $(call my-dir)
+
+LOCAL_SRC_FILES:= \
+ hellolib.c
+
+LOCAL_C_INCLUDES := \
+ $(JNI_H_INCLUDE)
+
+LOCAL_SHARED_LIBRARIES := \
+ libutils
+
+LOCAL_PRELINK_MODULE := false
+
+LOCAL_MODULE := libhello
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/native/hello_jni/hellolib.c b/native/hello_jni/hellolib.c
new file mode 100644
index 0000000..f7f6b46
--- /dev/null
+++ b/native/hello_jni/hellolib.c
@@ -0,0 +1,11 @@
+#include <jni.h>
+
+#define LOG_TAG "TestLib"
+#undef LOG
+#include <utils/Log.h>
+
+
+JNIEXPORT void JNICALL Java_org_zeroxlab_benchmark_Benchmark_printHello(JNIEnv * env, jobject jobj)
+{
+ LOGD("Hello LIB!\n");
+}
diff --git a/native/libMicro-0.4.0/Android.mk b/native/libMicro-0.4.0/Android.mk
new file mode 100644
index 0000000..c420325
--- /dev/null
+++ b/native/libMicro-0.4.0/Android.mk
@@ -0,0 +1,42 @@
+#
+# Copyright (C) 2010 0xlab - http://0xlab.org/
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := \
+ libmicro.c \
+ libmicro_main.c \
+ benchmark_init.c \
+ benchmark_fini.c \
+ benchmark_finirun.c \
+ benchmark_initrun.c \
+ benchmark_initbatch.c \
+ benchmark_finibatch.c \
+ benchmark_initworker.c \
+ benchmark_finiworker.c \
+ benchmark_optswitch.c \
+ benchmark_result.c
+
+LOCAL_MODULE:= libmicro
+include $(BUILD_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+include $(LOCAL_PATH)/_Executables.mk
+
+$(foreach TARGET_MODULE, $(EXEs), $(eval include $(LOCAL_PATH)/_Android.mk))
+
+
diff --git a/native/libMicro-0.4.0/Makefile b/native/libMicro-0.4.0/Makefile
new file mode 100644
index 0000000..aee11a5
--- /dev/null
+++ b/native/libMicro-0.4.0/Makefile
@@ -0,0 +1,95 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms
+# of the Common Development and Distribution License
+# (the "License"). You may not use this file except
+# in compliance with the License.
+#
+# You can obtain a copy of the license at
+# src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL
+# HEADER in each file and include the License file at
+# usr/src/OPENSOLARIS.LICENSE. If applicable,
+# add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your
+# own identifying information: Portions Copyright [yyyy]
+# [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+
+include Makefile.benchmarks
+
+BINS= $(ALL:%=bin/%) bin/tattle
+
+TARBALL_CONTENTS = \
+ Makefile.benchmarks \
+ Makefile.SunOS \
+ Makefile.Linux \
+ Makefile.Aix \
+ Makefile.com \
+ Makefile \
+ $(ALL:%=%.c) \
+ elided.c \
+ exec_bin.c \
+ libmicro.c \
+ libmicro_main.c \
+ libmicro.h \
+ recurse2.c \
+ benchmark_finibatch.c \
+ benchmark_initbatch.c \
+ benchmark_optswitch.c \
+ benchmark_fini.c \
+ benchmark_init.c \
+ benchmark_result.c \
+ benchmark_finirun.c \
+ benchmark_initrun.c \
+ benchmark_initworker.c \
+ benchmark_finiworker.c \
+ bench \
+ bench.sh \
+ mk_tarball \
+ multiview \
+ multiview.sh \
+ OPENSOLARIS.LICENSE \
+ tattle.c \
+ wrapper \
+ wrapper.sh \
+ README
+
+default $(ALL) run cstyle lint tattle: $(BINS)
+ @cp bench.sh bench
+ @cp multiview.sh multiview
+ @cp wrapper.sh wrapper
+ @chmod +x bench multiview wrapper
+ @mkdir -p bin-`uname -m`; cd bin-`uname -m`; MACH=`uname -m` $(MAKE) -f ../Makefile.`uname -s` UNAME_RELEASE=`uname -r | sed 's/\./_/g'` $@
+
+clean:
+ rm -rf bin bin-* wrapper multiview bench
+
+bin:
+ @mkdir -p bin
+
+$(BINS): bin
+ @cp wrapper.sh wrapper
+ @chmod +x wrapper
+ @ln -sf ../wrapper $@
+
+
+libMicro.tar: FORCE
+ @chmod +x ./mk_tarball wrapper
+ @./mk_tarball $(TARBALL_CONTENTS)
+
+FORCE:
+
diff --git a/native/libMicro-0.4.0/Makefile.Aix b/native/libMicro-0.4.0/Makefile.Aix
new file mode 100644
index 0000000..9e4dc42
--- /dev/null
+++ b/native/libMicro-0.4.0/Makefile.Aix
@@ -0,0 +1,41 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms
+# of the Common Development and Distribution License
+# (the "License"). You may not use this file except
+# in compliance with the License.
+#
+# You can obtain a copy of the license at
+# src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL
+# HEADER in each file and include the License file at
+# usr/src/OPENSOLARIS.LICENSE. If applicable,
+# add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your
+# own identifying information: Portions Copyright [yyyy]
+# [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+
+CFLAGS= -O3
+
+CPPFLAGS = -D_REENTRANT
+
+include ../Makefile.com
+
+NSLLIB= -lnsl
+SOCKLIB=
+
+.KEEP_STATE:
diff --git a/native/libMicro-0.4.0/Makefile.Linux b/native/libMicro-0.4.0/Makefile.Linux
new file mode 100644
index 0000000..ca12d15
--- /dev/null
+++ b/native/libMicro-0.4.0/Makefile.Linux
@@ -0,0 +1,43 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms
+# of the Common Development and Distribution License
+# (the "License"). You may not use this file except
+# in compliance with the License.
+#
+# You can obtain a copy of the license at
+# src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL
+# HEADER in each file and include the License file at
+# usr/src/OPENSOLARIS.LICENSE. If applicable,
+# add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your
+# own identifying information: Portions Copyright [yyyy]
+# [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+
+CC= gcc
+
+#CFLAGS= -O -DUSE_SEMOP
+CPPFLAGS= -DUSE_SEMOP -D_REENTRANT
+MATHLIB= -lm
+
+ELIDED_BENCHMARKS= \
+ cachetocache \
+ atomic
+
+
+include ../Makefile.com
diff --git a/native/libMicro-0.4.0/Makefile.SunOS b/native/libMicro-0.4.0/Makefile.SunOS
new file mode 100644
index 0000000..4fc7269
--- /dev/null
+++ b/native/libMicro-0.4.0/Makefile.SunOS
@@ -0,0 +1,61 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms
+# of the Common Development and Distribution License
+# (the "License"). You may not use this file except
+# in compliance with the License.
+#
+# You can obtain a copy of the license at
+# src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL
+# HEADER in each file and include the License file at
+# usr/src/OPENSOLARIS.LICENSE. If applicable,
+# add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your
+# own identifying information: Portions Copyright [yyyy]
+# [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+
+CPPFLAGS= -DUSE_GETHRTIME -D_REENTRANT
+
+CFLAGS = -O $(extra_CFLAGS)
+
+#
+# These defines allow libmicro to be compiled against older Solaris
+# releases by turning off the tests which don't work there.
+#
+# This is a little contorted-- UNAME_RELEASE is set as an environment
+# variable for us by the invoking make process (see Makefile)-- it is
+# the output of uname -r | sed 's/\./_/g'.
+#
+# We couldn't find any other gmake/unix make portable way to make this
+# work.
+#
+ELIDED_BENCHMARKS_5_8=atomic cachetocache
+ELIDED_BENCHMARKS_5_9=atomic
+
+ELIDED_BENCHMARKS_CMN=cascade_flock
+
+ELIDED_BENCHMARKS=$(ELIDED_BENCHMARKS_CMN) $(ELIDED_BENCHMARKS_$(UNAME_RELEASE))
+
+include ../Makefile.com
+
+NSLLIB= -lnsl
+SOCKLIB= -lsocket
+UCBLIB= -lc -L/usr/ucblib -lucb -R/usr/ucblib
+MATHLIB= -lm
+
+.KEEP_STATE:
diff --git a/native/libMicro-0.4.0/Makefile.benchmarks b/native/libMicro-0.4.0/Makefile.benchmarks
new file mode 100644
index 0000000..ed1923a
--- /dev/null
+++ b/native/libMicro-0.4.0/Makefile.benchmarks
@@ -0,0 +1,112 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms
+# of the Common Development and Distribution License
+# (the "License"). You may not use this file except
+# in compliance with the License.
+#
+# You can obtain a copy of the license at
+# src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL
+# HEADER in each file and include the License file at
+# usr/src/OPENSOLARIS.LICENSE. If applicable,
+# add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your
+# own identifying information: Portions Copyright [yyyy]
+# [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+
+ALL= \
+ atomic \
+ bind \
+ cachetocache \
+ cascade_mutex \
+ cascade_cond \
+ cascade_lockf \
+ cascade_fcntl \
+ cascade_flock \
+ chdir \
+ close \
+ close_tcp \
+ connection \
+ dup \
+ exec \
+ exit \
+ exp \
+ fcntl \
+ fcntl_ndelay \
+ file_lock \
+ fork \
+ getcontext \
+ getenv \
+ gettimeofday \
+ getpeername \
+ getpid \
+ getrusage \
+ getsockname \
+ isatty \
+ listen \
+ localtime_r \
+ log \
+ longjmp \
+ lrand48 \
+ lseek \
+ malloc \
+ memcpy \
+ memmove \
+ memrand \
+ memset \
+ mktime \
+ mprotect \
+ mmap \
+ msync \
+ munmap \
+ mutex \
+ nop \
+ open \
+ pipe \
+ poll \
+ pread \
+ pthread_create \
+ pwrite \
+ read \
+ realpath \
+ recurse \
+ select \
+ semop \
+ setcontext \
+ setsockopt \
+ sigaction \
+ siglongjmp \
+ signal \
+ sigprocmask \
+ socket \
+ socketpair \
+ stat \
+ strcasecmp \
+ strchr \
+ strcmp \
+ strcpy \
+ strftime \
+ strlen \
+ strtol \
+ system \
+ time \
+ times \
+ write \
+ writev
+
+
diff --git a/native/libMicro-0.4.0/Makefile.com b/native/libMicro-0.4.0/Makefile.com
new file mode 100644
index 0000000..61f2684
--- /dev/null
+++ b/native/libMicro-0.4.0/Makefile.com
@@ -0,0 +1,127 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms
+# of the Common Development and Distribution License
+# (the "License"). You may not use this file except
+# in compliance with the License.
+#
+# You can obtain a copy of the license at
+# src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL
+# HEADER in each file and include the License file at
+# usr/src/OPENSOLARIS.LICENSE. If applicable,
+# add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your
+# own identifying information: Portions Copyright [yyyy]
+# [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+include ../Makefile.benchmarks
+
+EXTRA_CFILES= \
+ exec_bin.c \
+ elided.c \
+ tattle.c
+
+#
+# some definitions to make getting compiler versions possible - avoid quotes
+#
+COMPILER_VERSION_CMD_cc=cc -V 2>&1 | egrep Sun
+COMPILER_VERSION_CMD_gcc=gcc -dumpversion
+COMPILER_VERSION_CMD=$(COMPILER_VERSION_CMD_$(CC))
+
+default: $(ALL) tattle
+
+cstyle:
+ for file in $(ALL:%=../%.c) $(EXTRA_CFILES:%=../%) ; \
+ do cstyle -p $$file ;\
+ done
+
+
+lint: libmicro.ln $(ALL:%=%.lint) $(EXTRA_CFILES:%.c=%.lint)
+
+
+$(EXTRA_CFILES:%.c=%.lint):
+ $(LINT) ../$(@:%.lint=%.c) -I. -mu -lc libmicro.ln -lm
+
+%.lint: ../%.c libmicro.ln
+ $(LINT) -mu $(CPPFLAGS) $< libmicro.ln -lpthread -lsocket -lnsl -lm
+
+%.o: ../%.c
+ $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
+
+libmicro.ln: ../libmicro.c ../libmicro_main.c ../libmicro.h ../benchmark_*.c
+ $(LINT) -muc $(CPPFLAGS) ../libmicro.c ../libmicro_main.c ../benchmark_*.c
+
+CPPFLAGS+= -D_REENTRANT
+
+bind_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB)
+cascade_flock_EXTRA_LIBS=$(UCBLIB)
+close_tcp_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB)
+connection_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB)
+fcntl_ndelay_EXTRA_LIBS=$(SOCKLIB)
+getpeername_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB)
+getsockname_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB)
+listen_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB)
+log_EXTRA_LIBS=$(MATHLIB)
+pipe_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB)
+poll_EXTRA_LIBS=$(SOCKLIB)
+select_EXTRA_LIBS=$(SOCKLIB)
+setsockopt_EXTRA_LIBS=$(NSLLIB) $(SOCKLIB)
+socket_EXTRA_LIBS=$(SOCKLIB)
+socketpair_EXTRA_LIBS=$(SOCKLIB)
+
+BENCHMARK_FUNCS= \
+ benchmark_init.o \
+ benchmark_fini.o \
+ benchmark_initrun.o \
+ benchmark_finirun.o \
+ benchmark_initbatch.o \
+ benchmark_finibatch.o \
+ benchmark_initworker.o \
+ benchmark_finiworker.o \
+ benchmark_optswitch.o \
+ benchmark_result.o
+
+recurse_EXTRA_DEPS=recurse2.o
+
+
+recurse: $(recurse_EXTRA_DEPS)
+
+libmicro.a: libmicro.o libmicro_main.o $(BENCHMARK_FUNCS)
+ $(AR) -cr libmicro.a libmicro.o libmicro_main.o $(BENCHMARK_FUNCS)
+
+tattle: ../tattle.c libmicro.a
+ echo "char * compiler_version = \""`$(COMPILER_VERSION_CMD)`"\";" > tattle.h
+ echo "char * CC = \""$(CC)"\";" >> tattle.h
+ echo "char * extra_compiler_flags = \""$(extra_CFLAGS)"\";" >> tattle.h
+ $(CC) -o tattle $(CFLAGS) -I. ../tattle.c libmicro.a -lrt -lm
+
+$(ELIDED_BENCHMARKS): ../elided.c
+ $(CC) -o $(@) ../elided.c
+
+%: libmicro.a %.o
+ $(CC) -o $(@) $(@).o $($(@)_EXTRA_DEPS) $(CFLAGS) libmicro.a $($(@)_EXTRA_LIBS) $(EXTRA_LIBS) -lpthread -lm
+
+exec: exec_bin
+
+exec_bin: exec_bin.o
+ $(CC) -o exec_bin $(CFLAGS) exec_bin.o
+
+FORCE:
+
+
+._KEEP_STATE:
+
diff --git a/native/libMicro-0.4.0/OPENSOLARIS.LICENSE b/native/libMicro-0.4.0/OPENSOLARIS.LICENSE
new file mode 100644
index 0000000..535dec2
--- /dev/null
+++ b/native/libMicro-0.4.0/OPENSOLARIS.LICENSE
@@ -0,0 +1,385 @@
+Unless otherwise noted, all files in this distribution are released
+under the Common Development and Distribution License (CDDL),
+Version 1.0 only. Exceptions are noted within the associated
+source files.
+
+--------------------------------------------------------------------
+
+
+COMMON DEVELOPMENT AND DISTRIBUTION LICENSE Version 1.0
+
+1. Definitions.
+
+ 1.1. "Contributor" means each individual or entity that creates
+ or contributes to the creation of Modifications.
+
+ 1.2. "Contributor Version" means the combination of the Original
+ Software, prior Modifications used by a Contributor (if any),
+ and the Modifications made by that particular Contributor.
+
+ 1.3. "Covered Software" means (a) the Original Software, or (b)
+ Modifications, or (c) the combination of files containing
+ Original Software with files containing Modifications, in
+ each case including portions thereof.
+
+ 1.4. "Executable" means the Covered Software in any form other
+ than Source Code.
+
+ 1.5. "Initial Developer" means the individual or entity that first
+ makes Original Software available under this License.
+
+ 1.6. "Larger Work" means a work which combines Covered Software or
+ portions thereof with code not governed by the terms of this
+ License.
+
+ 1.7. "License" means this document.
+
+ 1.8. "Licensable" means having the right to grant, to the maximum
+ extent possible, whether at the time of the initial grant or
+ subsequently acquired, any and all of the rights conveyed
+ herein.
+
+ 1.9. "Modifications" means the Source Code and Executable form of
+ any of the following:
+
+ A. Any file that results from an addition to, deletion from or
+ modification of the contents of a file containing Original
+ Software or previous Modifications;
+
+ B. Any new file that contains any part of the Original
+ Software or previous Modifications; or
+
+ C. Any new file that is contributed or otherwise made
+ available under the terms of this License.
+
+ 1.10. "Original Software" means the Source Code and Executable
+ form of computer software code that is originally released
+ under this License.
+
+ 1.11. "Patent Claims" means any patent claim(s), now owned or
+ hereafter acquired, including without limitation, method,
+ process, and apparatus claims, in any patent Licensable by
+ grantor.
+
+ 1.12. "Source Code" means (a) the common form of computer software
+ code in which modifications are made and (b) associated
+ documentation included in or with such code.
+
+ 1.13. "You" (or "Your") means an individual or a legal entity
+ exercising rights under, and complying with all of the terms
+ of, this License. For legal entities, "You" includes any
+ entity which controls, is controlled by, or is under common
+ control with You. For purposes of this definition,
+ "control" means (a) the power, direct or indirect, to cause
+ the direction or management of such entity, whether by
+ contract or otherwise, or (b) ownership of more than fifty
+ percent (50%) of the outstanding shares or beneficial
+ ownership of such entity.
+
+2. License Grants.
+
+ 2.1. The Initial Developer Grant.
+
+ Conditioned upon Your compliance with Section 3.1 below and
+ subject to third party intellectual property claims, the Initial
+ Developer hereby grants You a world-wide, royalty-free,
+ non-exclusive license:
+
+ (a) under intellectual property rights (other than patent or
+ trademark) Licensable by Initial Developer, to use,
+ reproduce, modify, display, perform, sublicense and
+ distribute the Original Software (or portions thereof),
+ with or without Modifications, and/or as part of a Larger
+ Work; and
+
+ (b) under Patent Claims infringed by the making, using or
+ selling of Original Software, to make, have made, use,
+ practice, sell, and offer for sale, and/or otherwise
+ dispose of the Original Software (or portions thereof).
+
+ (c) The licenses granted in Sections 2.1(a) and (b) are
+ effective on the date Initial Developer first distributes
+ or otherwise makes the Original Software available to a
+ third party under the terms of this License.
+
+ (d) Notwithstanding Section 2.1(b) above, no patent license is
+ granted: (1) for code that You delete from the Original
+ Software, or (2) for infringements caused by: (i) the
+ modification of the Original Software, or (ii) the
+ combination of the Original Software with other software
+ or devices.
+
+ 2.2. Contributor Grant.
+
+ Conditioned upon Your compliance with Section 3.1 below and
+ subject to third party intellectual property claims, each
+ Contributor hereby grants You a world-wide, royalty-free,
+ non-exclusive license:
+
+ (a) under intellectual property rights (other than patent or
+ trademark) Licensable by Contributor to use, reproduce,
+ modify, display, perform, sublicense and distribute the
+ Modifications created by such Contributor (or portions
+ thereof), either on an unmodified basis, with other
+ Modifications, as Covered Software and/or as part of a
+ Larger Work; and
+
+ (b) under Patent Claims infringed by the making, using, or
+ selling of Modifications made by that Contributor either
+ alone and/or in combination with its Contributor Version
+ (or portions of such combination), to make, use, sell,
+ offer for sale, have made, and/or otherwise dispose of:
+ (1) Modifications made by that Contributor (or portions
+ thereof); and (2) the combination of Modifications made by
+ that Contributor with its Contributor Version (or portions
+ of such combination).
+
+ (c) The licenses granted in Sections 2.2(a) and 2.2(b) are
+ effective on the date Contributor first distributes or
+ otherwise makes the Modifications available to a third
+ party.
+
+ (d) Notwithstanding Section 2.2(b) above, no patent license is
+ granted: (1) for any code that Contributor has deleted
+ from the Contributor Version; (2) for infringements caused
+ by: (i) third party modifications of Contributor Version,
+ or (ii) the combination of Modifications made by that
+ Contributor with other software (except as part of the
+ Contributor Version) or other devices; or (3) under Patent
+ Claims infringed by Covered Software in the absence of
+ Modifications made by that Contributor.
+
+3. Distribution Obligations.
+
+ 3.1. Availability of Source Code.
+
+ Any Covered Software that You distribute or otherwise make
+ available in Executable form must also be made available in Source
+ Code form and that Source Code form must be distributed only under
+ the terms of this License. You must include a copy of this
+ License with every copy of the Source Code form of the Covered
+ Software You distribute or otherwise make available. You must
+ inform recipients of any such Covered Software in Executable form
+ as to how they can obtain such Covered Software in Source Code
+ form in a reasonable manner on or through a medium customarily
+ used for software exchange.
+
+ 3.2. Modifications.
+
+ The Modifications that You create or to which You contribute are
+ governed by the terms of this License. You represent that You
+ believe Your Modifications are Your original creation(s) and/or
+ You have sufficient rights to grant the rights conveyed by this
+ License.
+
+ 3.3. Required Notices.
+
+ You must include a notice in each of Your Modifications that
+ identifies You as the Contributor of the Modification. You may
+ not remove or alter any copyright, patent or trademark notices
+ contained within the Covered Software, or any notices of licensing
+ or any descriptive text giving attribution to any Contributor or
+ the Initial Developer.
+
+ 3.4. Application of Additional Terms.
+
+ You may not offer or impose any terms on any Covered Software in
+ Source Code form that alters or restricts the applicable version
+ of this License or the recipients' rights hereunder. You may
+ choose to offer, and to charge a fee for, warranty, support,
+ indemnity or liability obligations to one or more recipients of
+ Covered Software. However, you may do so only on Your own behalf,
+ and not on behalf of the Initial Developer or any Contributor.
+ You must make it absolutely clear that any such warranty, support,
+ indemnity or liability obligation is offered by You alone, and You
+ hereby agree to indemnify the Initial Developer and every
+ Contributor for any liability incurred by the Initial Developer or
+ such Contributor as a result of warranty, support, indemnity or
+ liability terms You offer.
+
+ 3.5. Distribution of Executable Versions.
+
+ You may distribute the Executable form of the Covered Software
+ under the terms of this License or under the terms of a license of
+ Your choice, which may contain terms different from this License,
+ provided that You are in compliance with the terms of this License
+ and that the license for the Executable form does not attempt to
+ limit or alter the recipient's rights in the Source Code form from
+ the rights set forth in this License. If You distribute the
+ Covered Software in Executable form under a different license, You
+ must make it absolutely clear that any terms which differ from
+ this License are offered by You alone, not by the Initial
+ Developer or Contributor. You hereby agree to indemnify the
+ Initial Developer and every Contributor for any liability incurred
+ by the Initial Developer or such Contributor as a result of any
+ such terms You offer.
+
+ 3.6. Larger Works.
+
+ You may create a Larger Work by combining Covered Software with
+ other code not governed by the terms of this License and
+ distribute the Larger Work as a single product. In such a case,
+ You must make sure the requirements of this License are fulfilled
+ for the Covered Software.
+
+4. Versions of the License.
+
+ 4.1. New Versions.
+
+ Sun Microsystems, Inc. is the initial license steward and may
+ publish revised and/or new versions of this License from time to
+ time. Each version will be given a distinguishing version number.
+ Except as provided in Section 4.3, no one other than the license
+ steward has the right to modify this License.
+
+ 4.2. Effect of New Versions.
+
+ You may always continue to use, distribute or otherwise make the
+ Covered Software available under the terms of the version of the
+ License under which You originally received the Covered Software.
+ If the Initial Developer includes a notice in the Original
+ Software prohibiting it from being distributed or otherwise made
+ available under any subsequent version of the License, You must
+ distribute and make the Covered Software available under the terms
+ of the version of the License under which You originally received
+ the Covered Software. Otherwise, You may also choose to use,
+ distribute or otherwise make the Covered Software available under
+ the terms of any subsequent version of the License published by
+ the license steward.
+
+ 4.3. Modified Versions.
+
+ When You are an Initial Developer and You want to create a new
+ license for Your Original Software, You may create and use a
+ modified version of this License if You: (a) rename the license
+ and remove any references to the name of the license steward
+ (except to note that the license differs from this License); and
+ (b) otherwise make it clear that the license contains terms which
+ differ from this License.
+
+5. DISCLAIMER OF WARRANTY.
+
+ COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS"
+ BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
+ INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED
+ SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR
+ PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND
+ PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY
+ COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE
+ INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY
+ NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF
+ WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
+ ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS
+ DISCLAIMER.
+
+6. TERMINATION.
+
+ 6.1. This License and the rights granted hereunder will terminate
+ automatically if You fail to comply with terms herein and fail to
+ cure such breach within 30 days of becoming aware of the breach.
+ Provisions which, by their nature, must remain in effect beyond
+ the termination of this License shall survive.
+
+ 6.2. If You assert a patent infringement claim (excluding
+ declaratory judgment actions) against Initial Developer or a
+ Contributor (the Initial Developer or Contributor against whom You
+ assert such claim is referred to as "Participant") alleging that
+ the Participant Software (meaning the Contributor Version where
+ the Participant is a Contributor or the Original Software where
+ the Participant is the Initial Developer) directly or indirectly
+ infringes any patent, then any and all rights granted directly or
+ indirectly to You by such Participant, the Initial Developer (if
+ the Initial Developer is not the Participant) and all Contributors
+ under Sections 2.1 and/or 2.2 of this License shall, upon 60 days
+ notice from Participant terminate prospectively and automatically
+ at the expiration of such 60 day notice period, unless if within
+ such 60 day period You withdraw Your claim with respect to the
+ Participant Software against such Participant either unilaterally
+ or pursuant to a written agreement with Participant.
+
+ 6.3. In the event of termination under Sections 6.1 or 6.2 above,
+ all end user licenses that have been validly granted by You or any
+ distributor hereunder prior to termination (excluding licenses
+ granted to You by any distributor) shall survive termination.
+
+7. LIMITATION OF LIABILITY.
+
+ UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
+ (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE
+ INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF
+ COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE
+ LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
+ CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT
+ LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK
+ STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
+ COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
+ INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
+ LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL
+ INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT
+ APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO
+ NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR
+ CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT
+ APPLY TO YOU.
+
+8. U.S. GOVERNMENT END USERS.
+
+ The Covered Software is a "commercial item," as that term is
+ defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial
+ computer software" (as that term is defined at 48
+ C.F.R. 252.227-7014(a)(1)) and "commercial computer software
+ documentation" as such terms are used in 48 C.F.R. 12.212
+ (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48
+ C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all
+ U.S. Government End Users acquire Covered Software with only those
+ rights set forth herein. This U.S. Government Rights clause is in
+ lieu of, and supersedes, any other FAR, DFAR, or other clause or
+ provision that addresses Government rights in computer software
+ under this License.
+
+9. MISCELLANEOUS.
+
+ This License represents the complete agreement concerning subject
+ matter hereof. If any provision of this License is held to be
+ unenforceable, such provision shall be reformed only to the extent
+ necessary to make it enforceable. This License shall be governed
+ by the law of the jurisdiction specified in a notice contained
+ within the Original Software (except to the extent applicable law,
+ if any, provides otherwise), excluding such jurisdiction's
+ conflict-of-law provisions. Any litigation relating to this
+ License shall be subject to the jurisdiction of the courts located
+ in the jurisdiction and venue specified in a notice contained
+ within the Original Software, with the losing party responsible
+ for costs, including, without limitation, court costs and
+ reasonable attorneys' fees and expenses. The application of the
+ United Nations Convention on Contracts for the International Sale
+ of Goods is expressly excluded. Any law or regulation which
+ provides that the language of a contract shall be construed
+ against the drafter shall not apply to this License. You agree
+ that You alone are responsible for compliance with the United
+ States export administration regulations (and the export control
+ laws and regulation of any other countries) when You use,
+ distribute or otherwise make available any Covered Software.
+
+10. RESPONSIBILITY FOR CLAIMS.
+
+ As between Initial Developer and the Contributors, each party is
+ responsible for claims and damages arising, directly or
+ indirectly, out of its utilization of rights under this License
+ and You agree to work with Initial Developer and Contributors to
+ distribute such responsibility on an equitable basis. Nothing
+ herein is intended or shall be deemed to constitute any admission
+ of liability.
+
+--------------------------------------------------------------------
+
+NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND
+DISTRIBUTION LICENSE (CDDL)
+
+For Covered Software in this distribution, this License shall
+be governed by the laws of the State of California (excluding
+conflict-of-law provisions).
+
+Any litigation relating to this License shall be subject to the
+jurisdiction of the Federal Courts of the Northern District of
+California and the state courts of the State of California, with
+venue lying in Santa Clara County, California.
diff --git a/native/libMicro-0.4.0/README b/native/libMicro-0.4.0/README
new file mode 100644
index 0000000..d29768e
--- /dev/null
+++ b/native/libMicro-0.4.0/README
@@ -0,0 +1,85 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms
+# of the Common Development and Distribution License
+# (the "License"). You may not use this file except
+# in compliance with the License.
+#
+# You can obtain a copy of the license at
+# src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL
+# HEADER in each file and include the License file at
+# usr/src/OPENSOLARIS.LICENSE. If applicable,
+# add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your
+# own identifying information: Portions Copyright [yyyy]
+# [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+Building the tarball
+--------------------
+As long as cc is in your path, (gcc on Linux),
+
+% tar xf libMicro.tar
+% make
+
+will build the benchmark suite.
+
+Running the benchmarks
+-----------------------
+
+A set of generic scripts to invoke each micro benchmark
+are created in the bin directory; these may be invoked
+directly. Note that the actual binaries are created in
+OS-specific directories; this allows one to build for
+all varients (x86/sparc/Solaris/Linux) in one place.
+
+To collect a complete set of benchmarks, use the bench
+script and redirect its output to a file.
+
+% ./bench > output
+
+To compare the output of two or more runs, use multiview in the src
+directory:
+
+% ./multiview reference compare1 compare2 compare2 > compare.html
+%
+
+where the reference and compare files contain the output of different
+libmicro runs.
+
+The compare.html file will allow quick comparisons to be drawn,
+allowing a variety of experiments to be quickly analyzed.
+
+All benchmarks support the following options:
+
+ [-1] (single process; overrides -P > 1)
+ [-A] (align with clock)
+ [-B batch-size (default 10)]
+ [-C minimum number of samples (default 0)]
+ [-D duration in msecs (default 10s)]
+ [-E (echo name to stderr)]
+ [-H] (suppress headers)
+ [-I] specify approx. time per op in nsecs
+ [-L] (print argument line)
+ [-M] (reports mean rather than median)
+ [-N test-name ]
+ [-P processes (default 1)]
+ [-S] (print detailed stats)
+ [-T threads (default 1)]
+ [-V] (print the libMicro version and exit)
+ [-W] (flag possible benchmark problems)
+
+
diff --git a/native/libMicro-0.4.0/_Android.mk b/native/libMicro-0.4.0/_Android.mk
new file mode 100644
index 0000000..864f1ee
--- /dev/null
+++ b/native/libMicro-0.4.0/_Android.mk
@@ -0,0 +1,13 @@
+include $(CLEAR_VARS)
+
+MODULE:= $(TARGET_MODULE)
+
+LOCAL_CFLAGS:= -D_REENTRANT -D_REENTRANT -lpthread -lm
+
+LOCAL_SRC_FILES:= $(MODULE).c
+LOCAL_STATIC_LIBRARIES:= libmicro
+LOCAL_MODULE:= bench_$(MODULE)
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_EXECUTABLE)
+
diff --git a/native/libMicro-0.4.0/_Executables.mk b/native/libMicro-0.4.0/_Executables.mk
new file mode 100644
index 0000000..31277f7
--- /dev/null
+++ b/native/libMicro-0.4.0/_Executables.mk
@@ -0,0 +1,105 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms
+# of the Common Development and Distribution License
+# (the "License"). You may not use this file except
+# in compliance with the License.
+#
+# You can obtain a copy of the license at
+# src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL
+# HEADER in each file and include the License file at
+# usr/src/OPENSOLARIS.LICENSE. If applicable,
+# add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your
+# own identifying information: Portions Copyright [yyyy]
+# [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+
+EXEs= \
+ getpid \
+ bind \
+ cascade_mutex \
+ cascade_fcntl \
+ cascade_flock \
+ chdir \
+ close \
+ close_tcp \
+ connection \
+ dup \
+ exec \
+ exit \
+ exp \
+ fcntl \
+ fcntl_ndelay \
+ file_lock \
+ fork \
+ getenv \
+ gettimeofday \
+ getpeername \
+ getrusage \
+ getsockname \
+ isatty \
+ listen \
+ localtime_r \
+ log \
+ longjmp \
+ lrand48 \
+ lseek \
+ malloc \
+ memcpy \
+ memmove \
+ memrand \
+ memset \
+ mktime \
+ mprotect \
+ mmap \
+ msync \
+ munmap \
+ mutex \
+ nop \
+ open \
+ pipe \
+ poll \
+ pread \
+ pthread_create \
+ pwrite \
+ read \
+ realpath \
+ recurse \
+ select \
+ setsockopt \
+ sigaction \
+ siglongjmp \
+ signal \
+ sigprocmask \
+ socket \
+ socketpair \
+ stat \
+ strcasecmp \
+ strchr \
+ strcmp \
+ strcpy \
+ strftime \
+ strlen \
+ strtol \
+ system \
+ time \
+ times \
+ write \
+ writev
+
+
diff --git a/native/libMicro-0.4.0/atomic.c b/native/libMicro-0.4.0/atomic.c
new file mode 100644
index 0000000..e005b46
--- /dev/null
+++ b/native/libMicro-0.4.0/atomic.c
@@ -0,0 +1,74 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * benchmarks atomic add on Solaris - useful for platform comparisons.
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <atomic.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "note: measures atomic_add_32_nv()");
+
+ lm_tsdsize = 0;
+
+ return (0);
+}
+
+static unsigned int value = 0;
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ unsigned int i;
+ for (i = 0; i < lm_optB; i += 10) {
+ (void) atomic_add_32_nv(&value, 1);
+ (void) atomic_add_32_nv(&value, 1);
+ (void) atomic_add_32_nv(&value, 1);
+ (void) atomic_add_32_nv(&value, 1);
+ (void) atomic_add_32_nv(&value, 1);
+ (void) atomic_add_32_nv(&value, 1);
+ (void) atomic_add_32_nv(&value, 1);
+ (void) atomic_add_32_nv(&value, 1);
+ (void) atomic_add_32_nv(&value, 1);
+ (void) atomic_add_32_nv(&value, 1);
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/bench.sh b/native/libMicro-0.4.0/bench.sh
new file mode 100644
index 0000000..b700704
--- /dev/null
+++ b/native/libMicro-0.4.0/bench.sh
@@ -0,0 +1,482 @@
+#!/bin/sh
+#
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms
+# of the Common Development and Distribution License
+# (the "License"). You may not use this file except
+# in compliance with the License.
+#
+# You can obtain a copy of the license at
+# src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL
+# HEADER in each file and include the License file at
+# usr/src/OPENSOLARIS.LICENSE. If applicable,
+# add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your
+# own identifying information: Portions Copyright [yyyy]
+# [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+bench_version=0.4.0
+libmicro_version=`bin/tattle -V`
+
+case $libmicro_version in
+$bench_version)
+ ;;
+*)
+ echo "ERROR: libMicro version doesn't match 'bench' script version"
+ exit 1
+esac
+
+TMPROOT=/tmp/libmicro.$$
+VARROOT=/var/tmp/libmicro.$$
+mkdir -p $TMPROOT
+mkdir -p $VARROOT
+trap "rm -rf $TMPROOT $VARROOT" 0 2
+
+TFILE=$TMPROOT/data
+IFILE=$TMPROOT/ifile
+TDIR1=$TMPROOT/0/1/2/3/4/5/6/7/8/9
+TDIR2=$TMPROOT/1/2/3/4/5/6/7/8/9/0
+VFILE=$VARROOT/data
+VDIR1=$VARROOT/0/1/2/3/4/5/6/7/8/9
+VDIR2=$VARROOT/1/2/3/4/5/6/7/8/9/0
+
+
+OPTS="-E -C 200 -L -S -W"
+
+dd if=/dev/zero of=$TFILE bs=1024k count=10 2>/dev/null
+dd if=/dev/zero of=$VFILE bs=1024k count=10 2>/dev/null
+mkdir -p $TDIR1 $TDIR2
+mkdir -p $VDIR1 $VDIR2
+
+touch $IFILE
+
+ARCH=`arch -k`
+
+# produce benchmark header for easier comparisons
+
+hostname=`uname -n`
+
+if [ -f /usr/sbin/psrinfo ]; then
+ p_count=`psrinfo|wc -l`
+ p_mhz=`psrinfo -v | awk '/operates/{print $6 "MHz"; exit }'`
+ p_type=`psrinfo -vp 2>/dev/null | awk '{if (NR == 3) {print $0; exit}}'`
+fi
+
+if [ -f /proc/cpuinfo ]; then
+ p_count=`egrep processor /proc/cpuinfo | wc -l`
+ p_mhz=`awk -F: '/cpu MHz/{printf("%5.0f00Mhz\n",$2/100); exit}' /proc/cpuinfo`
+ p_type=`awk -F: '/model name/{print $2; exit}' /proc/cpuinfo`
+fi
+
+printf "!Libmicro_#: %30s\n" $libmicro_version
+printf "!Options: %30s\n" "$OPTS"
+printf "!Machine_name: %30s\n" $hostname
+printf "!OS_name: %30s\n" `uname -s`
+printf "!OS_release: %30s\n" `uname -r`
+printf "!OS_build: %30.18s\n" "`uname -v`"
+printf "!Processor: %30s\n" `uname -m`
+printf "!#CPUs: %30s\n" $p_count
+printf "!CPU_MHz: %30s\n" $p_mhz
+printf "!CPU_NAME: %30s\n" "$p_type"
+printf "!IP_address: %30s\n" `getent hosts $hostname | awk '{print $1}'`
+printf "!Run_by: %30s\n" $LOGNAME
+printf "!Date: %30s\n" "`date '+%D %R'`"
+printf "!Compiler: %30s\n" `bin/tattle -c`
+printf "!Compiler Ver.:%30s\n" "`bin/tattle -v`"
+printf "!sizeof(long): %30s\n" `bin/tattle -s`
+printf "!extra_CFLAGS: %30s\n" "`bin/tattle -f`"
+printf "!TimerRes: %30s\n" "`bin/tattle -r`"
+
+mkdir -p $TMPROOT/bin
+cp bin-$ARCH/exec_bin $TMPROOT/bin/$A
+
+while read A B
+do
+ # $A contains the command, $B contains the arguments
+ # we echo blank lines and comments
+ # we ship anything which fails to match *$1* (useful
+ # if we only want to test one case, but a nasty hack)
+
+ case $A in
+ ""|"#"*)
+ echo "$A $B"
+ continue
+ ;;
+ *$1*)
+ ;;
+ *)
+ continue
+ esac
+
+ if [ ! -f $TMPROOT/bin/$A ]
+ then
+ cp bin-$ARCH/$A $TMPROOT/bin/$A
+ fi
+ (cd $TMPROOT && eval "bin/$A $B")
+done <<.
+#
+# Obligatory null system call: use very short time
+# for default since SuSe implements this "syscall" in userland
+#
+getpid $OPTS -N "getpid" -I 5
+
+getenv $OPTS -N "getenv" -s 100 -I 100
+getenv $OPTS -N "getenvT2" -s 100 -I 100 -T 2
+
+gettimeofday $OPTS -N "gettimeofday"
+
+log $OPTS -N "log" -I 20
+exp $OPTS -N "exp" -I 20
+lrand48 $OPTS -N "lrand48"
+
+memset $OPTS -N "memset_10" -s 10 -I 10
+memset $OPTS -N "memset_256" -s 256 -I 20
+memset $OPTS -N "memset_256_u" -s 256 -a 1 -I 20
+memset $OPTS -N "memset_1k" -s 1k -I 100
+memset $OPTS -N "memset_4k" -s 4k -I 250
+memset $OPTS -N "memset_4k_uc" -s 4k -u -I 400
+
+memset $OPTS -N "memset_10k" -s 10k -I 600
+memset $OPTS -N "memset_1m" -s 1m -I 200000
+memset $OPTS -N "memset_10m" -s 10m -I 2000000
+memset $OPTS -N "memsetP2_10m" -s 10m -P 2 -I 2000000
+
+memrand $OPTS -N "memrand" -s 128m -B 10000
+cachetocache $OPTS -N "cachetocache" -s 100k -T 2 -I 200
+
+isatty $OPTS -N "isatty_yes"
+isatty $OPTS -N "isatty_no" -f $IFILE
+
+malloc $OPTS -N "malloc_10" -s 10 -g 10 -I 50
+malloc $OPTS -N "malloc_100" -s 100 -g 10 -I 50
+malloc $OPTS -N "malloc_1k" -s 1k -g 10 -I 50
+malloc $OPTS -N "malloc_10k" -s 10k -g 10 -I 50
+malloc $OPTS -N "malloc_100k" -s 100k -g 10 -I 2000
+
+malloc $OPTS -N "mallocT2_10" -s 10 -g 10 -T 2 -I 200
+malloc $OPTS -N "mallocT2_100" -s 100 -g 10 -T 2 -I 200
+malloc $OPTS -N "mallocT2_1k" -s 1k -g 10 -T 2 -I 200
+malloc $OPTS -N "mallocT2_10k" -s 10k -g 10 -T 2 -I 200
+malloc $OPTS -N "mallocT2_100k" -s 100k -g 10 -T 2 -I 10000
+
+close $OPTS -N "close_bad" -B 32 -b
+close $OPTS -N "close_tmp" -B 32 -f $TFILE
+close $OPTS -N "close_usr" -B 32 -f $VFILE
+close $OPTS -N "close_zero" -B 32 -f /dev/zero
+
+memcpy $OPTS -N "memcpy_10" -s 10 -I 10
+memcpy $OPTS -N "memcpy_1k" -s 1k -I 50
+memcpy $OPTS -N "memcpy_10k" -s 10k -I 800
+memcpy $OPTS -N "memcpy_1m" -s 1m -I 500000
+memcpy $OPTS -N "memcpy_10m" -s 10m -I 5000000
+
+strcpy $OPTS -N "strcpy_10" -s 10 -I 5
+strcpy $OPTS -N "strcpy_1k" -s 1k -I 100
+
+strlen $OPTS -N "strlen_10" -s 10 -I 5
+strlen $OPTS -N "strlen_1k" -s 1k -I 100
+
+strchr $OPTS -N "strchr_10" -s 10 -I 5
+strchr $OPTS -N "strchr_1k" -s 1k -I 200
+strcmp $OPTS -N "strcmp_10" -s 10 -I 10
+strcmp $OPTS -N "strcmp_1k" -s 1k -I 200
+
+strcasecmp $OPTS -N "scasecmp_10" -s 10 -I 50
+strcasecmp $OPTS -N "scasecmp_1k" -s 1k -I 20000
+
+strtol $OPTS -N "strtol" -I 20
+
+getcontext $OPTS -N "getcontext" -I 100
+setcontext $OPTS -N "setcontext" -I 100
+
+mutex $OPTS -N "mutex_st" -I 10
+mutex $OPTS -N "mutex_mt" -t -I 10
+mutex $OPTS -N "mutex_T2" -T 2 -I 100
+
+longjmp $OPTS -N "longjmp" -I 10
+siglongjmp $OPTS -N "siglongjmp" -I 20
+
+getrusage $OPTS -N "getrusage" -I 200
+
+times $OPTS -N "times" -I 200
+time $OPTS -N "time" -I 50
+localtime_r $OPTS -N "localtime_r" -I 200
+strftime $OPTS -N "strftime" -I 10000
+
+mktime $OPTS -N "mktime" -I 500
+mktime $OPTS -N "mktimeT2" -T 2 -I 1000
+
+cascade_mutex $OPTS -N "c_mutex_1" -I 50
+cascade_mutex $OPTS -N "c_mutex_10" -T 10 -I 5000
+cascade_mutex $OPTS -N "c_mutex_200" -T 200 -I 2000000
+
+cascade_cond $OPTS -N "c_cond_1" -I 100
+cascade_cond $OPTS -N "c_cond_10" -T 10 -I 3000
+cascade_cond $OPTS -N "c_cond_200" -T 200 -I 2000000
+
+cascade_lockf $OPTS -N "c_lockf_1" -I 1000
+cascade_lockf $OPTS -N "c_lockf_10" -P 10 -I 50000
+cascade_lockf $OPTS -N "c_lockf_200" -P 200 -I 5000000
+
+cascade_flock $OPTS -N "c_flock" -I 1000
+cascade_flock $OPTS -N "c_flock_10" -P 10 -I 50000
+cascade_flock $OPTS -N "c_flock_200" -P 200 -I 5000000
+
+cascade_fcntl $OPTS -N "c_fcntl_1" -I 2000
+cascade_fcntl $OPTS -N "c_fcntl_10" -P 10 -I 20000
+cascade_fcntl $OPTS -N "c_fcntl_200" -P 200 -I 5000000
+
+file_lock $OPTS -N "file_lock" -I 1000
+
+getsockname $OPTS -N "getsockname" -I 100
+getpeername $OPTS -N "getpeername" -I 100
+
+chdir $OPTS -N "chdir_tmp" -I 2000 $TDIR1 $TDIR2
+chdir $OPTS -N "chdir_usr" -I 2000 $VDIR1 $VDIR2
+
+chdir $OPTS -N "chgetwd_tmp" -I 3000 -g $TDIR1 $TDIR2
+chdir $OPTS -N "chgetwd_usr" -I 3000 -g $VDIR1 $VDIR2
+
+realpath $OPTS -N "realpath_tmp" -I 3000 -f $TDIR1
+realpath $OPTS -N "realpath_usr" -I 3000 -f $VDIR1
+
+stat $OPTS -N "stat_tmp" -I 1000 -f $TFILE
+stat $OPTS -N "stat_usr" -I 1000 -f $VFILE
+
+fcntl $OPTS -N "fcntl_tmp" -I 100 -f $TFILE
+fcntl $OPTS -N "fcntl_usr" -I 100 -f $VFILE
+fcntl_ndelay $OPTS -N "fcntl_ndelay" -I 100
+
+lseek $OPTS -N "lseek_t8k" -s 8k -I 50 -f $TFILE
+lseek $OPTS -N "lseek_u8k" -s 8k -I 50 -f $VFILE
+
+open $OPTS -N "open_tmp" -B 256 -f $TFILE
+open $OPTS -N "open_usr" -B 256 -f $VFILE
+open $OPTS -N "open_zero" -B 256 -f /dev/zero
+
+dup $OPTS -N "dup" -B 512
+
+socket $OPTS -N "socket_u" -B 256
+socket $OPTS -N "socket_i" -B 256 -f PF_INET
+
+socketpair $OPTS -N "socketpair" -B 256
+
+setsockopt $OPTS -N "setsockopt" -I 200
+
+bind $OPTS -N "bind" -B 100
+
+listen $OPTS -N "listen" -B 100
+
+connection $OPTS -N "connection" -B 256
+
+poll $OPTS -N "poll_10" -n 10 -I 500
+poll $OPTS -N "poll_100" -n 100 -I 1000
+poll $OPTS -N "poll_1000" -n 1000 -I 5000
+
+poll $OPTS -N "poll_w10" -n 10 -I 500 -w 1
+poll $OPTS -N "poll_w100" -n 100 -I 2000 -w 10
+poll $OPTS -N "poll_w1000" -n 1000 -I 40000 -w 100
+
+select $OPTS -N "select_10" -n 10 -I 500
+select $OPTS -N "select_100" -n 100 -I 1000
+select $OPTS -N "select_1000" -n 1000 -I 5000
+
+select $OPTS -N "select_w10" -n 10 -I 500 -w 1
+select $OPTS -N "select_w100" -n 100 -I 2000 -w 10
+select $OPTS -N "select_w1000" -n 1000 -I 40000 -w 100
+
+semop $OPTS -N "semop" -I 200
+
+sigaction $OPTS -N "sigaction" -I 100
+signal $OPTS -N "signal" -I 1000
+sigprocmask $OPTS -N "sigprocmask" -I 200
+
+pthread_create $OPTS -N "pthread_8" -B 8
+pthread_create $OPTS -N "pthread_32" -B 32
+pthread_create $OPTS -N "pthread_128" -B 128
+pthread_create $OPTS -N "pthread_512" -B 512
+
+fork $OPTS -N "fork_10" -B 10
+fork $OPTS -N "fork_100" -B 100 -C 100
+fork $OPTS -N "fork_1000" -B 1000 -C 50
+
+exit $OPTS -N "exit_10" -B 10
+exit $OPTS -N "exit_100" -B 100
+exit $OPTS -N "exit_1000" -B 1000 -C 50
+
+exit $OPTS -N "exit_10_nolibc" -e -B 10
+
+exec $OPTS -N "exec" -B 10
+
+system $OPTS -N "system" -I 1000000
+
+recurse $OPTS -N "recurse" -B 512
+
+read $OPTS -N "read_t1k" -s 1k -f $TFILE
+read $OPTS -N "read_t10k" -s 10k -f $TFILE
+read $OPTS -N "read_t100k" -s 100k -f $TFILE
+
+read $OPTS -N "read_u1k" -s 1k -f $VFILE
+read $OPTS -N "read_u10k" -s 10k -f $VFILE
+read $OPTS -N "read_u100k" -s 100k -f $VFILE
+
+read $OPTS -N "read_z1k" -s 1k -f /dev/zero
+read $OPTS -N "read_z10k" -s 10k -f /dev/zero
+read $OPTS -N "read_z100k" -s 100k -f /dev/zero
+read $OPTS -N "read_zw100k" -s 100k -w -f /dev/zero
+
+write $OPTS -N "write_t1k" -s 1k -f $TFILE
+write $OPTS -N "write_t10k" -s 10k -f $TFILE
+write $OPTS -N "write_t100k" -s 100k -f $TFILE
+
+write $OPTS -N "write_u1k" -s 1k -f $VFILE
+write $OPTS -N "write_u10k" -s 10k -f $VFILE
+write $OPTS -N "write_u100k" -s 100k -f $VFILE
+
+write $OPTS -N "write_n1k" -s 1k -I 100 -B 0 -f /dev/null
+write $OPTS -N "write_n10k" -s 10k -I 100 -B 0 -f /dev/null
+write $OPTS -N "write_n100k" -s 100k -I 100 -B 0 -f /dev/null
+
+writev $OPTS -N "writev_t1k" -s 1k -f $TFILE
+writev $OPTS -N "writev_t10k" -s 10k -f $TFILE
+writev $OPTS -N "writev_t100k" -s 100k -f $TFILE
+
+writev $OPTS -N "writev_u1k" -s 1k -f $VFILE
+writev $OPTS -N "writev_u10k" -s 10k -f $VFILE
+writev $OPTS -N "writev_u100k" -s 100k -f $VFILE
+
+writev $OPTS -N "writev_n1k" -s 1k -I 100 -B 0 -f /dev/null
+writev $OPTS -N "writev_n10k" -s 10k -I 100 -B 0 -f /dev/null
+writev $OPTS -N "writev_n100k" -s 100k -I 100 -B 0 -f /dev/null
+
+pread $OPTS -N "pread_t1k" -s 1k -I 300 -f $TFILE
+pread $OPTS -N "pread_t10k" -s 10k -I 1000 -f $TFILE
+pread $OPTS -N "pread_t100k" -s 100k -I 10000 -f $TFILE
+
+pread $OPTS -N "pread_u1k" -s 1k -I 300 -f $VFILE
+pread $OPTS -N "pread_u10k" -s 10k -I 1000 -f $VFILE
+pread $OPTS -N "pread_u100k" -s 100k -I 10000 -f $VFILE
+
+pread $OPTS -N "pread_z1k" -s 1k -I 300 -f /dev/zero
+pread $OPTS -N "pread_z10k" -s 10k -I 1000 -f /dev/zero
+pread $OPTS -N "pread_z100k" -s 100k -I 2000 -f /dev/zero
+pread $OPTS -N "pread_zw100k" -s 100k -w -I 10000 -f /dev/zero
+
+pwrite $OPTS -N "pwrite_t1k" -s 1k -I 500 -f $TFILE
+pwrite $OPTS -N "pwrite_t10k" -s 10k -I 1000 -f $TFILE
+pwrite $OPTS -N "pwrite_t100k" -s 100k -I 10000 -f $TFILE
+
+pwrite $OPTS -N "pwrite_u1k" -s 1k -I 500 -f $VFILE
+pwrite $OPTS -N "pwrite_u10k" -s 10k -I 1000 -f $VFILE
+pwrite $OPTS -N "pwrite_u100k" -s 100k -I 20000 -f $VFILE
+
+pwrite $OPTS -N "pwrite_n1k" -s 1k -I 100 -f /dev/null
+pwrite $OPTS -N "pwrite_n10k" -s 10k -I 100 -f /dev/null
+pwrite $OPTS -N "pwrite_n100k" -s 100k -I 100 -f /dev/null
+
+mmap $OPTS -N "mmap_z8k" -l 8k -I 1000 -f /dev/zero
+mmap $OPTS -N "mmap_z128k" -l 128k -I 2000 -f /dev/zero
+mmap $OPTS -N "mmap_t8k" -l 8k -I 1000 -f $TFILE
+mmap $OPTS -N "mmap_t128k" -l 128k -I 1000 -f $TFILE
+mmap $OPTS -N "mmap_u8k" -l 8k -I 1000 -f $VFILE
+mmap $OPTS -N "mmap_u128k" -l 128k -I 1000 -f $VFILE
+mmap $OPTS -N "mmap_a8k" -l 8k -I 200 -f MAP_ANON
+mmap $OPTS -N "mmap_a128k" -l 128k -I 200 -f MAP_ANON
+
+
+mmap $OPTS -N "mmap_rz8k" -l 8k -I 2000 -r -f /dev/zero
+mmap $OPTS -N "mmap_rz128k" -l 128k -I 2000 -r -f /dev/zero
+mmap $OPTS -N "mmap_rt8k" -l 8k -I 2000 -r -f $TFILE
+mmap $OPTS -N "mmap_rt128k" -l 128k -I 20000 -r -f $TFILE
+mmap $OPTS -N "mmap_ru8k" -l 8k -I 2000 -r -f $VFILE
+mmap $OPTS -N "mmap_ru128k" -l 128k -I 20000 -r -f $VFILE
+mmap $OPTS -N "mmap_ra8k" -l 8k -I 2000 -r -f MAP_ANON
+mmap $OPTS -N "mmap_ra128k" -l 128k -I 20000 -r -f MAP_ANON
+
+mmap $OPTS -N "mmap_wz8k" -l 8k -I 5000 -w -f /dev/zero
+mmap $OPTS -N "mmap_wz128k" -l 128k -I 50000 -w -f /dev/zero
+mmap $OPTS -N "mmap_wt8k" -l 8k -I 5000 -w -f $TFILE
+mmap $OPTS -N "mmap_wt128k" -l 128k -I 50000 -w -f $TFILE
+mmap $OPTS -N "mmap_wu8k" -l 8k -I 5000 -w -f $VFILE
+mmap $OPTS -N "mmap_wu128k" -l 128k -I 500000 -w -f $VFILE
+mmap $OPTS -N "mmap_wa8k" -l 8k -I 3000 -w -f MAP_ANON
+mmap $OPTS -N "mmap_wa128k" -l 128k -I 50000 -w -f MAP_ANON
+
+munmap $OPTS -N "unmap_z8k" -l 8k -I 500 -f /dev/zero
+munmap $OPTS -N "unmap_z128k" -l 128k -I 500 -f /dev/zero
+munmap $OPTS -N "unmap_t8k" -l 8k -I 500 -f $TFILE
+munmap $OPTS -N "unmap_t128k" -l 128k -I 500 -f $TFILE
+munmap $OPTS -N "unmap_u8k" -l 8k -I 500 -f $VFILE
+munmap $OPTS -N "unmap_u128k" -l 128k -I 500 -f $VFILE
+munmap $OPTS -N "unmap_a8k" -l 8k -I 500 -f MAP_ANON
+munmap $OPTS -N "unmap_a128k" -l 128k -I 500 -f MAP_ANON
+
+munmap $OPTS -N "unmap_rz8k" -l 8k -I 1000 -r -f /dev/zero
+munmap $OPTS -N "unmap_rz128k" -l 128k -I 2000 -r -f /dev/zero
+munmap $OPTS -N "unmap_rt8k" -l 8k -I 1000 -r -f $TFILE
+munmap $OPTS -N "unmap_rt128k" -l 128k -I 3000 -r -f $TFILE
+munmap $OPTS -N "unmap_ru8k" -l 8k -I 1000 -r -f $VFILE
+munmap $OPTS -N "unmap_ru128k" -l 128k -I 3000 -r -f $VFILE
+munmap $OPTS -N "unmap_ra8k" -l 8k -I 1000 -r -f MAP_ANON
+munmap $OPTS -N "unmap_ra128k" -l 128k -I 2000 -r -f MAP_ANON
+
+connection $OPTS -N "conn_connect" -B 256 -c
+
+munmap $OPTS -N "unmap_wz8k" -l 8k -I 1000 -w -f /dev/zero
+munmap $OPTS -N "unmap_wz128k" -l 128k -I 8000 -w -f /dev/zero
+munmap $OPTS -N "unmap_wt8k" -l 8k -I 1000 -w -f $TFILE
+munmap $OPTS -N "unmap_wt128k" -l 128k -I 10000 -w -f $TFILE
+munmap $OPTS -N "unmap_wu8k" -l 8k -I 1000 -w -f $VFILE
+munmap $OPTS -N "unmap_wu128k" -l 128k -I 50000 -w -f $VFILE
+munmap $OPTS -N "unmap_wa8k" -l 8k -I 1000 -w -f MAP_ANON
+munmap $OPTS -N "unmap_wa128k" -l 128k -I 10000 -w -f MAP_ANON
+
+
+mprotect $OPTS -N "mprot_z8k" -l 8k -I 300 -f /dev/zero
+mprotect $OPTS -N "mprot_z128k" -l 128k -I 500 -f /dev/zero
+mprotect $OPTS -N "mprot_wz8k" -l 8k -I 500 -w -f /dev/zero
+mprotect $OPTS -N "mprot_wz128k" -l 128k -I 1000 -w -f /dev/zero
+mprotect $OPTS -N "mprot_twz8k" -l 8k -I 1000 -w -t -f /dev/zero
+mprotect $OPTS -N "mprot_tw128k" -l 128k -I 2000 -w -t -f /dev/zero
+mprotect $OPTS -N "mprot_tw4m" -l 4m -w -t -B 1 -f /dev/zero
+
+pipe $OPTS -N "pipe_pst1" -s 1 -I 1000 -x pipe -m st
+pipe $OPTS -N "pipe_pmt1" -s 1 -I 8000 -x pipe -m mt
+pipe $OPTS -N "pipe_pmp1" -s 1 -I 8000 -x pipe -m mp
+pipe $OPTS -N "pipe_pst4k" -s 4k -I 1000 -x pipe -m st
+pipe $OPTS -N "pipe_pmt4k" -s 4k -I 8000 -x pipe -m mt
+pipe $OPTS -N "pipe_pmp4k" -s 4k -I 8000 -x pipe -m mp
+
+pipe $OPTS -N "pipe_sst1" -s 1 -I 1000 -x sock -m st
+pipe $OPTS -N "pipe_smt1" -s 1 -I 8000 -x sock -m mt
+pipe $OPTS -N "pipe_smp1" -s 1 -I 8000 -x sock -m mp
+pipe $OPTS -N "pipe_sst4k" -s 4k -I 1000 -x sock -m st
+pipe $OPTS -N "pipe_smt4k" -s 4k -I 8000 -x sock -m mt
+pipe $OPTS -N "pipe_smp4k" -s 4k -I 8000 -x sock -m mp
+
+pipe $OPTS -N "pipe_tst1" -s 1 -I 1000 -x tcp -m st
+pipe $OPTS -N "pipe_tmt1" -s 1 -I 8000 -x tcp -m mt
+pipe $OPTS -N "pipe_tmp1" -s 1 -I 8000 -x tcp -m mp
+pipe $OPTS -N "pipe_tst4k" -s 4k -I 1000 -x tcp -m st
+pipe $OPTS -N "pipe_tmt4k" -s 4k -I 8000 -x tcp -m mt
+pipe $OPTS -N "pipe_tmp4k" -s 4k -I 8000 -x tcp -m mp
+
+connection $OPTS -N "conn_accept" -B 256 -a
+
+close_tcp $OPTS -N "close_tcp" -B 32
+.
diff --git a/native/libMicro-0.4.0/benchmark_fini.c b/native/libMicro-0.4.0/benchmark_fini.c
new file mode 100644
index 0000000..4952a9a
--- /dev/null
+++ b/native/libMicro-0.4.0/benchmark_fini.c
@@ -0,0 +1,46 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * default implementation (nop) of benchmark_fini
+ */
+
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+int
+benchmark_fini()
+{
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/benchmark_finibatch.c b/native/libMicro-0.4.0/benchmark_finibatch.c
new file mode 100644
index 0000000..482258c
--- /dev/null
+++ b/native/libMicro-0.4.0/benchmark_finibatch.c
@@ -0,0 +1,46 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * default implementation (nop) of benchmark_finibatch
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+/*ARGSUSED*/
+int
+benchmark_finibatch(void *tsd)
+{
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/benchmark_finirun.c b/native/libMicro-0.4.0/benchmark_finirun.c
new file mode 100644
index 0000000..52a5822
--- /dev/null
+++ b/native/libMicro-0.4.0/benchmark_finirun.c
@@ -0,0 +1,45 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * default implementation (nop) of benchmark_finirun
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+int
+benchmark_finirun()
+{
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/benchmark_finiworker.c b/native/libMicro-0.4.0/benchmark_finiworker.c
new file mode 100644
index 0000000..53161ea
--- /dev/null
+++ b/native/libMicro-0.4.0/benchmark_finiworker.c
@@ -0,0 +1,46 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * default implementation (nop) of benchmark_finiworker
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+/*ARGSUSED*/
+int
+benchmark_finiworker(void *tsd)
+{
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/benchmark_init.c b/native/libMicro-0.4.0/benchmark_init.c
new file mode 100644
index 0000000..83cec2b
--- /dev/null
+++ b/native/libMicro-0.4.0/benchmark_init.c
@@ -0,0 +1,46 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * default implementation (nop) of benchmark_init
+ */
+
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/benchmark_initbatch.c b/native/libMicro-0.4.0/benchmark_initbatch.c
new file mode 100644
index 0000000..0a8cddd
--- /dev/null
+++ b/native/libMicro-0.4.0/benchmark_initbatch.c
@@ -0,0 +1,47 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * default implementation (nop) of benchmark_initbatch
+ */
+
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+/*ARGSUSED*/
+int
+benchmark_initbatch(void *tsd)
+{
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/benchmark_initrun.c b/native/libMicro-0.4.0/benchmark_initrun.c
new file mode 100644
index 0000000..ac437d4
--- /dev/null
+++ b/native/libMicro-0.4.0/benchmark_initrun.c
@@ -0,0 +1,45 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * default implementation (nop) of benchmark_initrun
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+int
+benchmark_initrun()
+{
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/benchmark_initworker.c b/native/libMicro-0.4.0/benchmark_initworker.c
new file mode 100644
index 0000000..29b487c
--- /dev/null
+++ b/native/libMicro-0.4.0/benchmark_initworker.c
@@ -0,0 +1,46 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * default implementation (nop) of benchmark_initworker
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+/*ARGSUSED*/
+int
+benchmark_initworker(void *tsd)
+{
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/benchmark_optswitch.c b/native/libMicro-0.4.0/benchmark_optswitch.c
new file mode 100644
index 0000000..d46ee2f
--- /dev/null
+++ b/native/libMicro-0.4.0/benchmark_optswitch.c
@@ -0,0 +1,46 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * default implementation (nop) of benchmark_optswitch
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+/*ARGSUSED*/
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/benchmark_result.c b/native/libMicro-0.4.0/benchmark_result.c
new file mode 100644
index 0000000..c8ab2f2
--- /dev/null
+++ b/native/libMicro-0.4.0/benchmark_result.c
@@ -0,0 +1,47 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * default implementation (nop) of benchmark_result
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+char *
+benchmark_result()
+{
+ static char result = '\0';
+
+ return (&result);
+}
diff --git a/native/libMicro-0.4.0/bind.c b/native/libMicro-0.4.0/bind.c
new file mode 100644
index 0000000..bd8e43b
--- /dev/null
+++ b/native/libMicro-0.4.0/bind.c
@@ -0,0 +1,163 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * benchmark for bind... keep in mind tcp hash chain effects
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "libmicro.h"
+
+#define FIRSTPORT 12345
+
+typedef struct {
+ int *ts_lsns;
+ struct sockaddr_in *ts_adds;
+} tsd_t;
+
+static int optz = -0;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ lm_defB = 256;
+ (void) sprintf(lm_optstr, "z");
+
+ (void) sprintf(lm_usage,
+ " [-z bind to port 0 rather than seq. number\n"
+ "notes: measures bind() on TCP");
+
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ (void) setfdlimit(lm_optB * lm_optT + 10);
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'z':
+ optz = 1;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i, j;
+ int opt = 1;
+ struct hostent *host;
+ int errors = 0;
+
+ ts->ts_lsns = (int *)malloc(lm_optB * sizeof (int));
+ if (ts->ts_lsns == NULL)
+ errors ++;
+
+ ts->ts_adds = (struct sockaddr_in *)malloc(lm_optB *
+ sizeof (struct sockaddr_in));
+ if (ts->ts_adds == NULL)
+ errors ++;
+
+ j = FIRSTPORT;
+ for (i = 0; i < lm_optB; i++) {
+ if ((ts->ts_lsns[i] = socket(PF_INET, SOCK_STREAM, 0)) == -1)
+ errors ++;
+
+ if (setsockopt(ts->ts_lsns[i], SOL_SOCKET, SO_REUSEADDR,
+ &opt, sizeof (int)) == -1)
+ errors ++;
+
+ if ((host = gethostbyname("localhost")) == NULL)
+ errors ++;
+
+ (void) memset(&ts->ts_adds[i], 0,
+ sizeof (struct sockaddr_in));
+ ts->ts_adds[i].sin_family = AF_INET;
+ ts->ts_adds[i].sin_port = (optz ? 0 : htons(j++));
+ (void) memcpy(&ts->ts_adds[i].sin_addr.s_addr,
+ host->h_addr_list[0], sizeof (struct in_addr));
+ }
+ return (errors);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ if ((bind(ts->ts_lsns[i],
+ (struct sockaddr *)&ts->ts_adds[i],
+ sizeof (struct sockaddr_in)) != 0) &&
+ (errno != EADDRINUSE))
+ res->re_errors ++;
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+int
+benchmark_finibatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++)
+ (void) close(ts->ts_lsns[i]);
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/cachetocache.c b/native/libMicro-0.4.0/cachetocache.c
new file mode 100644
index 0000000..ffe9ddf
--- /dev/null
+++ b/native/libMicro-0.4.0/cachetocache.c
@@ -0,0 +1,222 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * routine to benchmark cache-to-cache transfer times... uses
+ * solaris features to find and bind to cpus in the current
+ * processor set, so not likely to work elsewhere.
+ */
+
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/processor.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/pset.h>
+
+#include "libmicro.h"
+
+static long opts = 1024*512;
+
+typedef struct {
+ long **ts_data;
+ long ts_result;
+ pthread_mutex_t ts_lock;
+} tsd_t;
+
+static unsigned int ncpu = 1024;
+
+static tsd_t *thread_data[1024];
+static processorid_t cpus[1024];
+
+int traverse_ptrchain(long **, int, int);
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "s:");
+
+ (void) sprintf(lm_usage,
+ " [-s size] size of access area in bytes"
+ " (default %ld)\n"
+ "notes: measures cache to cache transfer times on Solaris\n",
+ opts);
+
+ (void) sprintf(lm_header, "%8s", "size");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 's':
+ opts = sizetoint(optarg);
+ break;
+ default:
+ return (-1);
+ }
+
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ if (pset_info(PS_MYID, NULL, &ncpu, cpus) < 0) {
+ perror("pset_info");
+ return (1);
+ }
+
+ return (0);
+}
+
+int
+benchmark_initworker(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i, j;
+ processorid_t cpu;
+
+ ts->ts_data = malloc(opts);
+
+ if (ts->ts_data == NULL) {
+ return (1);
+ }
+
+ (void) pthread_mutex_init(&ts->ts_lock, NULL);
+
+
+ if (processor_bind(P_LWPID, P_MYID,
+ cpu = cpus[(pthread_self() - 1) % ncpu],
+ NULL) < 0) {
+ perror("processor_bind:");
+ return (1);
+ }
+
+ (void) printf("# thread %d using processor %d\n", pthread_self(), cpu);
+
+ /*
+ * use lmbench style backwards stride
+ */
+
+ for (i = 0; i < opts / sizeof (long); i++) {
+ j = i - 128;
+ if (j < 0)
+ j = j + opts / sizeof (long);
+ ts->ts_data[i] = (long *)&(ts->ts_data[j]);
+ }
+
+ thread_data[pthread_self() - 1] = ts;
+
+ return (0);
+}
+
+/*
+ * here we go in order for each thread, causing inherent serialization
+ * this is normally not a good idea, but in this case we're trying to
+ * measure cache-to-cache transfer times, and if we run threads in
+ * parallel we're likely to see saturation effects rather than cache-to-cache,
+ * esp. on wimpy memory platforms like P4.
+ */
+
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts;
+ int i, j;
+ int count = opts / 128 / sizeof (long);
+
+ for (j = 0; j < lm_optB; j++)
+ for (i = 0; i < lm_optT; i++) {
+ ts = thread_data[i];
+ (void) pthread_mutex_lock(&ts->ts_lock);
+ ts->ts_result += traverse_ptrchain(
+ (long **)ts->ts_data, count, 0);
+ (void) pthread_mutex_unlock(&ts->ts_lock);
+ }
+
+ res->re_count = lm_optB * lm_optT * count;
+
+ return (0);
+}
+
+int
+traverse_ptrchain(long **ptr, int count, int value)
+{
+ int i;
+
+ for (i = 0; i < count; i += 10) {
+ *ptr = *ptr + value;
+ ptr = (long **)*ptr;
+ *ptr = *ptr + value;
+ ptr = (long **)*ptr;
+ *ptr = *ptr + value;
+ ptr = (long **)*ptr;
+ *ptr = *ptr + value;
+ ptr = (long **)*ptr;
+ *ptr = *ptr + value;
+ ptr = (long **)*ptr;
+ *ptr = *ptr + value;
+ ptr = (long **)*ptr;
+ *ptr = *ptr + value;
+ ptr = (long **)*ptr;
+ *ptr = *ptr + value;
+ ptr = (long **)*ptr;
+ *ptr = *ptr + value;
+ ptr = (long **)*ptr;
+ *ptr = *ptr + value;
+ ptr = (long **)*ptr;
+ *ptr = *ptr + value;
+ }
+ return ((int)*ptr); /* bogus return */
+}
+
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%8ld ", opts);
+
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/cascade_cond.c b/native/libMicro-0.4.0/cascade_cond.c
new file mode 100644
index 0000000..bf22110
--- /dev/null
+++ b/native/libMicro-0.4.0/cascade_cond.c
@@ -0,0 +1,278 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * The "cascade" test case is a multiprocess/multithread batten-passing model
+ * using lock primitives alone for synchronisation. Threads are arranged in a
+ * ring. Each thread has two locks of its own on which it blocks, and is able
+ * to manipulate the two locks belonging to the thread which follows it in the
+ * ring.
+ *
+ * The number of threads (nthreads) is specified by the generic libMicro -P/-T
+ * options. With nthreads == 1 (the default) the uncontended case can be timed.
+ *
+ * The main logic is generic and allows any simple blocking API to be tested.
+ * The API-specific component is clearly indicated.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <sys/mman.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ int ts_once;
+ int ts_id;
+ int ts_us0; /* our lock indices */
+ int ts_us1;
+ int ts_them0; /* their lock indices */
+ int ts_them1;
+} tsd_t;
+
+static int nthreads;
+
+/*
+ * API-specific code BEGINS here
+ */
+
+static int opto = 0;
+static int opts = 0;
+static int nlocks;
+static pthread_mutex_t *mxs;
+static pthread_cond_t *cvs;
+static int *conds;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "os");
+
+ lm_defN = "cscd_cond";
+
+ (void) sprintf(lm_usage,
+ " [-o] (do signal outside mutex)\n"
+ " [-s] (force PTHREAD_PROCESS_SHARED)\n"
+ "notes: thread cascade using pthread_conds\n");
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'o':
+ opto = 1;
+ break;
+ case 's':
+ opts = 1;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ int i;
+ int e = 0;
+ pthread_mutexattr_t ma;
+ pthread_condattr_t ca;
+
+ nthreads = lm_optP * lm_optT;
+ nlocks = nthreads * 2;
+ /*LINTED*/
+ mxs = (pthread_mutex_t *)mmap(NULL,
+ nlocks * sizeof (pthread_mutex_t),
+ PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_SHARED,
+ -1, 0L);
+ if (mxs == MAP_FAILED) {
+ return (1);
+ }
+
+ /*LINTED*/
+ cvs = (pthread_cond_t *)mmap(NULL,
+ nlocks * sizeof (pthread_cond_t),
+ PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_SHARED,
+ -1, 0L);
+ if (cvs == MAP_FAILED) {
+ return (1);
+ }
+
+ /*LINTED*/
+ conds = (int *)mmap(NULL,
+ nlocks * sizeof (pthread_cond_t),
+ PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_SHARED,
+ -1, 0L);
+ if (conds == MAP_FAILED) {
+ return (1);
+ }
+
+ (void) pthread_mutexattr_init(&ma);
+ (void) pthread_condattr_init(&ca);
+ if (lm_optP > 1 || opts) {
+ (void) pthread_mutexattr_setpshared(&ma,
+ PTHREAD_PROCESS_SHARED);
+ (void) pthread_condattr_setpshared(&ca,
+ PTHREAD_PROCESS_SHARED);
+ } else {
+ (void) pthread_mutexattr_setpshared(&ma,
+ PTHREAD_PROCESS_PRIVATE);
+ (void) pthread_condattr_setpshared(&ca,
+ PTHREAD_PROCESS_PRIVATE);
+ }
+
+ for (i = 0; i < nlocks; i++) {
+ (void) pthread_mutex_init(&mxs[i], &ma);
+ (void) pthread_cond_init(&cvs[i], &ca);
+ conds[i] = 0;
+ }
+
+ return (e);
+}
+
+int
+block(int index)
+{
+ (void) pthread_mutex_lock(&mxs[index]);
+ while (conds[index] != 0) {
+ (void) pthread_cond_wait(&cvs[index], &mxs[index]);
+ }
+ conds[index] = 1;
+ (void) pthread_mutex_unlock(&mxs[index]);
+
+ return (0);
+}
+
+int
+unblock(int index)
+{
+ (void) pthread_mutex_lock(&mxs[index]);
+ conds[index] = 0;
+ if (opto) {
+ (void) pthread_mutex_unlock(&mxs[index]);
+ (void) pthread_cond_signal(&cvs[index]);
+ } else {
+ (void) pthread_cond_signal(&cvs[index]);
+ (void) pthread_mutex_unlock(&mxs[index]);
+ }
+ return (0);
+}
+
+/*
+ * API-specific code ENDS here
+ */
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int e = 0;
+
+ if (ts->ts_once == 0) {
+ int us, them;
+
+ us = (getpindex() * lm_optT) + gettindex();
+ them = (us + 1) % (lm_optP * lm_optT);
+
+ ts->ts_id = us;
+
+ /* lock index asignment for us and them */
+ ts->ts_us0 = (us * 2);
+ ts->ts_us1 = (us * 2) + 1;
+ if (us < nthreads - 1) {
+ /* straight-thru connection to them */
+ ts->ts_them0 = (them * 2);
+ ts->ts_them1 = (them * 2) + 1;
+ } else {
+ /* cross-over connection to them */
+ ts->ts_them0 = (them * 2) + 1;
+ ts->ts_them1 = (them * 2);
+ }
+
+ ts->ts_once = 1;
+ }
+
+ /* block their first move */
+ e += block(ts->ts_them0);
+
+ return (e);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int e = 0;
+
+ /* wait to be unblocked (id == 0 will not block) */
+ e += block(ts->ts_us0);
+
+ for (i = 0; i < lm_optB; i += 2) {
+ /* allow them to block us again */
+ e += unblock(ts->ts_us0);
+
+ /* block their next + 1 move */
+ e += block(ts->ts_them1);
+
+ /* unblock their next move */
+ e += unblock(ts->ts_them0);
+
+ /* wait for them to unblock us */
+ e += block(ts->ts_us1);
+
+ /* repeat with locks reversed */
+ e += unblock(ts->ts_us1);
+ e += block(ts->ts_them0);
+ e += unblock(ts->ts_them1);
+ e += block(ts->ts_us0);
+ }
+
+ /* finish batch with nothing blocked */
+ e += unblock(ts->ts_them0);
+ e += unblock(ts->ts_us0);
+
+ res->re_count = i;
+ res->re_errors = e;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/cascade_fcntl.c b/native/libMicro-0.4.0/cascade_fcntl.c
new file mode 100644
index 0000000..5b632c6
--- /dev/null
+++ b/native/libMicro-0.4.0/cascade_fcntl.c
@@ -0,0 +1,232 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * The "cascade" test case is a multiprocess/multithread batten-passing model
+ * using lock primitives alone for synchronisation. Threads are arranged in a
+ * ring. Each thread has two locks of its own on which it blocks, and is able
+ * to manipulate the two locks belonging to the thread which follows it in the
+ * ring.
+ *
+ * The number of threads (nthreads) is specified by the generic libMicro -P/-T
+ * options. With nthreads == 1 (the default) the uncontended case can be timed.
+ *
+ * The main logic is generic and allows any simple blocking API to be tested.
+ * The API-specific component is clearly indicated.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ int ts_once;
+ int ts_id;
+ int ts_us0; /* our lock indices */
+ int ts_us1;
+ int ts_them0; /* their lock indices */
+ int ts_them1;
+} tsd_t;
+
+static int nthreads;
+
+/*
+ * API-specific code BEGINS here
+ */
+
+#define DEFD "/tmp"
+
+static char *optd = DEFD;
+static int file;
+static int nlocks;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "d:");
+
+ lm_defN = "cscd_fcntl";
+
+ (void) sprintf(lm_usage,
+ " [-d directory for temp file (default %s)]\n"
+ "notes: thread cascade using fcntl region locking\n",
+ DEFD);
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'd':
+ optd = optarg;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ int errors = 0;
+ char fname[1024];
+
+ nthreads = lm_optP * lm_optT;
+ nlocks = nthreads * 2;
+
+ (void) sprintf(fname, "%s/cascade.%ld", optd, getpid());
+
+ file = open(fname, O_CREAT | O_TRUNC | O_RDWR, 0600);
+ if (file == -1) {
+ errors++;
+ }
+
+ if (unlink(fname)) {
+ errors++;
+ }
+
+ if (ftruncate(file, nlocks * 3) == -1) {
+ errors++;
+ }
+
+ return (errors);
+}
+
+int
+block(int index)
+{
+ struct flock fl;
+
+ fl.l_type = F_WRLCK;
+ fl.l_whence = SEEK_SET;
+ fl.l_start = index;
+ fl.l_len = 1;
+ return (fcntl(file, F_SETLKW, &fl) == -1);
+}
+
+int
+unblock(int index)
+{
+ struct flock fl;
+
+ fl.l_type = F_UNLCK;
+ fl.l_whence = SEEK_SET;
+ fl.l_start = index;
+ fl.l_len = 1;
+ return (fcntl(file, F_SETLK, &fl) == -1);
+}
+
+/*
+ * API-specific code ENDS here
+ */
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int e = 0;
+
+ if (ts->ts_once == 0) {
+ int us, them;
+
+ us = (getpindex() * lm_optT) + gettindex();
+ them = (us + 1) % (lm_optP * lm_optT);
+
+ ts->ts_id = us;
+
+ /* lock index asignment for us and them */
+ ts->ts_us0 = (us * 4);
+ ts->ts_us1 = (us * 4) + 2;
+ if (us < nthreads - 1) {
+ /* straight-thru connection to them */
+ ts->ts_them0 = (them * 4);
+ ts->ts_them1 = (them * 4) + 2;
+ } else {
+ /* cross-over connection to them */
+ ts->ts_them0 = (them * 4) + 2;
+ ts->ts_them1 = (them * 4);
+ }
+
+ ts->ts_once = 1;
+ }
+
+ /* block their first move */
+ e += block(ts->ts_them0);
+
+ return (e);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int e = 0;
+
+ /* wait to be unblocked (id == 0 will not block) */
+ e += block(ts->ts_us0);
+
+ for (i = 0; i < lm_optB; i += 2) {
+ /* allow them to block us again */
+ e += unblock(ts->ts_us0);
+
+ /* block their next + 1 move */
+ e += block(ts->ts_them1);
+
+ /* unblock their next move */
+ e += unblock(ts->ts_them0);
+
+ /* wait for them to unblock us */
+ e += block(ts->ts_us1);
+
+ /* repeat with locks reversed */
+ e += unblock(ts->ts_us1);
+ e += block(ts->ts_them0);
+ e += unblock(ts->ts_them1);
+ e += block(ts->ts_us0);
+ }
+
+ /* finish batch with nothing blocked */
+ e += unblock(ts->ts_them0);
+ e += unblock(ts->ts_us0);
+
+ res->re_count = i;
+ res->re_errors = e;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/cascade_flock.c b/native/libMicro-0.4.0/cascade_flock.c
new file mode 100644
index 0000000..27d95d1
--- /dev/null
+++ b/native/libMicro-0.4.0/cascade_flock.c
@@ -0,0 +1,228 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * The "cascade" test case is a multiprocess/multithread batten-passing model
+ * using lock primitives alone for synchronisation. Threads are arranged in a
+ * ring. Each thread has two locks of its own on which it blocks, and is able
+ * to manipulate the two locks belonging to the thread which follows it in the
+ * ring.
+ *
+ * The number of threads (nthreads) is specified by the generic libMicro -P/-T
+ * options. With nthreads == 1 (the default) the uncontended case can be timed.
+ *
+ * The main logic is generic and allows any simple blocking API to be tested.
+ * The API-specific component is clearly indicated.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "libmicro.h"
+
+#ifndef LOCK_EX
+#include "/usr/ucbinclude/sys/file.h"
+extern int flock(int fd, int operation);
+#endif
+
+typedef struct {
+ int ts_once;
+ int ts_id;
+ int ts_us0; /* our lock indices */
+ int ts_us1;
+ int ts_them0; /* their lock indices */
+ int ts_them1;
+} tsd_t;
+
+static int nthreads;
+
+/*
+ * API-specific code BEGINS here
+ */
+
+#define DEFD "/tmp"
+
+static char *optd = DEFD;
+static int nfiles;
+static int *files;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "d:");
+
+ lm_defN = "cscd_flock";
+
+ (void) sprintf(lm_usage,
+ " [-d directory for temp files (default %s)]\n"
+ "notes: thread cascade using flock file locking\n",
+ DEFD);
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'd':
+ optd = optarg;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ int i;
+ int errors = 0;
+ char fname[1024];
+
+ nthreads = lm_optP * lm_optT;
+ nfiles = nthreads * 2;
+ (void) setfdlimit(nfiles + 10);
+ files = (int *)malloc(nfiles * sizeof (int));
+ if (files == NULL) {
+ return (1);
+ }
+
+ (void) sprintf(fname, "%s/cascade.%ld", optd, getpid());
+
+ for (i = 0; i < nfiles; i++) {
+ files[i] = open(fname, O_CREAT | O_TRUNC | O_RDWR, 0600);
+ if (files[i] == -1) {
+ errors++;
+ }
+ if (unlink(fname)) {
+ errors++;
+ }
+ }
+
+ return (errors);
+}
+
+int
+block(int index)
+{
+ return (flock(files[index], LOCK_EX) == -1);
+}
+
+int
+unblock(int index)
+{
+ return (flock(files[index], LOCK_UN) == -1);
+}
+
+/*
+ * API-specific code ENDS here
+ */
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int e = 0;
+
+ if (ts->ts_once == 0) {
+ int us, them;
+
+ us = (getpindex() * lm_optT) + gettindex();
+ them = (us + 1) % (lm_optP * lm_optT);
+
+ ts->ts_id = us;
+
+ /* lock index asignment for us and them */
+ ts->ts_us0 = (us * 2);
+ ts->ts_us1 = (us * 2) + 1;
+ if (us < nthreads - 1) {
+ /* straight-thru connection to them */
+ ts->ts_them0 = (them * 2);
+ ts->ts_them1 = (them * 2) + 1;
+ } else {
+ /* cross-over connection to them */
+ ts->ts_them0 = (them * 2) + 1;
+ ts->ts_them1 = (them * 2);
+ }
+
+ ts->ts_once = 1;
+ }
+
+ /* block their first move */
+ e += block(ts->ts_them0);
+
+ return (e);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int e = 0;
+
+ /* wait to be unblocked (id == 0 will not block) */
+ e += block(ts->ts_us0);
+
+ for (i = 0; i < lm_optB; i += 2) {
+ /* allow them to block us again */
+ e += unblock(ts->ts_us0);
+
+ /* block their next + 1 move */
+ e += block(ts->ts_them1);
+
+ /* unblock their next move */
+ e += unblock(ts->ts_them0);
+
+ /* wait for them to unblock us */
+ e += block(ts->ts_us1);
+
+ /* repeat with locks reversed */
+ e += unblock(ts->ts_us1);
+ e += block(ts->ts_them0);
+ e += unblock(ts->ts_them1);
+ e += block(ts->ts_us0);
+ }
+
+ /* finish batch with nothing blocked */
+ e += unblock(ts->ts_them0);
+ e += unblock(ts->ts_us0);
+
+ res->re_count = i;
+ res->re_errors = e;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/cascade_lockf.c b/native/libMicro-0.4.0/cascade_lockf.c
new file mode 100644
index 0000000..2c95582
--- /dev/null
+++ b/native/libMicro-0.4.0/cascade_lockf.c
@@ -0,0 +1,223 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * The "cascade" test case is a multiprocess/multithread batten-passing model
+ * using lock primitives alone for synchronisation. Threads are arranged in a
+ * ring. Each thread has two locks of its own on which it blocks, and is able
+ * to manipulate the two locks belonging to the thread which follows it in the
+ * ring.
+ *
+ * The number of threads (nthreads) is specified by the generic libMicro -P/-T
+ * options. With nthreads == 1 (the default) the uncontended case can be timed.
+ *
+ * The main logic is generic and allows any simple blocking API to be tested.
+ * The API-specific component is clearly indicated.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ int ts_once;
+ int ts_id;
+ int ts_us0; /* our lock indices */
+ int ts_us1;
+ int ts_them0; /* their lock indices */
+ int ts_them1;
+} tsd_t;
+
+static int nthreads;
+
+/*
+ * API-specific code BEGINS here
+ */
+
+#define DEFD "/tmp"
+
+static char *optd = DEFD;
+static int nfiles;
+static int *files;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "d:");
+
+ lm_defN = "cscd_lockf";
+
+ (void) sprintf(lm_usage,
+ " [-d directory for temp files (default %s)]\n"
+ "notes: thread cascade using lockf file locking\n",
+ DEFD);
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'd':
+ optd = optarg;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ int i;
+ int errors = 0;
+ char fname[1024];
+
+ nthreads = lm_optP * lm_optT;
+ nfiles = nthreads * 2;
+ (void) setfdlimit(nfiles + 10);
+ files = (int *)malloc(nfiles * sizeof (int));
+ if (files == NULL) {
+ return (1);
+ }
+
+ (void) sprintf(fname, "%s/cascade.%ld", optd, getpid());
+
+ for (i = 0; i < nfiles; i++) {
+ files[i] = open(fname, O_CREAT | O_TRUNC | O_RDWR, 0600);
+ if (files[i] == -1) {
+ errors++;
+ }
+ if (unlink(fname)) {
+ errors++;
+ }
+ }
+
+ return (errors);
+}
+
+int
+block(int index)
+{
+ return (lockf(files[index], F_LOCK, 0) == -1);
+}
+
+int
+unblock(int index)
+{
+ return (lockf(files[index], F_ULOCK, 0) == -1);
+}
+
+/*
+ * API-specific code ENDS here
+ */
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int e = 0;
+
+ if (ts->ts_once == 0) {
+ int us, them;
+
+ us = (getpindex() * lm_optT) + gettindex();
+ them = (us + 1) % (lm_optP * lm_optT);
+
+ ts->ts_id = us;
+
+ /* lock index asignment for us and them */
+ ts->ts_us0 = (us * 2);
+ ts->ts_us1 = (us * 2) + 1;
+ if (us < nthreads - 1) {
+ /* straight-thru connection to them */
+ ts->ts_them0 = (them * 2);
+ ts->ts_them1 = (them * 2) + 1;
+ } else {
+ /* cross-over connection to them */
+ ts->ts_them0 = (them * 2) + 1;
+ ts->ts_them1 = (them * 2);
+ }
+
+ ts->ts_once = 1;
+ }
+
+ /* block their first move */
+ e += block(ts->ts_them0);
+
+ return (e);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int e = 0;
+
+ /* wait to be unblocked (id == 0 will not block) */
+ e += block(ts->ts_us0);
+
+ for (i = 0; i < lm_optB; i += 2) {
+ /* allow them to block us again */
+ e += unblock(ts->ts_us0);
+
+ /* block their next + 1 move */
+ e += block(ts->ts_them1);
+
+ /* unblock their next move */
+ e += unblock(ts->ts_them0);
+
+ /* wait for them to unblock us */
+ e += block(ts->ts_us1);
+
+ /* repeat with locks reversed */
+ e += unblock(ts->ts_us1);
+ e += block(ts->ts_them0);
+ e += unblock(ts->ts_them1);
+ e += block(ts->ts_us0);
+ }
+
+ /* finish batch with nothing blocked */
+ e += unblock(ts->ts_them0);
+ e += unblock(ts->ts_us0);
+
+ res->re_count = i;
+ res->re_errors = e;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/cascade_mutex.c b/native/libMicro-0.4.0/cascade_mutex.c
new file mode 100644
index 0000000..ecb38a1
--- /dev/null
+++ b/native/libMicro-0.4.0/cascade_mutex.c
@@ -0,0 +1,227 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * The "cascade" test case is a multiprocess/multithread batten-passing model
+ * using lock primitives alone for synchronisation. Threads are arranged in a
+ * ring. Each thread has two locks of its own on which it blocks, and is able
+ * to manipulate the two locks belonging to the thread which follows it in the
+ * ring.
+ *
+ * The number of threads (nthreads) is specified by the generic libMicro -P/-T
+ * options. With nthreads == 1 (the default) the uncontended case can be timed.
+ *
+ * The main logic is generic and allows any simple blocking API to be tested.
+ * The API-specific component is clearly indicated.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <pthread.h>
+#include <sys/mman.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ int ts_once;
+ int ts_id;
+ int ts_us0; /* our lock indices */
+ int ts_us1;
+ int ts_them0; /* their lock indices */
+ int ts_them1;
+} tsd_t;
+
+static int nthreads;
+
+/*
+ * API-specific code BEGINS here
+ */
+
+static int opts = 0;
+static int nlocks;
+static pthread_mutex_t *locks;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "s");
+
+ lm_defN = "cscd_mutex";
+
+ (void) sprintf(lm_usage,
+ " [-s] (force PTHREAD_PROCESS_SHARED)\n"
+ "notes: thread cascade using pthread_mutexes\n");
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 's':
+ opts = 1;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ int i;
+ int e = 0;
+ pthread_mutexattr_t ma;
+
+ nthreads = lm_optP * lm_optT;
+ nlocks = nthreads * 2;
+ /*LINTED*/
+ locks = (pthread_mutex_t *)mmap(NULL,
+ nlocks * sizeof (pthread_mutex_t),
+ PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_SHARED,
+ -1, 0L);
+ if (locks == MAP_FAILED) {
+ return (1);
+ }
+
+ (void) pthread_mutexattr_init(&ma);
+ if (lm_optP > 1 || opts) {
+ (void) pthread_mutexattr_setpshared(&ma,
+ PTHREAD_PROCESS_SHARED);
+ } else {
+ (void) pthread_mutexattr_setpshared(&ma,
+ PTHREAD_PROCESS_PRIVATE);
+ }
+
+ for (i = 0; i < nlocks; i++) {
+ (void) pthread_mutex_init(&locks[i], &ma);
+ }
+
+ return (e);
+}
+
+int
+block(int index)
+{
+ return (pthread_mutex_lock(&locks[index]) == -1);
+}
+
+int
+unblock(int index)
+{
+ return (pthread_mutex_unlock(&locks[index]) == -1);
+}
+
+/*
+ * API-specific code ENDS here
+ */
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int e = 0;
+
+ if (ts->ts_once == 0) {
+ int us, them;
+
+ us = (getpindex() * lm_optT) + gettindex();
+ them = (us + 1) % (lm_optP * lm_optT);
+
+ ts->ts_id = us;
+
+ /* lock index asignment for us and them */
+ ts->ts_us0 = (us * 2);
+ ts->ts_us1 = (us * 2) + 1;
+ if (us < nthreads - 1) {
+ /* straight-thru connection to them */
+ ts->ts_them0 = (them * 2);
+ ts->ts_them1 = (them * 2) + 1;
+ } else {
+ /* cross-over connection to them */
+ ts->ts_them0 = (them * 2) + 1;
+ ts->ts_them1 = (them * 2);
+ }
+
+ ts->ts_once = 1;
+ }
+
+ /* block their first move */
+ e += block(ts->ts_them0);
+
+ return (e);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int e = 0;
+
+ /* wait to be unblocked (id == 0 will not block) */
+ e += block(ts->ts_us0);
+
+ for (i = 0; i < lm_optB; i += 2) {
+ /* allow them to block us again */
+ e += unblock(ts->ts_us0);
+
+ /* block their next + 1 move */
+ e += block(ts->ts_them1);
+
+ /* unblock their next move */
+ e += unblock(ts->ts_them0);
+
+ /* wait for them to unblock us */
+ e += block(ts->ts_us1);
+
+ /* repeat with locks reversed */
+ e += unblock(ts->ts_us1);
+ e += block(ts->ts_them0);
+ e += unblock(ts->ts_them1);
+ e += block(ts->ts_us0);
+ }
+
+ /* finish batch with nothing blocked */
+ e += unblock(ts->ts_them0);
+ e += unblock(ts->ts_us0);
+
+ res->re_count = i;
+ res->re_errors = e;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/chdir.c b/native/libMicro-0.4.0/chdir.c
new file mode 100644
index 0000000..a9ff379
--- /dev/null
+++ b/native/libMicro-0.4.0/chdir.c
@@ -0,0 +1,132 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * change directory benchmark
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+#define DEFAULTDIR "/"
+#define MAXPATHLEN 1024
+
+static int optg = 0;
+
+static int dircount;
+static char ** dirlist;
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_optstr, "g");
+ lm_tsdsize = 0;
+
+ (void) sprintf(lm_usage,
+ " [-g] (do getcwd() also)\n"
+ " directory ... (default = %s)\n"
+ "notes: measures chdir() and (optionally) getcwd()",
+ DEFAULTDIR);
+
+ (void) sprintf(lm_header, "%5s %5s", "dirs", "gets");
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'g':
+ optg = 1;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ extern int optind;
+ int i;
+
+ dircount = lm_argc - optind;
+ if (dircount <= 0) {
+ dirlist = (char **)malloc(sizeof (char *));
+ dirlist[0] = DEFAULTDIR;
+ dircount = 1;
+ } else {
+ dirlist = (char **)malloc(dircount * sizeof (char *));
+ for (i = 0; i < dircount; i++) {
+ dirlist[i] = lm_argv[optind++];
+ }
+ }
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i, j;
+ char buf[MAXPATHLEN];
+
+ j = 0;
+ for (i = 0; i < lm_optB; i++) {
+ if (chdir(dirlist[j]) == -1)
+ res->re_errors++;
+ j++;
+ j %= dircount;
+
+ if (optg && (getcwd(buf, MAXPATHLEN) == NULL)) {
+ res->re_errors++;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%5d %5s", dircount, optg ? "y" : "n");
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/close.c b/native/libMicro-0.4.0/close.c
new file mode 100644
index 0000000..6050bcd
--- /dev/null
+++ b/native/libMicro-0.4.0/close.c
@@ -0,0 +1,141 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * benchmark for close
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "libmicro.h"
+
+#define DEFF "/dev/null"
+static char *optf = DEFF;
+static int optb = 0;
+
+typedef struct {
+ int *ts_fds;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ lm_defB = 256;
+
+ (void) sprintf(lm_optstr, "f:b");
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-close (default %s)]\n"
+ " [-b] (try to close an unopened fd)\n"
+ "notes: measures close()",
+ DEFF);
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf = optarg;
+ break;
+ case 'b':
+ optb = 1;
+ break;
+ default:
+ return (-1);
+ }
+
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ (void) setfdlimit(lm_optB * lm_optT + 10);
+
+ return (0);
+}
+
+int
+benchmark_initworker(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ ts->ts_fds = (int *)malloc(lm_optB * sizeof (int));
+ if (ts->ts_fds == NULL) {
+ return (1);
+ }
+ return (0);
+}
+
+/*
+ * don't need a finiworker; we're exiting anyway
+ */
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int errors = 0;
+
+ for (i = 0; i < lm_optB; i++) {
+ ts->ts_fds[i] = ((optb == 0) ?
+ open(optf, O_RDONLY) : i + 1024);
+ if (ts->ts_fds[i] == -1) {
+ errors++;
+ }
+ }
+
+ return (errors);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (close(ts->ts_fds[i]) == -1 && !optb) {
+ res->re_errors++;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/close_tcp.c b/native/libMicro-0.4.0/close_tcp.c
new file mode 100644
index 0000000..6bce7a7
--- /dev/null
+++ b/native/libMicro-0.4.0/close_tcp.c
@@ -0,0 +1,241 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * benchmark to measure time to close a local tcp connection
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "libmicro.h"
+
+#define FIRSTPORT 12345
+
+typedef struct {
+ int *ts_lsns;
+ int *ts_accs;
+ int *ts_cons;
+ struct sockaddr_in *ts_adds;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ lm_defB = 256;
+
+ (void) sprintf(lm_usage,
+ "notes: measures close() on local TCP connections");
+
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ (void) setfdlimit(3 * lm_optB * lm_optT + 10);
+
+ return (0);
+}
+
+int
+benchmark_initworker(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i, j;
+ int opt = 1;
+ struct hostent *host;
+ int errors = 0;
+
+ ts->ts_lsns = (int *)malloc(lm_optB * sizeof (int));
+ if (ts->ts_lsns == NULL) {
+ errors ++;
+ }
+ ts->ts_accs = (int *)malloc(lm_optB * sizeof (int));
+ if (ts->ts_accs == NULL) {
+ errors ++;
+ }
+ ts->ts_cons = (int *)malloc(lm_optB * sizeof (int));
+ if (ts->ts_cons == NULL) {
+ errors ++;
+ }
+ ts->ts_adds = (struct sockaddr_in *)malloc(lm_optB *
+ sizeof (struct sockaddr_in));
+ if (ts->ts_adds == NULL) {
+ errors ++;
+ }
+
+ j = FIRSTPORT;
+ for (i = 0; i < lm_optB; i++) {
+ ts->ts_lsns[i] = socket(AF_INET, SOCK_STREAM, 0);
+ if (ts->ts_lsns[i] == -1) {
+ perror("socket");
+ errors ++;
+ }
+
+ if (setsockopt(ts->ts_lsns[i], SOL_SOCKET, SO_REUSEADDR,
+ &opt, sizeof (int)) == -1) {
+ perror("setsockopt");
+ errors ++;
+ }
+
+ if ((host = gethostbyname("localhost")) == NULL) {
+ errors ++;
+ }
+
+ for (;;) {
+ (void) memset(&ts->ts_adds[i], 0,
+ sizeof (struct sockaddr_in));
+ ts->ts_adds[i].sin_family = AF_INET;
+ ts->ts_adds[i].sin_port = htons(j++);
+ (void) memcpy(&ts->ts_adds[i].sin_addr.s_addr,
+ host->h_addr_list[0], sizeof (struct in_addr));
+
+ if (bind(ts->ts_lsns[i],
+ (struct sockaddr *)&ts->ts_adds[i],
+ sizeof (struct sockaddr_in)) == 0) {
+ break;
+ }
+
+ if (errno != EADDRINUSE) {
+ perror("bind");
+ errors ++;
+ }
+ }
+
+ if (listen(ts->ts_lsns[i], 5) == -1) {
+ perror("listen");
+ errors ++;
+ }
+
+ }
+ return (errors);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int result;
+ struct sockaddr_in addr;
+ socklen_t size;
+ int errors = 0;
+
+ for (i = 0; i < lm_optB; i++) {
+ ts->ts_cons[i] = socket(AF_INET, SOCK_STREAM, 0);
+ if (ts->ts_cons[i] == -1) {
+ perror("socket");
+ errors ++;
+ continue;
+ }
+
+ if (fcntl(ts->ts_cons[i], F_SETFL, O_NDELAY) == -1) {
+ perror("fcnt");
+ errors ++;
+ continue;
+ }
+
+ result = connect(ts->ts_cons[i],
+ (struct sockaddr *)&ts->ts_adds[i],
+ sizeof (struct sockaddr_in));
+
+ if ((result == -1) && (errno != EINPROGRESS)) {
+ perror("connect");
+ errors ++;
+ continue;
+ }
+
+ size = sizeof (struct sockaddr);
+ result = accept(ts->ts_lsns[i], (struct sockaddr *)&addr,
+ &size);
+ if (result == -1) {
+ perror("accept");
+ errors ++;
+ continue;
+ }
+ ts->ts_accs[i] = result;
+ }
+
+ return (errors);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (close(ts->ts_accs[i]) == -1) {
+ res->re_errors ++;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+int
+benchmark_finibatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ (void) close(ts->ts_cons[i]);
+ }
+
+ return (0);
+}
+
+int
+benchmark_finiworker(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ (void) close(ts->ts_lsns[i]);
+ }
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/connection.c b/native/libMicro-0.4.0/connection.c
new file mode 100644
index 0000000..67239f9
--- /dev/null
+++ b/native/libMicro-0.4.0/connection.c
@@ -0,0 +1,305 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/poll.h>
+
+#include "libmicro.h"
+
+#define FIRSTPORT 12345
+
+typedef struct {
+ int ts_once;
+ int *ts_lsns;
+ int *ts_accs;
+ int *ts_cons;
+ struct sockaddr_in *ts_adds;
+} tsd_t;
+
+static int opta = 0;
+static int optc = 0;
+static struct hostent *host;
+
+int
+benchmark_init()
+{
+ lm_defB = 256;
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "ac");
+
+ (void) sprintf(lm_usage,
+ " [-a] (measure accept() only)\n"
+ " [-c] (measure connect() only)\n"
+ "notes: measures connect()/accept()\n");
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'a':
+ opta = 1;
+ break;
+ case 'c':
+ optc = 1;
+ break;
+ default:
+ return (-1);
+ }
+
+ if (opta && optc) {
+ (void) printf("warning: -a overrides -c\n");
+ optc = 0;
+ }
+
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ (void) setfdlimit(3 * lm_optB * lm_optT + 10);
+
+ return (0);
+}
+
+int
+benchmark_initbatch_once(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i, j;
+
+ int errors = 0;
+
+ ts->ts_lsns = (int *)malloc(lm_optB * sizeof (int));
+ if (ts->ts_lsns == NULL) {
+ errors ++;
+ }
+ ts->ts_accs = (int *)malloc(lm_optB * sizeof (int));
+ if (ts->ts_accs == NULL) {
+ errors ++;
+ }
+ ts->ts_cons = (int *)malloc(lm_optB * sizeof (int));
+ if (ts->ts_cons == NULL) {
+ errors ++;
+ }
+ ts->ts_adds =
+ (struct sockaddr_in *)malloc(lm_optB *
+ sizeof (struct sockaddr_in));
+ if (ts->ts_accs == NULL) {
+ errors ++;
+ }
+
+ j = FIRSTPORT;
+ for (i = 0; i < lm_optB; i++) {
+ ts->ts_lsns[i] = socket(AF_INET, SOCK_STREAM, 0);
+ if (ts->ts_lsns[i] == -1) {
+ perror("socket");
+ errors ++;
+ }
+
+ /*
+ * make accept socket non-blocking so in case of errors
+ * we don't hang
+ */
+
+ if (fcntl(ts->ts_lsns[i], F_SETFL, O_NDELAY) == -1) {
+ perror("fcntl");
+ errors ++;
+ }
+
+
+ if ((host = gethostbyname("localhost")) == NULL) {
+ errors ++;
+ }
+
+ for (;;) {
+ (void) memset(&ts->ts_adds[i], 0,
+ sizeof (struct sockaddr_in));
+ ts->ts_adds[i].sin_family = AF_INET;
+ ts->ts_adds[i].sin_port = htons(j++);
+ (void) memcpy(&ts->ts_adds[i].sin_addr.s_addr,
+ host->h_addr_list[0], sizeof (struct in_addr));
+
+ if (bind(ts->ts_lsns[i],
+ (struct sockaddr *)&ts->ts_adds[i],
+ sizeof (struct sockaddr_in)) == 0) {
+ break;
+ }
+
+ if (errno != EADDRINUSE) {
+ errors ++;
+ }
+ }
+
+ if (listen(ts->ts_lsns[i], 5) == -1) {
+ perror("listen");
+ errors ++;
+ }
+ }
+ return (errors);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int errors = 0;
+ int result;
+
+ if (ts->ts_once++ == 0) {
+ if (errors += benchmark_initbatch_once(tsd) == -1) {
+ return (-1);
+ }
+ }
+
+
+ for (i = 0; i < lm_optB; i++) {
+ ts->ts_cons[i] = socket(AF_INET, SOCK_STREAM, 0);
+ if (ts->ts_cons[i] == -1) {
+ perror("init:socket");
+ errors ++;
+ }
+
+ if (fcntl(ts->ts_cons[i], F_SETFL, O_NDELAY) == -1) {
+ perror("init:fcntl");
+ errors ++;
+ }
+
+ if (opta) {
+ result = connect(ts->ts_cons[i],
+ (struct sockaddr *)&ts->ts_adds[i],
+ sizeof (struct sockaddr_in));
+ if ((result == -1) && (errno != EINPROGRESS)) {
+ perror("init:connect");
+ errors ++;
+ }
+ }
+ }
+
+ return (errors);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+
+
+
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int result;
+ struct sockaddr_in addr;
+ socklen_t size;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (!opta) {
+ again:
+ result = connect(ts->ts_cons[i],
+ (struct sockaddr *)&ts->ts_adds[i],
+ sizeof (struct sockaddr_in));
+ if (result != 0 && errno != EISCONN) {
+ if (errno == EINPROGRESS) {
+ struct pollfd pollfd;
+ if (optc)
+ continue;
+ pollfd.fd = ts->ts_cons[i];
+ pollfd.events = POLLOUT;
+ if (poll(&pollfd, 1, -1) == 1)
+ goto again;
+ }
+
+ res->re_errors ++;
+ perror("benchmark:connect");
+ continue;
+ }
+ }
+
+ if (!optc) {
+ size = sizeof (struct sockaddr);
+ for (;;) {
+ struct pollfd pollfd;
+ result = accept(ts->ts_lsns[i],
+ (struct sockaddr *)&addr, &size);
+ if (result > 0 || (result == -1 &&
+ errno != EAGAIN))
+ break;
+ pollfd.fd = ts->ts_lsns[i];
+ pollfd.events = POLLIN;
+ if (poll(&pollfd, 1, -1) != 1)
+ break;
+ }
+
+ ts->ts_accs[i] = result;
+ if (result == -1) {
+ res->re_errors ++;
+ perror("benchmark:accept");
+ continue;
+ }
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+int
+benchmark_finibatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+
+ if (!optc) {
+ (void) close(ts->ts_accs[i]);
+ }
+ (void) close(ts->ts_cons[i]);
+ }
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/dup.c b/native/libMicro-0.4.0/dup.c
new file mode 100644
index 0000000..cdce1f1
--- /dev/null
+++ b/native/libMicro-0.4.0/dup.c
@@ -0,0 +1,139 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * time dup
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "libmicro.h"
+
+#define DEFF "/dev/null"
+static char *optf = DEFF;
+
+static int fd;
+
+typedef struct {
+ int ts_once;
+ int *ts_fds;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ lm_defB = 256;
+
+ (void) sprintf(lm_optstr, "f:");
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-dup (default %s)]\n"
+ "notes: measures dup()\n",
+ DEFF);
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf = optarg;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ (void) setfdlimit(lm_optB * lm_optT + 10);
+ fd = (open(optf, O_RDONLY));
+
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int errors = 0;
+
+ if (ts->ts_once++ == 0) {
+ ts->ts_fds = (int *)malloc(lm_optB * sizeof (int));
+ if (ts->ts_fds == NULL) {
+ errors ++;
+ }
+ for (i = 0; i < lm_optB; i++) {
+ ts->ts_fds[i] = -1;
+ }
+ }
+
+ return (errors);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ ts->ts_fds[i] = dup(fd);
+ if (ts->ts_fds[i] == -1) {
+ res->re_errors++;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+int
+benchmark_finibatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ (void) close(ts->ts_fds[i]);
+ }
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/elided.c b/native/libMicro-0.4.0/elided.c
new file mode 100644
index 0000000..ab26e6e
--- /dev/null
+++ b/native/libMicro-0.4.0/elided.c
@@ -0,0 +1,59 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * empty benchmark program to substitute for benchmarks
+ * that don't work/exist on some platforms
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*ARGSUSED*/
+int
+main(int argc, char *argv[])
+{
+ char *tmp = strrchr(argv[0], '/');
+
+ if (tmp == NULL)
+ tmp = argv[0];
+ else
+ tmp++;
+
+ (void) printf(
+ "#\n"
+ "# benchmark %s not compiled/supported on this platform\n"
+ "#\n",
+ tmp);
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/exec.c b/native/libMicro-0.4.0/exec.c
new file mode 100644
index 0000000..3110a14
--- /dev/null
+++ b/native/libMicro-0.4.0/exec.c
@@ -0,0 +1,101 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * exec benchmark
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/wait.h>
+
+#include "libmicro.h"
+
+static char exec_path[1024];
+static char *argv[3];
+
+int
+benchmark_init()
+{
+ lm_defB = 128;
+ lm_tsdsize = 0;
+
+ (void) sprintf(lm_usage,
+ "notes: measures execv time of simple process()\n");
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark_initbatch(void *tsd)
+{
+ char buffer[80];
+
+ (void) strcpy(exec_path, lm_procpath);
+ (void) strcat(exec_path, "/exec_bin");
+
+ (void) sprintf(buffer, "%d", lm_optB);
+ argv[0] = exec_path;
+ argv[1] = strdup(buffer);
+ argv[2] = NULL;
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int c;
+ int status;
+
+ switch (c = fork()) {
+ case -1:
+ res->re_errors++;
+ break;
+ default:
+ if (waitpid(c, &status, 0) < 0)
+ res->re_errors++;
+
+ if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
+ res->re_errors++;
+ break;
+ case 0:
+ if (execv(exec_path, argv) < 0)
+ res->re_errors++;
+ }
+
+ res->re_count = lm_optB;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/exec_bin.c b/native/libMicro-0.4.0/exec_bin.c
new file mode 100644
index 0000000..4cddfd3
--- /dev/null
+++ b/native/libMicro-0.4.0/exec_bin.c
@@ -0,0 +1,65 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * time program to recursively test exec time
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int
+main(int argc, char *argv[])
+{
+ int left;
+
+ if (argc == 1) {
+ exit(1);
+ }
+
+ left = atoi(argv[1]);
+
+ left--;
+
+ if (left <= 0) {
+ exit(0);
+ } else {
+ char buffer[80];
+ (void) sprintf(buffer, "%d", left);
+ argv[1] = buffer;
+ if (execv(argv[0], argv)) {
+ exit(2);
+ }
+ }
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/exit.c b/native/libMicro-0.4.0/exit.c
new file mode 100644
index 0000000..e2aa54d
--- /dev/null
+++ b/native/libMicro-0.4.0/exit.c
@@ -0,0 +1,160 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * benchmark exit
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ int ts_once;
+ int *ts_pids;
+} tsd_t;
+
+static int opte = 0;
+static barrier_t *b;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+ (void) sprintf(lm_optstr, "e");
+
+ (void) sprintf(lm_usage,
+ " [-e] (uses _exit() rather than exit())"
+ "notes: measures exit()\n");
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'e':
+ opte = 1;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ b = barrier_create(lm_optP * lm_optT * (lm_optB + 1), 0);
+
+ return (0);
+}
+
+int
+benchmark_finirun()
+{
+ (void) barrier_destroy(b);
+
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int errors = 0;
+
+ if (ts->ts_once++ == 0) {
+ ts->ts_pids = (int *)malloc(lm_optB * sizeof (pid_t));
+ if (ts->ts_pids == NULL) {
+ errors ++;
+ }
+ }
+
+ /*
+ * create processes to exit
+ */
+
+ for (i = 0; i < lm_optB; i++) {
+ ts->ts_pids[i] = fork();
+ switch (ts->ts_pids[i]) {
+ case 0:
+ (void) barrier_queue(b, NULL);
+ if (opte)
+ _exit(0);
+ exit(0);
+ break;
+ case -1:
+ errors ++;
+ break;
+ default:
+ continue;
+ }
+ }
+
+ return (errors);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+
+ /*
+ * start them all exiting
+ */
+
+ (void) barrier_queue(b, NULL);
+
+ /*
+ * wait for them all to exit
+ */
+
+ for (i = 0; i < lm_optB; i++) {
+ switch (waitpid((pid_t)-1, NULL, 0)) {
+ case 0:
+ continue;
+ case -1:
+ res->re_errors++;
+ }
+ }
+
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/exp.c b/native/libMicro-0.4.0/exp.c
new file mode 100644
index 0000000..acc81c5
--- /dev/null
+++ b/native/libMicro-0.4.0/exp.c
@@ -0,0 +1,73 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * test exp performance (should add range check)
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "note: measures exp()");
+ lm_nsecs_per_op = 25;
+ lm_tsdsize = 0;
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ double value = 1.0 / (i + .01);
+ (void) exp(value);
+ (void) exp(value);
+ (void) exp(value);
+ (void) exp(value);
+ (void) exp(value);
+ (void) exp(value);
+ (void) exp(value);
+ (void) exp(value);
+ (void) exp(value);
+ (void) exp(value);
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/fcntl.c b/native/libMicro-0.4.0/fcntl.c
new file mode 100644
index 0000000..95099c1
--- /dev/null
+++ b/native/libMicro-0.4.0/fcntl.c
@@ -0,0 +1,99 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * benchmark fcntl getfl
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include "libmicro.h"
+
+#define DEFF "/dev/null"
+
+static char *optf = DEFF;
+static int fd = -1;
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_optstr, "f:");
+ lm_tsdsize = 0;
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-fcntl (default %s)]\n"
+ "notes: measures fcntl()\n",
+ DEFF);
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf = optarg;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ if ((fd = open(optf, O_RDONLY)) == -1) {
+ perror("open");
+ exit(1);
+ }
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ int flags;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (fcntl(fd, F_GETFL, &flags) == -1)
+ res->re_errors++;
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/fcntl_ndelay.c b/native/libMicro-0.4.0/fcntl_ndelay.c
new file mode 100644
index 0000000..3f55a18
--- /dev/null
+++ b/native/libMicro-0.4.0/fcntl_ndelay.c
@@ -0,0 +1,100 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * measures O_NDELAY on socket
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <fcntl.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include "libmicro.h"
+
+static int fd = -1;
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage,
+ "notes: measures F_GETFL/F_SETFL O_NDELAY on socket\n");
+
+ lm_tsdsize = 0;
+
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ fd = socket(AF_INET, SOCK_STREAM, 0);
+ if (fd == -1) {
+ perror("socket");
+ exit(1);
+ }
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ int flags;
+
+ for (i = 0; i < lm_optB; i += 4) {
+ if (fcntl(fd, F_GETFL, &flags) < 0)
+ res->re_errors++;
+ flags |= O_NDELAY;
+
+ if (fcntl(fd, F_SETFL, &flags) < 0)
+ res->re_errors++;
+
+ if (fcntl(fd, F_GETFL, &flags) < 0)
+ res->re_errors++;
+ flags &= ~O_NDELAY;
+
+ if (fcntl(fd, F_SETFL, &flags) < 0)
+ res->re_errors++;
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/file_lock.c b/native/libMicro-0.4.0/file_lock.c
new file mode 100644
index 0000000..33d8860
--- /dev/null
+++ b/native/libMicro-0.4.0/file_lock.c
@@ -0,0 +1,106 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * test file locking
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include "libmicro.h"
+
+static int file;
+
+int
+block(int index)
+{
+ struct flock fl;
+
+ fl.l_type = F_WRLCK;
+ fl.l_whence = SEEK_SET;
+ fl.l_start = index;
+ fl.l_len = 1;
+ return (fcntl(file, F_SETLKW, &fl) == -1);
+}
+
+int
+unblock(int index)
+{
+ struct flock fl;
+
+ fl.l_type = F_UNLCK;
+ fl.l_whence = SEEK_SET;
+ fl.l_start = index;
+ fl.l_len = 1;
+ return (fcntl(file, F_SETLK, &fl) == -1);
+}
+int
+benchmark_init()
+{
+ char fname[80];
+ int errors = 0;
+
+ (void) sprintf(fname, "/tmp/oneflock.%ld", getpid());
+
+ file = open(fname, O_CREAT | O_TRUNC | O_RDWR, 0600);
+
+ if (file == -1) {
+ errors++;
+ }
+ if (unlink(fname)) {
+ errors++;
+ }
+
+ lm_tsdsize = 0;
+
+ return (errors);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ int e = 0;
+
+ for (i = 0; i < lm_optB; i ++) {
+ e += block(0);
+ e += unblock(0);
+ }
+ res->re_count = i;
+ res->re_errors = e;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/fork.c b/native/libMicro-0.4.0/fork.c
new file mode 100644
index 0000000..d033691
--- /dev/null
+++ b/native/libMicro-0.4.0/fork.c
@@ -0,0 +1,131 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * benchmark fork
+ */
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "libmicro.h"
+
+static barrier_t *b;
+
+typedef struct {
+ int ts_once;
+ int *ts_pids;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+ (void) sprintf(lm_usage, "notes: measures fork()\n");
+
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ b = barrier_create(lm_optP * lm_optT * (lm_optB + 1), 0);
+
+ return (0);
+}
+
+int
+benchmark_finirun()
+{
+ (void) barrier_destroy(b);
+
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int errors = 0;
+
+ if (ts->ts_once++ == 0) {
+ ts->ts_pids = (int *)malloc(lm_optB * sizeof (pid_t));
+ if (ts->ts_pids == NULL) {
+ errors++;
+ }
+ }
+
+ return (errors);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ ts->ts_pids[i] = fork();
+ switch (ts->ts_pids[i]) {
+ case 0:
+ (void) barrier_queue(b, NULL);
+ exit(0);
+ break;
+ case -1:
+ res->re_errors++;
+ break;
+ default:
+ continue;
+ }
+ }
+ res->re_count = lm_optB;
+
+ (void) barrier_queue(b, NULL);
+
+ return (0);
+}
+
+int
+benchmark_finibatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (ts->ts_pids[i] > 0) {
+ (void) waitpid(ts->ts_pids[i], NULL, 0);
+ }
+ }
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/getcontext.c b/native/libMicro-0.4.0/getcontext.c
new file mode 100644
index 0000000..524a016
--- /dev/null
+++ b/native/libMicro-0.4.0/getcontext.c
@@ -0,0 +1,74 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * getcontext
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ucontext.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "notes: measures getcontext()\n");
+
+ lm_tsdsize = 0;
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ ucontext_t uc;
+ (void) getcontext(&uc);
+ (void) getcontext(&uc);
+ (void) getcontext(&uc);
+ (void) getcontext(&uc);
+ (void) getcontext(&uc);
+ (void) getcontext(&uc);
+ (void) getcontext(&uc);
+ (void) getcontext(&uc);
+ (void) getcontext(&uc);
+ (void) getcontext(&uc);
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/getenv.c b/native/libMicro-0.4.0/getenv.c
new file mode 100644
index 0000000..f75bfd4
--- /dev/null
+++ b/native/libMicro-0.4.0/getenv.c
@@ -0,0 +1,126 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * test getenv
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <string.h>
+
+#include "libmicro.h"
+
+#define DEFS 100
+
+static int opts = DEFS;
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_optstr, "s:");
+
+ lm_tsdsize = 0;
+
+ (void) sprintf(lm_usage,
+ " [-s search-size (default = %d)]\n"
+ "notes: measures time to search env for missing string\n",
+ DEFS);
+
+ lm_nsecs_per_op = 200;
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 's':
+ opts = atoi(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ extern char ** environ;
+ int i, j;
+
+ /* count environment strings */
+
+ for (i = 0; environ[i++]; )
+ ;
+
+ /*
+ * pad to desired count
+ */
+
+ if (opts < i)
+ opts = i;
+
+ for (j = i; j < opts; j++) {
+ char buf[80];
+ (void) sprintf(buf, "VAR_%d=%d", j, j);
+ (void) putenv(strdup(buf));
+ }
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ char *search = "RUMPLSTILTSKIN";
+
+ for (i = 0; i < lm_optB; i += 10) {
+ (void) getenv(search);
+ (void) getenv(search);
+ (void) getenv(search);
+ (void) getenv(search);
+ (void) getenv(search);
+ (void) getenv(search);
+ (void) getenv(search);
+ (void) getenv(search);
+ (void) getenv(search);
+ (void) getenv(search);
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/getpeername.c b/native/libMicro-0.4.0/getpeername.c
new file mode 100644
index 0000000..877215d
--- /dev/null
+++ b/native/libMicro-0.4.0/getpeername.c
@@ -0,0 +1,163 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * getpeername test
+ */
+
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "libmicro.h"
+
+#define FIRSTPORT 12345
+
+static int sock = -1;
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "notes: measures getpeername()\n");
+ lm_tsdsize = 0;
+
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ int j;
+ int opt = 1;
+ int result;
+ socklen_t size;
+ struct hostent *host;
+ struct sockaddr_in adds;
+ int sock2, sock3;
+
+ sock2 = socket(AF_INET, SOCK_STREAM, 0);
+ if (sock2 == -1) {
+ perror("socket");
+ exit(1);
+ }
+
+ if (setsockopt(sock2, SOL_SOCKET, SO_REUSEADDR,
+ &opt, sizeof (int)) == -1) {
+ perror("setsockopt");
+ exit(1);
+ }
+
+ if ((host = gethostbyname("localhost")) == NULL) {
+ perror("gethostbyname");
+ exit(1);
+ }
+
+ j = FIRSTPORT;
+ for (;;) {
+ (void) memset(&adds, 0, sizeof (struct sockaddr_in));
+ adds.sin_family = AF_INET;
+ adds.sin_port = htons(j++);
+ (void) memcpy(&adds.sin_addr.s_addr, host->h_addr_list[0],
+ sizeof (struct in_addr));
+
+ if (bind(sock2, (struct sockaddr *)&adds,
+ sizeof (struct sockaddr_in)) == 0) {
+ break;
+ }
+
+ if (errno != EADDRINUSE) {
+ perror("bind");
+ exit(1);
+ }
+ }
+
+ if (listen(sock2, 5) == -1) {
+ perror("listen");
+ exit(1);
+ }
+
+ sock3 = socket(AF_INET, SOCK_STREAM, 0);
+ if (sock3 == -1) {
+ perror("socket");
+ exit(1);
+ }
+
+ if (fcntl(sock3, F_SETFL, O_NDELAY) == -1) {
+ perror("fcntl");
+ exit(1);
+ }
+
+ result = connect(sock3, (struct sockaddr *)&adds,
+ sizeof (struct sockaddr_in));
+ if ((result == -1) && (errno != EINPROGRESS)) {
+ perror("connect");
+ exit(1);
+ }
+
+ size = sizeof (struct sockaddr);
+ sock = accept(sock2, (struct sockaddr *)&adds, &size);
+ if (sock == -1) {
+ perror("accept");
+ exit(1);
+ }
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ struct sockaddr_in adds;
+ socklen_t size;
+
+ for (i = 0; i < lm_optB; i++) {
+ size = sizeof (struct sockaddr_in);
+ if (getpeername(sock, (struct sockaddr *)&adds, &size) == -1) {
+ perror("getpeername");
+ exit(1);
+ res->re_errors++;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/getpid.c b/native/libMicro-0.4.0/getpid.c
new file mode 100644
index 0000000..4ac8165
--- /dev/null
+++ b/native/libMicro-0.4.0/getpid.c
@@ -0,0 +1,64 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * getpid
+ */
+
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "note: measures getpid()");
+
+ lm_tsdsize = 0;
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+
+ for (i = 0; i < lm_optB; i ++) {
+ (void) getpid();
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/getrusage.c b/native/libMicro-0.4.0/getrusage.c
new file mode 100644
index 0000000..2f02213
--- /dev/null
+++ b/native/libMicro-0.4.0/getrusage.c
@@ -0,0 +1,73 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * getrusage
+ */
+
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/resource.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "notes: measures getrusage(RUSAGE_SELF)\n");
+ lm_tsdsize = 0;
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ struct rusage u;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ (void) getrusage(RUSAGE_SELF, &u);
+ (void) getrusage(RUSAGE_SELF, &u);
+ (void) getrusage(RUSAGE_SELF, &u);
+ (void) getrusage(RUSAGE_SELF, &u);
+ (void) getrusage(RUSAGE_SELF, &u);
+ (void) getrusage(RUSAGE_SELF, &u);
+ (void) getrusage(RUSAGE_SELF, &u);
+ (void) getrusage(RUSAGE_SELF, &u);
+ (void) getrusage(RUSAGE_SELF, &u);
+ (void) getrusage(RUSAGE_SELF, &u);
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/getsockname.c b/native/libMicro-0.4.0/getsockname.c
new file mode 100644
index 0000000..e3f7769
--- /dev/null
+++ b/native/libMicro-0.4.0/getsockname.c
@@ -0,0 +1,125 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * getsockname
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "libmicro.h"
+
+#define FIRSTPORT 12345
+
+static struct sockaddr_in adds;
+static int sock = -1;
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "notes: measures getsockname()()\n");
+ lm_tsdsize = 0;
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ int j;
+ int opt = 1;
+ struct hostent *host;
+
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+ if (sock == -1) {
+ perror("socket");
+ exit(1);
+ }
+
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+ &opt, sizeof (int)) == -1) {
+ perror("setsockopt");
+ exit(1);
+ }
+
+ if ((host = gethostbyname("localhost")) == NULL) {
+ perror("gethostbyname");
+ exit(1);
+ }
+
+ j = FIRSTPORT;
+ for (;;) {
+ (void) memset(&adds, 0, sizeof (struct sockaddr_in));
+ adds.sin_family = AF_INET;
+ adds.sin_port = htons(j++);
+ (void) memcpy(&adds.sin_addr.s_addr, host->h_addr_list[0],
+ sizeof (struct in_addr));
+
+ if (bind(sock, (struct sockaddr *)&adds,
+ sizeof (struct sockaddr_in)) == 0) {
+ break;
+ }
+
+ if (errno != EADDRINUSE) {
+ perror("bind");
+ exit(1);
+ }
+ }
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ struct sockaddr_in adds;
+ socklen_t size;
+
+ for (i = 0; i < lm_optB; i++) {
+ size = sizeof (struct sockaddr_in);
+ if (getsockname(sock, (struct sockaddr *)&adds, &size) == -1)
+ res->re_errors++;
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/gettimeofday.c b/native/libMicro-0.4.0/gettimeofday.c
new file mode 100644
index 0000000..a17bf75
--- /dev/null
+++ b/native/libMicro-0.4.0/gettimeofday.c
@@ -0,0 +1,72 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * gettimeofday test
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "note: measures gettimeofday()");
+ lm_tsdsize = 0;
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ struct timeval t;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ (void) gettimeofday(&t, NULL);
+ (void) gettimeofday(&t, NULL);
+ (void) gettimeofday(&t, NULL);
+ (void) gettimeofday(&t, NULL);
+ (void) gettimeofday(&t, NULL);
+ (void) gettimeofday(&t, NULL);
+ (void) gettimeofday(&t, NULL);
+ (void) gettimeofday(&t, NULL);
+ (void) gettimeofday(&t, NULL);
+ (void) gettimeofday(&t, NULL);
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/isatty.c b/native/libMicro-0.4.0/isatty.c
new file mode 100644
index 0000000..68aaf85
--- /dev/null
+++ b/native/libMicro-0.4.0/isatty.c
@@ -0,0 +1,110 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * isatty test
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "libmicro.h"
+
+#define DEFF "/dev/tty"
+static char *optf = DEFF;
+static int optb = 0;
+
+typedef struct {
+ int ts_fd;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "f:b");
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-isatty (default %s)]\n"
+ " [-b] (try to isatty an unopened fd)\n"
+ "notes: measures isatty()",
+ DEFF);
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf = optarg;
+ break;
+ case 'b':
+ optb = 1;
+ break;
+ default:
+ return (-1);
+ }
+
+ return (0);
+}
+
+int
+benchmark_initworker(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ ts->ts_fd = ((optb == 0) ?
+ open(optf, O_RDONLY) : 1024);
+ if (ts->ts_fd == -1) {
+ return (1);
+ }
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (isatty(ts->ts_fd) == -1) {
+ res->re_errors++;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/libmicro.c b/native/libMicro-0.4.0/libmicro.c
new file mode 100644
index 0000000..b4e11c2
--- /dev/null
+++ b/native/libMicro-0.4.0/libmicro.c
@@ -0,0 +1,1612 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * benchmarking routines
+ */
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/ipc.h>
+#include <sys/mman.h>
+#include <sys/wait.h>
+#include <ctype.h>
+#include <string.h>
+#include <strings.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <poll.h>
+#include <pthread.h>
+#include <dlfcn.h>
+#include <errno.h>
+#include <sys/resource.h>
+#include <math.h>
+#include <limits.h>
+
+#ifdef __sun
+#include <sys/elf.h>
+#endif
+
+#include "libmicro.h"
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <netinet/tcp.h>
+
+
+/*
+ * user visible globals
+ */
+
+int lm_argc = 0;
+char ** lm_argv = NULL;
+
+int lm_opt1;
+int lm_optA;
+int lm_optB;
+int lm_optC = 100;
+int lm_optD;
+int lm_optE;
+int lm_optH;
+int lm_optI;
+int lm_optL = 0;
+int lm_optM = 0;
+char *lm_optN;
+int lm_optP;
+int lm_optS;
+int lm_optT;
+int lm_optW;
+
+int lm_def1 = 0;
+int lm_defB = 0; /* use lm_nsecs_per_op */
+int lm_defD = 10;
+int lm_defH = 0;
+char *lm_defN = NULL;
+int lm_defP = 1;
+
+int lm_defS = 0;
+int lm_defT = 1;
+
+/*
+ * default on fast platform, should be overridden by individual
+ * benchmarks if significantly wrong in either direction.
+ */
+
+int lm_nsecs_per_op = 5;
+
+char *lm_procpath;
+char lm_procname[STRSIZE];
+char lm_usage[STRSIZE];
+char lm_optstr[STRSIZE];
+char lm_header[STRSIZE];
+size_t lm_tsdsize = 0;
+
+
+/*
+ * Globals we do not export to the user
+ */
+
+static barrier_t *lm_barrier;
+static pid_t *pids = NULL;
+static pthread_t *tids = NULL;
+static int pindex = -1;
+static void *tsdseg = NULL;
+static size_t tsdsize = 0;
+
+#ifdef USE_RDTSC
+static long long lm_hz = 0;
+#endif
+
+
+/*
+ * Forward references
+ */
+
+static void worker_process();
+static void usage();
+static void print_stats(barrier_t *);
+static void print_histo(barrier_t *);
+static int remove_outliers(double *, int, stats_t *);
+static long long nsecs_overhead;
+static long long nsecs_resolution;
+static long long get_nsecs_overhead();
+static int crunch_stats(double *, int, stats_t *);
+static void compute_stats(barrier_t *);
+
+#define SERVERHOST "localhost"
+uint16_t PORT = -1;
+int SOCK = -1;
+int socket_on = 0;
+
+void init_sockaddr (struct sockaddr_in *name, const char *hostname, uint16_t port)
+{
+ struct hostent *hostinfo;
+
+ name->sin_family = AF_INET;
+ name->sin_port = htons (port);
+ hostinfo = gethostbyname (hostname);
+ if (hostinfo == NULL) {
+ fprintf (stderr, "Unknown host %s.\n", hostname);
+ fflush(stderr);
+ exit (EXIT_FAILURE);
+ }
+ name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
+}
+
+int make_socket()
+{
+ int sock = socket (PF_INET, SOCK_STREAM, 0);
+ if (sock < 0) {
+ fprintf(stderr, "cannot create socket.\n");
+ fflush(stderr);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Disable Nagle buffering algo */
+ int flag = 1;
+ setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int));
+
+ struct sockaddr_in servername;
+ /* Connect to the server. */
+ init_sockaddr (&servername, SERVERHOST, PORT);
+ if ( 0 > connect(sock, (struct sockaddr *) &servername, sizeof (servername)) ) {
+ fprintf (stderr, "cannot connect to server.");
+ fflush(stderr);
+ exit (EXIT_FAILURE);
+ }
+
+ return sock;
+}
+
+/*
+ * main routine; renamed in this file to allow linking with other
+ * files
+ */
+
+int
+actual_main(int argc, char *argv[])
+{
+ int i;
+ int opt;
+ extern char *optarg;
+ char *tmp;
+ char optstr[256];
+ barrier_t *b;
+ long long startnsecs = getnsecs();
+
+#ifdef USE_RDTSC
+ if (getenv("LIBMICRO_HZ") == NULL) {
+ (void) printf("LIBMICRO_HZ needed but not set\n");
+ exit(1);
+ }
+ lm_hz = strtoll(getenv("LIBMICRO_HZ"), NULL, 10);
+#endif
+ char *port = getenv("ZXBENCH_PORT");
+ if (port != NULL){
+ PORT = atoi(port);
+ socket_on = 1;
+ }
+
+ lm_argc = argc;
+ lm_argv = argv;
+
+ /* before we do anything */
+ (void) benchmark_init();
+
+
+ nsecs_overhead = get_nsecs_overhead();
+ nsecs_resolution = get_nsecs_resolution();
+
+ /*
+ * Set defaults
+ */
+
+ lm_opt1 = lm_def1;
+ lm_optB = lm_defB;
+ lm_optD = lm_defD;
+ lm_optH = lm_defH;
+ lm_optN = lm_defN;
+ lm_optP = lm_defP;
+
+ lm_optS = lm_defS;
+ lm_optT = lm_defT;
+
+ /*
+ * squirrel away the path to the current
+ * binary in a way that works on both
+ * Linux and Solaris
+ */
+
+ if (*argv[0] == '/') {
+ lm_procpath = strdup(argv[0]);
+ *strrchr(lm_procpath, '/') = 0;
+ } else {
+ char path[1024];
+ (void) getcwd(path, 1024);
+ (void) strcat(path, "/");
+ (void) strcat(path, argv[0]);
+ *strrchr(path, '/') = 0;
+ lm_procpath = strdup(path);
+ }
+
+ /*
+ * name of binary
+ */
+
+ if ((tmp = strrchr(argv[0], '/')) == NULL)
+ (void) strcpy(lm_procname, argv[0]);
+ else
+ (void) strcpy(lm_procname, tmp + 1);
+
+ if (lm_optN == NULL) {
+ lm_optN = lm_procname;
+ }
+
+ /*
+ * Parse command line arguments
+ */
+
+ (void) sprintf(optstr, "1AB:C:D:EHI:LMN:P:RST:VW?%s", lm_optstr);
+ while ((opt = getopt(argc, argv, optstr)) != -1) {
+ switch (opt) {
+ case '1':
+ lm_opt1 = 1;
+ break;
+ case 'A':
+ lm_optA = 1;
+ break;
+ case 'B':
+ lm_optB = sizetoint(optarg);
+ break;
+ case 'C':
+ lm_optC = sizetoint(optarg);
+ break;
+ case 'D':
+ lm_optD = sizetoint(optarg);
+ break;
+ case 'E':
+ lm_optE = 1;
+ break;
+ case 'H':
+ lm_optH = 1;
+ break;
+ case 'I':
+ lm_optI = sizetoint(optarg);
+ break;
+ case 'L':
+ lm_optL = 1;
+ break;
+ case 'M':
+ lm_optM = 1;
+ break;
+ case 'N':
+ lm_optN = optarg;
+ break;
+ case 'P':
+ lm_optP = sizetoint(optarg);
+ break;
+ case 'S':
+ lm_optS = 1;
+ break;
+ case 'T':
+ lm_optT = sizetoint(optarg);
+ break;
+ case 'V':
+ (void) printf("%s\n", LIBMICRO_VERSION);
+ exit(0);
+ break;
+ case 'W':
+ lm_optW = 1;
+ lm_optS = 1;
+ break;
+ case '?':
+ usage();
+ exit(0);
+ break;
+ default:
+ if (benchmark_optswitch(opt, optarg) == -1) {
+ usage();
+ exit(0);
+ }
+ }
+ }
+
+ /* deal with implicit and overriding options */
+ if (lm_opt1 && lm_optP > 1) {
+ lm_optP = 1;
+ (void) printf("warning: -1 overrides -P\n");
+ }
+
+ if (lm_optE) {
+ (void) fprintf(stderr, "Running:%20s", lm_optN);
+ (void) fflush(stderr);
+ }
+
+ if (lm_optB == 0) {
+ /*
+ * neither benchmark or user has specified the number
+ * of cnts/sample, so use computed value
+ */
+ if (lm_optI)
+ lm_nsecs_per_op = lm_optI;
+
+ lm_optB = nsecs_resolution * 100 / lm_nsecs_per_op;
+ if (lm_optB == 0)
+ lm_optB = 1;
+ }
+
+ /*
+ * now that the options are set
+ */
+
+ if (benchmark_initrun() == -1) {
+ exit(1);
+ }
+
+ /* allocate dynamic data */
+ pids = (pid_t *)malloc(lm_optP * sizeof (pid_t));
+ if (pids == NULL) {
+ perror("malloc(pids)");
+ exit(1);
+ }
+ tids = (pthread_t *)malloc(lm_optT * sizeof (pthread_t));
+ if (tids == NULL) {
+ perror("malloc(tids)");
+ exit(1);
+ }
+
+ /* check that the case defines lm_tsdsize before proceeding */
+ if (lm_tsdsize == (size_t)-1) {
+ (void) fprintf(stderr, "error in benchmark_init: "
+ "lm_tsdsize not set\n");
+ exit(1);
+ }
+
+ /* round up tsdsize to nearest 128 to eliminate false sharing */
+ tsdsize = ((lm_tsdsize + 127) / 128) * 128;
+
+ /* allocate sufficient TSD for each thread in each process */
+ tsdseg = (void *)mmap(NULL, lm_optT * lm_optP * tsdsize + 8192,
+ PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0L);
+ if (tsdseg == NULL) {
+ perror("mmap(tsd)");
+ exit(1);
+ }
+
+ /* initialise worker synchronisation */
+ b = barrier_create(lm_optT * lm_optP, DATASIZE);
+ if (b == NULL) {
+ perror("barrier_create()");
+ exit(1);
+ }
+ lm_barrier = b;
+ b->ba_flag = 1;
+
+ /* need this here so that parent and children can call exit() */
+ (void) fflush(stdout);
+ (void) fflush(stderr);
+
+ // open socket here
+ if(socket_on ==1)
+ SOCK = make_socket();
+
+ /* when we started and when to stop */
+
+ b->ba_starttime = getnsecs();
+ b->ba_deadline = (long long) (b->ba_starttime + (lm_optD * 1000000LL));
+
+ /* do the work */
+ if (lm_opt1) {
+ /* single process, non-fork mode */
+ pindex = 0;
+ worker_process();
+ } else {
+ /* create worker processes */
+ for (i = 0; i < lm_optP; i++) {
+ pids[i] = fork();
+
+ switch (pids[i]) {
+ case 0:
+ pindex = i;
+ worker_process();
+ if(socket_on ==1)
+ close(SOCK);
+ exit(0);
+ break;
+ case -1:
+ perror("fork");
+ if(socket_on ==1)
+ close(SOCK);
+ exit(1);
+ break;
+ default:
+ continue;
+ }
+ }
+
+ /* wait for worker processes */
+ for (i = 0; i < lm_optP; i++) {
+ if (pids[i] > 0) {
+ (void) waitpid(pids[i], NULL, 0);
+ }
+ }
+ }
+
+ b->ba_endtime = getnsecs();
+
+ /* compute results */
+
+ compute_stats(b);
+
+ /* print arguments benchmark was invoked with ? */
+ if (lm_optL) {
+ int l;
+ (void) printf("# %s ", argv[0]);
+ for (l = 1; l < argc; l++) {
+ (void) printf("%s ", argv[l]);
+ }
+ (void) printf("\n");
+ }
+
+ /* print result header (unless suppressed) */
+ if (!lm_optH) {
+ (void) printf("%12s %3s %3s %12s %12s %8s %8s %s\n",
+ "", "prc", "thr",
+ "usecs/call",
+ "samples", "errors", "cnt/samp", lm_header);
+ }
+
+ /* print result */
+
+ (void) printf("%-12s %3d %3d %12.5f %12d %8lld %8d %s\n",
+ lm_optN, lm_optP, lm_optT,
+ (lm_optM?b->ba_corrected.st_mean:b->ba_corrected.st_median),
+ b->ba_batches, b->ba_errors, lm_optB,
+ benchmark_result());
+
+ if (lm_optS) {
+ print_stats(b);
+ }
+
+ /* just incase something goes awry */
+ (void) fflush(stdout);
+ (void) fflush(stderr);
+
+ /* cleanup by stages */
+ (void) benchmark_finirun();
+ (void) barrier_destroy(b);
+ (void) benchmark_fini();
+
+ if (lm_optE) {
+ (void) fprintf(stderr, " for %12.5f seconds\n",
+ (double)(getnsecs() - startnsecs) /
+ 1.e9);
+ (void) fflush(stderr);
+ }
+ if(socket_on ==1)
+ close(SOCK);
+ return (0);
+}
+
+void *
+worker_thread(void *arg)
+{
+ result_t r;
+ long long last_sleep = 0;
+ long long t;
+
+ r.re_errors = benchmark_initworker(arg);
+
+ while (lm_barrier->ba_flag) {
+ r.re_count = 0;
+ r.re_errors += benchmark_initbatch(arg);
+
+ /* sync to clock */
+
+ if (lm_optA && ((t = getnsecs()) - last_sleep) > 75000000LL) {
+ (void) poll(0, 0, 10);
+ last_sleep = t;
+ }
+ /* wait for it ... */
+ (void) barrier_queue(lm_barrier, NULL);
+
+ /* time the test */
+ r.re_t0 = getnsecs();
+ (void) benchmark(arg, &r);
+ r.re_t1 = getnsecs();
+
+ /* time to stop? */
+ if (r.re_t1 > lm_barrier->ba_deadline &&
+ (!lm_optC || lm_optC < lm_barrier->ba_batches)) {
+ lm_barrier->ba_flag = 0;
+ }
+
+ /* record results and sync */
+ (void) barrier_queue(lm_barrier, &r);
+
+ (void) benchmark_finibatch(arg);
+
+ r.re_errors = 0;
+ }
+
+ (void) benchmark_finiworker(arg);
+
+ return (0);
+}
+
+void
+worker_process()
+{
+ int i;
+ void *tsd;
+
+ for (i = 1; i < lm_optT; i++) {
+ tsd = gettsd(pindex, i);
+ if (pthread_create(&tids[i], NULL, worker_thread, tsd) != 0) {
+ perror("pthread_create");
+ exit(1);
+ }
+ }
+
+ tsd = gettsd(pindex, 0);
+ (void) worker_thread(tsd);
+
+ for (i = 1; i < lm_optT; i++) {
+ (void) pthread_join(tids[i], NULL);
+ }
+}
+
+void
+usage()
+{
+ (void) printf(
+ "usage: %s\n"
+ " [-1] (single process; overrides -P > 1)\n"
+ " [-A] (align with clock)\n"
+ " [-B batch-size (default %d)]\n"
+ " [-C minimum number of samples (default 0)]\n"
+ " [-D duration in msecs (default %ds)]\n"
+ " [-E (echo name to stderr)]\n"
+ " [-H] (suppress headers)\n"
+ " [-I] nsecs per op (used to compute batch size)"
+ " [-L] (print argument line)\n"
+ " [-M] (reports mean rather than median)\n"
+ " [-N test-name (default '%s')]\n"
+ " [-P processes (default %d)]\n"
+ " [-S] (print detailed stats)\n"
+ " [-T threads (default %d)]\n"
+ " [-V] (print the libMicro version and exit)\n"
+ " [-W] (flag possible benchmark problems)\n"
+ "%s\n",
+ lm_procname,
+ lm_defB, lm_defD, lm_procname, lm_defP, lm_defT,
+ lm_usage);
+}
+
+void
+print_warnings(barrier_t *b)
+{
+ int head = 0;
+ int increase;
+
+ if (b->ba_quant) {
+ if (!head++) {
+ (void) printf("#\n# WARNINGS\n");
+ }
+ increase = (int)(floor((nsecs_resolution * 100.0) /
+ ((double)lm_optB * b->ba_corrected.st_median * 1000.0)) +
+ 1.0);
+ (void) printf("# Quantization error likely;"
+ "increase batch size (-B option) %dX to avoid.\n",
+ increase);
+ }
+
+ /*
+ * XXX should warn on median != mean by a lot
+ */
+
+ if (b->ba_errors) {
+ if (!head++) {
+ (void) printf("#\n# WARNINGS\n");
+ }
+ (void) printf("# Errors occured during benchmark.\n");
+ }
+}
+
+void
+print_stats(barrier_t *b)
+{
+ (void) printf("#\n");
+ (void) printf("# STATISTICS %7s %7s\n",
+ "usecs/call (raw)",
+ "usecs/call (outliers removed)");
+
+ if (b->ba_count == 0) {
+ (void) printf("zero samples\n");
+ return;
+ }
+
+ (void) printf(" min %7.3f %7.3f\n",
+ b->ba_raw.st_min,
+ b->ba_corrected.st_min);
+
+ (void) printf(" max %7.3f %7.3f\n",
+ b->ba_raw.st_max,
+ b->ba_corrected.st_max);
+ (void) printf(" mean %7.3f %7.3f\n",
+ b->ba_raw.st_mean,
+ b->ba_corrected.st_mean);
+ (void) printf(" median %7.3f %7.3f\n",
+ b->ba_raw.st_median,
+ b->ba_corrected.st_median);
+ (void) printf(" stddev %7.3f %7.3f\n",
+ b->ba_raw.st_stddev,
+ b->ba_corrected.st_stddev);
+ (void) printf(" standard error %7.3f %7.3f\n",
+ b->ba_raw.st_stderr,
+ b->ba_corrected.st_stderr);
+ (void) printf(" 99%% conf level %7.3f %7.3f\n",
+ b->ba_raw.st_99confidence,
+ b->ba_corrected.st_99confidence);
+ (void) printf(" skew %7.3f %7.3f\n",
+ b->ba_raw.st_skew,
+ b->ba_corrected.st_skew);
+ (void) printf(" kurtosis %7.3f %7.3f\n",
+ b->ba_raw.st_kurtosis,
+ b->ba_corrected.st_kurtosis);
+
+ (void) printf(" T correlation %7.3f %7.3f\n",
+ b->ba_raw.st_timecorr,
+ b->ba_corrected.st_timecorr);
+ (void) printf("#\n");
+
+ (void) printf("# elasped time %7.3f\n", (b->ba_endtime -
+ b->ba_starttime) / 1.0e9);
+ (void) printf("# number of samples %7d\n", b->ba_batches);
+ (void) printf("# number of outliers %7d\n", b->ba_outliers);
+ (void) printf("# getnsecs overhead %7d\n", (int)nsecs_overhead);
+
+ (void) printf("#\n");
+ (void) printf("# DISTRIBUTION\n");
+
+ print_histo(b);
+
+ if (lm_optW) {
+ print_warnings(b);
+ }
+}
+
+void
+update_stats(barrier_t *b, result_t *r)
+{
+ double time;
+ double nsecs_per_call;
+
+ if (b->ba_waiters == 0) {
+ /* first thread only */
+ b->ba_t0 = r->re_t0;
+ b->ba_t1 = r->re_t1;
+ b->ba_count0 = 0;
+ b->ba_errors0 = 0;
+ } else {
+ /* all but first thread */
+ if (r->re_t0 < b->ba_t0) {
+ b->ba_t0 = r->re_t0;
+ }
+ if (r->re_t1 > b->ba_t1) {
+ b->ba_t1 = r->re_t1;
+ }
+ }
+
+ b->ba_count0 += r->re_count;
+ b->ba_errors0 += r->re_errors;
+
+ if (b->ba_waiters == b->ba_hwm - 1) {
+ /* last thread only */
+
+
+ time = (double)b->ba_t1 - (double)b->ba_t0 -
+ (double)nsecs_overhead;
+
+ if (time < 100 * nsecs_resolution)
+ b->ba_quant++;
+
+ /*
+ * normalize by procs * threads if not -U
+ */
+
+ nsecs_per_call = time / (double)b->ba_count0 *
+ (double)(lm_optT * lm_optP);
+
+ b->ba_count += b->ba_count0;
+ b->ba_errors += b->ba_errors0;
+
+ b->ba_data[b->ba_batches % b->ba_datasize] =
+ nsecs_per_call;
+ //TODO sock here
+ if(socket_on == 1) {
+ char message[64];
+ sprintf(message, "%s\t%f\n", lm_optN, nsecs_per_call);
+ write (SOCK, message, strlen(message));
+ }
+
+ b->ba_batches++;
+ }
+}
+
+#ifdef USE_SEMOP
+barrier_t *
+barrier_create(int hwm, int datasize)
+{
+ struct sembuf s[1];
+ barrier_t *b;
+
+ /*LINTED*/
+ b = (barrier_t *)mmap(NULL,
+ sizeof (barrier_t) + (datasize - 1) * sizeof (double),
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANON, -1, 0L);
+ if (b == (barrier_t *)MAP_FAILED) {
+ return (NULL);
+ }
+ b->ba_datasize = datasize;
+
+ b->ba_flag = 0;
+ b->ba_hwm = hwm;
+ b->ba_semid = semget(IPC_PRIVATE, 3, 0600);
+ if (b->ba_semid == -1) {
+ (void) munmap((void *)b, sizeof (barrier_t));
+ return (NULL);
+ }
+
+ /* [hwm - 1, 0, 0] */
+ s[0].sem_num = 0;
+ s[0].sem_op = hwm - 1;
+ s[0].sem_flg = 0;
+ if (semop(b->ba_semid, s, 1) == -1) {
+ perror("semop(1)");
+ (void) semctl(b->ba_semid, 0, IPC_RMID);
+ (void) munmap((void *)b, sizeof (barrier_t));
+ return (NULL);
+ }
+
+ b->ba_waiters = 0;
+ b->ba_phase = 0;
+
+ b->ba_count = 0;
+ b->ba_errors = 0;
+
+ return (b);
+}
+
+int
+barrier_destroy(barrier_t *b)
+{
+ (void) semctl(b->ba_semid, 0, IPC_RMID);
+ (void) munmap((void *)b, sizeof (barrier_t));
+
+ return (0);
+}
+
+int
+barrier_queue(barrier_t *b, result_t *r)
+{
+ struct sembuf s[2];
+
+ /*
+ * {s0(-(hwm-1))}
+ * if ! nowait {s1(-(hwm-1))}
+ * (all other threads)
+ * update shared stats
+ * {s0(hwm-1), s1(1)}
+ * {s0(1), s2(-1)}
+ * else
+ * (last thread)
+ * update shared stats
+ * {s2(hwm-1)}
+ */
+
+ s[0].sem_num = 0;
+ s[0].sem_op = -(b->ba_hwm - 1);
+ s[0].sem_flg = 0;
+ if (semop(b->ba_semid, s, 1) == -1) {
+ perror("semop(2)");
+ return (-1);
+ }
+
+ s[0].sem_num = 1;
+ s[0].sem_op = -(b->ba_hwm - 1);
+ s[0].sem_flg = IPC_NOWAIT;
+ if (semop(b->ba_semid, s, 1) == -1) {
+ if (errno != EAGAIN) {
+ perror("semop(3)");
+ return (-1);
+ }
+
+ /* all but the last thread */
+
+ if (r != NULL) {
+ update_stats(b, r);
+ }
+
+ b->ba_waiters++;
+
+ s[0].sem_num = 0;
+ s[0].sem_op = b->ba_hwm - 1;
+ s[0].sem_flg = 0;
+ s[1].sem_num = 1;
+ s[1].sem_op = 1;
+ s[1].sem_flg = 0;
+ if (semop(b->ba_semid, s, 2) == -1) {
+ perror("semop(4)");
+ return (-1);
+ }
+
+ s[0].sem_num = 0;
+ s[0].sem_op = 1;
+ s[0].sem_flg = 0;
+ s[1].sem_num = 2;
+ s[1].sem_op = -1;
+ s[1].sem_flg = 0;
+ if (semop(b->ba_semid, s, 2) == -1) {
+ perror("semop(5)");
+ return (-1);
+ }
+
+ } else {
+ /* the last thread */
+
+ if (r != NULL) {
+ update_stats(b, r);
+ }
+
+ b->ba_waiters = 0;
+ b->ba_phase++;
+
+ s[0].sem_num = 2;
+ s[0].sem_op = b->ba_hwm - 1;
+ s[0].sem_flg = 0;
+ if (semop(b->ba_semid, s, 1) == -1) {
+ perror("semop(6)");
+ return (-1);
+ }
+ }
+
+ return (0);
+}
+
+#else /* USE_SEMOP */
+
+barrier_t *
+barrier_create(int hwm, int datasize)
+{
+ pthread_mutexattr_t attr;
+ pthread_condattr_t cattr;
+ barrier_t *b;
+
+ /*LINTED*/
+ b = (barrier_t *)mmap(NULL,
+ sizeof (barrier_t) + (datasize - 1) * sizeof (double),
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED | MAP_ANON, -1, 0L);
+ if (b == (barrier_t *)MAP_FAILED) {
+ return (NULL);
+ }
+ b->ba_datasize = datasize;
+
+ b->ba_hwm = hwm;
+ b->ba_flag = 0;
+
+ (void) pthread_mutexattr_init(&attr);
+ (void) pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+
+ (void) pthread_mutex_init(&b->ba_lock, &attr);
+ (void) pthread_cond_init(&b->ba_cv, &cattr);
+
+ b->ba_waiters = 0;
+ b->ba_phase = 0;
+
+ b->ba_count = 0;
+ b->ba_errors = 0;
+
+ return (b);
+}
+
+int
+barrier_destroy(barrier_t *b)
+{
+ (void) munmap((void *)b, sizeof (barrier_t));
+
+ return (0);
+}
+
+int
+barrier_queue(barrier_t *b, result_t *r)
+{
+ int phase;
+
+ (void) pthread_mutex_lock(&b->ba_lock);
+
+ if (r != NULL) {
+ update_stats(b, r);
+ }
+
+ phase = b->ba_phase;
+
+ b->ba_waiters++;
+ if (b->ba_hwm == b->ba_waiters) {
+ b->ba_waiters = 0;
+ b->ba_phase++;
+ (void) pthread_cond_broadcast(&b->ba_cv);
+ }
+
+ while (b->ba_phase == phase) {
+ (void) pthread_cond_wait(&b->ba_cv, &b->ba_lock);
+ }
+
+ (void) pthread_mutex_unlock(&b->ba_lock);
+ return (0);
+}
+#endif /* USE_SEMOP */
+
+int
+gettindex()
+{
+ int i;
+
+ if (tids == NULL) {
+ return (-1);
+ }
+
+ for (i = 1; i < lm_optT; i++) {
+ if (pthread_self() == tids[i]) {
+ return (i);
+ }
+ }
+
+ return (0);
+}
+
+int
+getpindex()
+{
+ return (pindex);
+}
+
+void *
+gettsd(int p, int t)
+{
+ if ((p < 0) || (p >= lm_optP) || (t < 0) || (t >= lm_optT))
+ return (NULL);
+
+ return ((void *)((unsigned long)tsdseg +
+ (((p * lm_optT) + t) * tsdsize)));
+}
+
+#ifdef USE_GETHRTIME
+long long
+getnsecs()
+{
+ return (gethrtime());
+}
+
+long long
+getusecs()
+{
+ return (gethrtime() / 1000);
+}
+
+#elif USE_RDTSC /* USE_GETHRTIME */
+
+__inline__ long long
+rdtsc(void)
+{
+ unsigned long long x;
+ __asm__ volatile(".byte 0x0f, 0x31" : "=A" (x));
+ return (x);
+}
+
+long long
+getusecs()
+{
+ return (rdtsc() * 1000000 / lm_hz);
+}
+
+long long
+getnsecs()
+{
+ return (rdtsc() * 1000000000 / lm_hz);
+}
+
+#else /* USE_GETHRTIME */
+
+long long
+getusecs()
+{
+ struct timeval tv;
+
+ (void) gettimeofday(&tv, NULL);
+
+ return ((long long)tv.tv_sec * 1000000LL + (long long) tv.tv_usec);
+}
+
+long long
+getnsecs()
+{
+ struct timeval tv;
+
+ (void) gettimeofday(&tv, NULL);
+
+ return ((long long)tv.tv_sec * 1000000000LL +
+ (long long) tv.tv_usec * 1000LL);
+}
+
+#endif /* USE_GETHRTIME */
+
+int
+setfdlimit(int limit)
+{
+ struct rlimit rlimit;
+
+ if (getrlimit(RLIMIT_NOFILE, &rlimit) < 0) {
+ perror("getrlimit");
+ exit(1);
+ }
+
+ if (rlimit.rlim_cur > limit)
+ return (0); /* no worries */
+
+ rlimit.rlim_cur = limit;
+
+ if (rlimit.rlim_max < limit)
+ rlimit.rlim_max = limit;
+
+ if (setrlimit(RLIMIT_NOFILE, &rlimit) < 0) {
+ perror("setrlimit");
+ exit(3);
+ }
+
+ return (0);
+}
+
+
+#define KILOBYTE 1024
+#define MEGABYTE (KILOBYTE * KILOBYTE)
+#define GIGABYTE (KILOBYTE * MEGABYTE)
+
+long long
+sizetoll(const char *arg)
+{
+ int len = strlen(arg);
+ int i;
+ long long mult = 1;
+
+ if (len && isalpha(arg[len - 1])) {
+ switch (arg[len - 1]) {
+
+ case 'k':
+ case 'K':
+ mult = KILOBYTE;
+ break;
+ case 'm':
+ case 'M':
+ mult = MEGABYTE;
+ break;
+ case 'g':
+ case 'G':
+ mult = GIGABYTE;
+ break;
+ default:
+ return (-1);
+ }
+
+ for (i = 0; i < len - 1; i++)
+ if (!isdigit(arg[i]))
+ return (-1);
+ }
+
+ return (mult * strtoll(arg, NULL, 10));
+}
+
+int
+sizetoint(const char *arg)
+{
+ int len = strlen(arg);
+ int i;
+ long long mult = 1;
+
+ if (len && isalpha(arg[len - 1])) {
+ switch (arg[len - 1]) {
+
+ case 'k':
+ case 'K':
+ mult = KILOBYTE;
+ break;
+ case 'm':
+ case 'M':
+ mult = MEGABYTE;
+ break;
+ case 'g':
+ case 'G':
+ mult = GIGABYTE;
+ break;
+ default:
+ return (-1);
+ }
+
+ for (i = 0; i < len - 1; i++)
+ if (!isdigit(arg[i]))
+ return (-1);
+ }
+
+ return (mult * atoi(arg));
+}
+
+static void
+print_bar(long count, long total)
+{
+ int i;
+
+ (void) putchar_unlocked(count ? '*' : ' ');
+ for (i = 1; i < (12 * count) / total; i++)
+ (void) putchar_unlocked('*');
+ for (; i < 12; i++)
+ (void) putchar_unlocked(' ');
+}
+
+static int
+doublecmp(const void *p1, const void *p2)
+{
+ double a = *((double *)p1);
+ double b = *((double *)p2);
+
+ if (a > b)
+ return (1);
+ if (a < b)
+ return (-1);
+ return (0);
+}
+
+static void
+print_histo(barrier_t *b)
+{
+ int n;
+ int i;
+ int j;
+ int last;
+ long long maxcount;
+ double sum;
+ long long min;
+ long long scale;
+ double x;
+ long long y;
+ long long count;
+ int i95;
+ double p95;
+ double r95;
+ double m95;
+ histo_t *histo;
+
+ (void) printf("# %12s %12s %32s %12s\n", "counts", "usecs/call",
+ "", "means");
+
+ /* calculate how much data we've captured */
+ n = b->ba_batches > b->ba_datasize ? b->ba_datasize : b->ba_batches;
+
+ /* find the 95th percentile - index, value and range */
+ qsort((void *)b->ba_data, n, sizeof (double), doublecmp);
+ min = b->ba_data[0] + 0.000001;
+ i95 = n * 95 / 100;
+ p95 = b->ba_data[i95];
+ r95 = p95 - min + 1;
+
+ /* find a suitable min and scale */
+ i = 0;
+ x = r95 / (HISTOSIZE - 1);
+ while (x >= 10.0) {
+ x /= 10.0;
+ i++;
+ }
+ y = x + 0.9999999999;
+ while (i > 0) {
+ y *= 10;
+ i--;
+ }
+ min /= y;
+ min *= y;
+ scale = y * (HISTOSIZE - 1);
+ if (scale < (HISTOSIZE - 1)) {
+ scale = (HISTOSIZE - 1);
+ }
+
+ /* create and initialise the histogram */
+ histo = malloc(HISTOSIZE * sizeof (histo_t));
+ for (i = 0; i < HISTOSIZE; i++) {
+ histo[i].sum = 0.0;
+ histo[i].count = 0;
+ }
+
+ /* populate the histogram */
+ last = 0;
+ sum = 0.0;
+ count = 0;
+ for (i = 0; i < i95; i++) {
+ j = (HISTOSIZE - 1) * (b->ba_data[i] - min) / scale;
+
+ if (j >= HISTOSIZE) {
+ (void) printf("panic!\n");
+ j = HISTOSIZE - 1;
+ }
+
+ histo[j].sum += b->ba_data[i];
+ histo[j].count++;
+
+ sum += b->ba_data[i];
+ count++;
+ }
+ m95 = sum / count;
+
+ /* find the larges bucket */
+ maxcount = 0;
+ for (i = 0; i < HISTOSIZE; i++)
+ if (histo[i].count > 0) {
+ last = i;
+ if (histo[i].count > maxcount)
+ maxcount = histo[i].count;
+ }
+
+ /* print the buckets */
+ for (i = 0; i <= last; i++) {
+ (void) printf("%7lld %7.3f |", histo[i].count,
+ (min + scale * (double)i / (HISTOSIZE - 1)));
+
+ print_bar(histo[i].count, maxcount);
+
+ if (histo[i].count > 0)
+ (void) printf("%7.3f\n",
+ histo[i].sum / histo[i].count);
+ else
+ (void) printf("%7s\n", "-");
+ }
+
+ /* find the mean of values beyond the 95th percentile */
+ sum = 0.0;
+ count = 0;
+ for (i = i95; i < n; i++) {
+ sum += b->ba_data[i];
+ count++;
+ }
+
+ /* print the >95% bucket summary */
+ (void) printf("\n");
+ (void) printf("%7lld %7s |", count, "> 95%");
+ print_bar(count, maxcount);
+ if (count > 0)
+ (void) printf("%7.3f\n", sum / count);
+ else
+ (void) printf("%7s\n", "-");
+ (void) printf("\n");
+ (void) printf("%7s %7.3f\n", "mean of 95%", m95);
+ (void) printf("%7s %7.3f\n", "95th %ile", p95);
+
+ /* quantify any buffer overflow */
+ if (b->ba_batches > b->ba_datasize)
+ (void) printf("%7s %7d\n", "data dropped",
+ b->ba_batches - b->ba_datasize);
+}
+
+static void
+compute_stats(barrier_t *b)
+{
+ int i;
+
+ if (b->ba_batches > b->ba_datasize)
+ b->ba_batches = b->ba_datasize;
+
+ /*
+ * convert to usecs/call
+ */
+
+ for (i = 0; i < b->ba_batches; i++)
+ b->ba_data[i] /= 1000.0;
+
+ /*
+ * do raw stats
+ */
+
+ (void) crunch_stats(b->ba_data, b->ba_batches, &b->ba_raw);
+
+ /*
+ * recursively apply 3 sigma rule to remove outliers
+ */
+
+ b->ba_corrected = b->ba_raw;
+ b->ba_outliers = 0;
+
+ if (b->ba_batches > 40) { /* remove outliers */
+ int removed;
+
+ do {
+ removed = remove_outliers(b->ba_data, b->ba_batches,
+ &b->ba_corrected);
+ b->ba_outliers += removed;
+ b->ba_batches -= removed;
+ (void) crunch_stats(b->ba_data, b->ba_batches,
+ &b->ba_corrected);
+ } while (removed != 0 && b->ba_batches > 40);
+ }
+
+}
+
+/*
+ * routine to compute various statistics on array of doubles.
+ */
+
+static int
+crunch_stats(double *data, int count, stats_t *stats)
+{
+ double a;
+ double std;
+ double diff;
+ double sk;
+ double ku;
+ double mean;
+ int i;
+ int bytes;
+ double *dupdata;
+
+ /*
+ * first we need the mean
+ */
+
+ mean = 0.0;
+
+ for (i = 0; i < count; i++) {
+ mean += data[i];
+ }
+
+ mean /= count;
+
+ stats->st_mean = mean;
+
+ /*
+ * malloc and sort so we can do median
+ */
+
+ dupdata = malloc(bytes = sizeof (double) * count);
+ (void) memcpy(dupdata, data, bytes);
+ qsort((void *)dupdata, count, sizeof (double), doublecmp);
+ stats->st_median = dupdata[count/2];
+
+ /*
+ * reuse dupdata to compute time correlation of data to
+ * detect interesting time-based trends
+ */
+
+ for (i = 0; i < count; i++)
+ dupdata[i] = (double)i;
+
+ (void) fit_line(dupdata, data, count, &a, &stats->st_timecorr);
+ free(dupdata);
+
+ std = 0.0;
+ sk = 0.0;
+ ku = 0.0;
+
+ stats->st_max = -1;
+ stats->st_min = 1.0e99; /* hard to find portable values */
+
+ for (i = 0; i < count; i++) {
+ if (data[i] > stats->st_max)
+ stats->st_max = data[i];
+ if (data[i] < stats->st_min)
+ stats->st_min = data[i];
+
+ diff = data[i] - mean;
+ std += diff * diff;
+ sk += diff * diff * diff;
+ ku += diff * diff * diff * diff;
+ }
+
+ stats->st_stddev = std = sqrt(std/(double)(count - 1));
+ stats->st_stderr = std / sqrt(count);
+ stats->st_99confidence = stats->st_stderr * 2.326;
+ stats->st_skew = sk / (std * std * std) / (double)(count);
+ stats->st_kurtosis = ku / (std * std * std * std) /
+ (double)(count) - 3;
+
+ return (0);
+}
+
+/*
+ * does a least squares fit to the set of points x, y and
+ * fits a line y = a + bx. Returns a, b
+ */
+
+int
+fit_line(double *x, double *y, int count, double *a, double *b)
+{
+ double sumx, sumy, sumxy, sumx2;
+ double denom;
+ int i;
+
+ sumx = sumy = sumxy = sumx2 = 0.0;
+
+ for (i = 0; i < count; i++) {
+ sumx += x[i];
+ sumx2 += x[i] * x[i];
+ sumy += y[i];
+ sumxy += x[i] * y[i];
+ }
+
+ denom = count * sumx2 - sumx * sumx;
+
+ if (denom == 0.0)
+ return (-1);
+
+ *a = (sumy * sumx2 - sumx * sumxy) / denom;
+
+ *b = (count * sumxy - sumx * sumy) / denom;
+
+ return (0);
+}
+
+/*
+ * empty function for measurement purposes
+ */
+
+int
+nop()
+{
+ return (1);
+}
+
+#define NSECITER 1000
+
+static long long
+get_nsecs_overhead()
+{
+ long long s;
+
+ double data[NSECITER];
+ stats_t stats;
+
+ int i;
+ int count;
+ int outliers;
+
+ (void) getnsecs(); /* warmup */
+ (void) getnsecs(); /* warmup */
+ (void) getnsecs(); /* warmup */
+
+ i = 0;
+
+ count = NSECITER;
+
+ for (i = 0; i < count; i++) {
+ s = getnsecs();
+ data[i] = getnsecs() - s;
+ }
+
+ (void) crunch_stats(data, count, &stats);
+
+ while ((outliers = remove_outliers(data, count, &stats)) != 0) {
+ count -= outliers;
+ (void) crunch_stats(data, count, &stats);
+ }
+
+ return ((long long)stats.st_mean);
+
+}
+
+long long
+get_nsecs_resolution()
+{
+ long long y[1000];
+
+ int i, j, nops, res;
+ long long start, stop;
+
+ /*
+ * first, figure out how many nops to use
+ * to get any delta between time measurements.
+ * use a minimum of one.
+ */
+
+ /*
+ * warm cache
+ */
+
+ stop = start = getnsecs();
+
+ for (i = 1; i < 10000000; i++) {
+ start = getnsecs();
+ for (j = i; j; j--)
+ ;
+ stop = getnsecs();
+ if (stop > start)
+ break;
+ }
+
+ nops = i;
+
+ /*
+ * now collect data at linearly varying intervals
+ */
+
+ for (i = 0; i < 1000; i++) {
+ start = getnsecs();
+ for (j = nops * i; j; j--)
+ ;
+ stop = getnsecs();
+ y[i] = stop - start;
+ }
+
+ /*
+ * find smallest positive difference between samples;
+ * this is the timer resolution
+ */
+
+ res = 1<<30;
+
+ for (i = 1; i < 1000; i++) {
+ int diff = y[i] - y[i-1];
+
+ if (diff > 0 && res > diff)
+ res = diff;
+
+ }
+
+ return (res);
+}
+
+/*
+ * remove any data points from the array more than 3 sigma out
+ */
+
+static int
+remove_outliers(double *data, int count, stats_t *stats)
+{
+ double outmin = stats->st_mean - 3 * stats->st_stddev;
+ double outmax = stats->st_mean + 3 * stats->st_stddev;
+
+ int i, j, outliers;
+
+ for (outliers = i = j = 0; i < count; i++)
+ if (data[i] > outmax || data[i] < outmin)
+ outliers++;
+ else
+ data[j++] = data[i];
+
+ return (outliers);
+}
diff --git a/native/libMicro-0.4.0/libmicro.h b/native/libMicro-0.4.0/libmicro.h
new file mode 100644
index 0000000..892516d
--- /dev/null
+++ b/native/libMicro-0.4.0/libmicro.h
@@ -0,0 +1,196 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef LIBMICRO_H
+#define LIBMICRO_H
+
+#include <pthread.h>
+
+#define LIBMICRO_VERSION "0.4.0"
+
+#define STRSIZE 1024
+
+typedef struct {
+ long long re_count;
+ long long re_errors;
+ long long re_t0;
+ long long re_t1;
+} result_t;
+
+typedef struct {
+ double sum;
+ long long count;
+} histo_t;
+
+#define HISTOSIZE 32
+#define DATASIZE 100000
+
+/*
+ * stats we compute on data sets
+ */
+
+typedef struct stats {
+ double st_min;
+ double st_max;
+ double st_mean;
+ double st_median;
+ double st_stddev;
+ double st_stderr;
+ double st_99confidence;
+ double st_skew;
+ double st_kurtosis;
+ double st_timecorr; /* correlation with respect to time */
+} stats_t;
+
+/*
+ * Barrier stuff
+ */
+
+typedef struct {
+ int ba_hwm; /* barrier setpoint */
+ int ba_flag; /* benchmark while true */
+ long long ba_deadline; /* when to stop */
+ int ba_phase; /* number of time used */
+ int ba_waiters; /* how many are waiting */
+
+#ifdef USE_SEMOP
+ int ba_semid;
+#else
+ pthread_mutex_t ba_lock;
+ pthread_cond_t ba_cv;
+#endif
+
+ long long ba_count; /* how many ops */
+ long long ba_errors; /* how many errors */
+
+ int ba_quant; /* how many quant errors */
+ int ba_batches; /* how many samples */
+
+ double ba_starttime; /* test time start */
+ double ba_endtime; /* test time end */
+
+#ifdef NEVER
+ double ba_tmin; /* min time taken */
+ double ba_tmax; /* max time taken */
+ double ba_ctmax; /* max after outliers */
+ double ba_mean; /* average value */
+ double ba_median; /* median value */
+ double ba_rawmedian; /* raw median value */
+ double ba_stddev; /* standard deviation */
+ double ba_stderr; /* standard error */
+ double ba_skew; /* skew */
+ double ba_kurtosis; /* kurtosis */
+#endif
+ stats_t ba_raw; /* raw stats */
+ stats_t ba_corrected; /* corrected stats */
+
+ int ba_outliers; /* outlier count */
+
+ long long ba_t0; /* first thread/proc */
+ long long ba_t1; /* time of last thread */
+ long long ba_count0;
+ long long ba_errors0;
+
+ int ba_datasize; /* possible #items data */
+ double ba_data[1]; /* start of data ararry */
+} barrier_t;
+
+
+/*
+ * Barrier interfaces
+ */
+
+barrier_t *barrier_create(int hwm, int datasize);
+int barrier_destroy(barrier_t *bar);
+int barrier_queue(barrier_t *bar, result_t *res);
+
+
+/*
+ * Functions that can be provided by the user
+ */
+
+int benchmark(void *tsd, result_t *res);
+int benchmark_init();
+int benchmark_fini();
+int benchmark_initrun();
+int benchmark_finirun();
+int benchmark_initworker();
+int benchmark_finiworker();
+int benchmark_initbatch(void *tsd);
+int benchmark_finibatch(void *tsd);
+int benchmark_optswitch(int opt, char *optarg);
+char *benchmark_result();
+
+
+/*
+ * Globals exported to the user
+ */
+
+extern int lm_argc;
+extern char **lm_argv;
+
+extern int lm_optB;
+extern int lm_optD;
+extern int lm_optH;
+extern char *lm_optN;
+extern int lm_optP;
+extern int lm_optS;
+extern int lm_optT;
+
+extern int lm_defB;
+extern int lm_defD;
+extern int lm_defH;
+extern char *lm_defN;
+extern int lm_defP;
+extern int lm_defS;
+extern int lm_defT;
+extern int lm_nsecs_per_op;
+
+extern char *lm_procpath;
+extern char lm_procname[STRSIZE];
+extern char lm_usage[STRSIZE];
+extern char lm_optstr[STRSIZE];
+extern char lm_header[STRSIZE];
+extern size_t lm_tsdsize;
+
+
+/*
+ * Utility functions
+ */
+
+int getpindex();
+int gettindex();
+void *gettsd(int p, int t);
+long long getusecs();
+long long getnsecs();
+int setfdlimit(int limit);
+long long sizetoll();
+int sizetoint();
+int fit_line(double *, double *, int, double *, double *);
+long long get_nsecs_resolution();
+
+#endif /* LIBMICRO_H */
diff --git a/native/libMicro-0.4.0/libmicro_main.c b/native/libMicro-0.4.0/libmicro_main.c
new file mode 100644
index 0000000..f7bcde1
--- /dev/null
+++ b/native/libMicro-0.4.0/libmicro_main.c
@@ -0,0 +1,44 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Separate file for main so we can link other programs
+ * with libmicro
+ */
+
+#include <stdlib.h>
+
+extern int actual_main(int, char **);
+
+int
+main(int argc, char *argv[])
+{
+ return (actual_main(argc, argv));
+}
diff --git a/native/libMicro-0.4.0/listen.c b/native/libMicro-0.4.0/listen.c
new file mode 100644
index 0000000..f8730d7
--- /dev/null
+++ b/native/libMicro-0.4.0/listen.c
@@ -0,0 +1,127 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * listen benchmark
+ */
+
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "libmicro.h"
+
+#define FIRSTPORT 12345
+
+static struct sockaddr_in adds;
+static int sock = -1;
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "notes: measures listen()()\n");
+
+ lm_tsdsize = 0;
+
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ int j;
+ int opt = 1;
+ struct hostent *host;
+
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+ if (sock == -1) {
+ perror("socket");
+ exit(1);
+ }
+
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+ &opt, sizeof (int)) == -1) {
+ perror("setsockopt");
+ exit(1);
+ }
+
+ if ((host = gethostbyname("localhost")) == NULL) {
+ perror("gethostbyname");
+ exit(1);
+ }
+
+ j = FIRSTPORT;
+ for (;;) {
+ (void) memset(&adds, 0, sizeof (struct sockaddr_in));
+ adds.sin_family = AF_INET;
+ adds.sin_port = htons(j++);
+ (void) memcpy(&adds.sin_addr.s_addr, host->h_addr_list[0],
+ sizeof (struct in_addr));
+
+ if (bind(sock, (struct sockaddr *)&adds,
+ sizeof (struct sockaddr_in)) == 0) {
+ break;
+ }
+
+ if (errno != EADDRINUSE) {
+ perror("bind");
+ exit(1);
+ }
+ }
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+
+ for (i = 0; i < lm_optB; i += 2) {
+ if (listen(sock, 4) == -1)
+ res->re_errors++;
+ if (listen(sock, 5) == -1)
+ res->re_errors++;
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/localtime_r.c b/native/libMicro-0.4.0/localtime_r.c
new file mode 100644
index 0000000..8430884
--- /dev/null
+++ b/native/libMicro-0.4.0/localtime_r.c
@@ -0,0 +1,75 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * localtime benchmark
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "notes: measures localtime_r()\n");
+ lm_tsdsize = 0;
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ struct tm tms;
+ static time_t clock1 = 0L;
+ static time_t clock2 = 1L;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ (void) localtime_r(&clock1, &tms);
+ (void) localtime_r(&clock2, &tms);
+ (void) localtime_r(&clock1, &tms);
+ (void) localtime_r(&clock2, &tms);
+ (void) localtime_r(&clock1, &tms);
+ (void) localtime_r(&clock2, &tms);
+ (void) localtime_r(&clock1, &tms);
+ (void) localtime_r(&clock2, &tms);
+ (void) localtime_r(&clock1, &tms);
+ (void) localtime_r(&clock2, &tms);
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/log.c b/native/libMicro-0.4.0/log.c
new file mode 100644
index 0000000..0b4605f
--- /dev/null
+++ b/native/libMicro-0.4.0/log.c
@@ -0,0 +1,73 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * log benchmark - should do wider range...
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "note: measures log()");
+ lm_nsecs_per_op = 75;
+ lm_tsdsize = 0;
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ double value = i + .01;
+ (void) log(value);
+ (void) log(value);
+ (void) log(value);
+ (void) log(value);
+ (void) log(value);
+ (void) log(value);
+ (void) log(value);
+ (void) log(value);
+ (void) log(value);
+ (void) log(value);
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/longjmp.c b/native/libMicro-0.4.0/longjmp.c
new file mode 100644
index 0000000..50f4dbc
--- /dev/null
+++ b/native/libMicro-0.4.0/longjmp.c
@@ -0,0 +1,65 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * benchmark longjmp
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <setjmp.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "notes: measures longjmp()\n");
+ lm_tsdsize = 0;
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i = 0;
+ jmp_buf env;
+
+ (void) setjmp(env);
+ i++;
+ if (i < lm_optB)
+ longjmp(env, 0);
+
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/lrand48.c b/native/libMicro-0.4.0/lrand48.c
new file mode 100644
index 0000000..e82ddfd
--- /dev/null
+++ b/native/libMicro-0.4.0/lrand48.c
@@ -0,0 +1,71 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * lrand48
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "note: measures lrand48()");
+ lm_nsecs_per_op = 10;
+ lm_tsdsize = 0;
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ (void) lrand48();
+ (void) lrand48();
+ (void) lrand48();
+ (void) lrand48();
+ (void) lrand48();
+ (void) lrand48();
+ (void) lrand48();
+ (void) lrand48();
+ (void) lrand48();
+ (void) lrand48();
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/lseek.c b/native/libMicro-0.4.0/lseek.c
new file mode 100644
index 0000000..6ca4af4
--- /dev/null
+++ b/native/libMicro-0.4.0/lseek.c
@@ -0,0 +1,130 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * lseek
+ */
+
+#ifdef linux
+#define _XOPEN_SOURCE 500
+#endif
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "libmicro.h"
+
+#define DEFF "/dev/zero"
+#define DEFS 1024
+
+static char *optf = DEFF;
+static long long opts = DEFS;
+
+typedef struct {
+ int ts_once;
+ int ts_fd;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "f:s:");
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-read (default %s)]\n"
+ " [-s buffer-size (default %d)]\n"
+ "notes: measures lseek()\n",
+ DEFF, DEFS);
+
+ (void) sprintf(lm_header, "%8s", "size");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf = optarg;
+ break;
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ if (ts->ts_once++ == 0) {
+ ts->ts_fd = open(optf, O_RDONLY);
+ }
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i += 2) {
+ if (lseek(ts->ts_fd, 0L, SEEK_SET) != 0) {
+ res->re_errors++;
+ }
+ if (lseek(ts->ts_fd, opts, SEEK_SET) != opts) {
+ res->re_errors++;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%8lld", opts);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/malloc.c b/native/libMicro-0.4.0/malloc.c
new file mode 100644
index 0000000..6ccc52b
--- /dev/null
+++ b/native/libMicro-0.4.0/malloc.c
@@ -0,0 +1,139 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * malloc benchmark (crude)
+ */
+
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+
+#include "libmicro.h"
+
+static int optg = 100;
+static int opts[32] = {32};
+static int optscnt = 0;
+
+typedef struct {
+ void **ts_glob;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "s:g:");
+
+ (void) sprintf(lm_usage,
+ " [-g number of mallocs before free (default %d)]\n"
+ " [-s size to malloc (default %d)."
+ " Up to 32 sizes accepted\n"
+ "notes: measures malloc()/free()",
+ optg, opts[0]);
+
+ (void) sprintf(lm_header, "%6s %6s", "glob", "sizes");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'g':
+ optg = sizetoint(optarg);
+ break;
+ case 's':
+ opts[optscnt] = sizetoint(optarg);
+ optscnt = optscnt + 1;
+ optscnt = optscnt & (31);
+ break;
+ default:
+ return (-1);
+ }
+
+ return (0);
+}
+
+int
+benchmark_initworker(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ if (optscnt == 0)
+ optscnt = 1;
+
+ ts->ts_glob = malloc(sizeof (void *)* optg);
+ if (ts->ts_glob == NULL) {
+ return (1);
+ }
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i, j, k;
+
+ for (i = 0; i < lm_optB; i++) {
+ for (k = j = 0; j < optg; j++) {
+ if ((ts->ts_glob[j] = malloc(opts[k++])) == NULL)
+ res->re_errors++;
+ if (k >= optscnt)
+ k = 0;
+ }
+ for (j = 0; j < optg; j++) {
+ free(ts->ts_glob[j]);
+ }
+ }
+
+ res->re_count = i * j;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+ int i;
+
+ (void) sprintf(result, "%6d ", optg);
+
+ for (i = 0; i < optscnt; i++)
+ (void) sprintf(result + strlen(result), "%d ", opts[i]);
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/memcpy.c b/native/libMicro-0.4.0/memcpy.c
new file mode 100644
index 0000000..9a9448c
--- /dev/null
+++ b/native/libMicro-0.4.0/memcpy.c
@@ -0,0 +1,160 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * memcpy
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "libmicro.h"
+
+#define DEFS 8192
+#define DEFR 1
+
+static long long opts = DEFS;
+static int optf;
+static int optt;
+static int opta;
+
+typedef struct {
+ char *ts_src;
+ char *ts_dest;
+ int ts_srcsize;
+ int ts_destsize;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "a:s:ft");
+
+ (void) sprintf(lm_usage,
+ " [-s buffer-size (default %d)]\n"
+ " [-a relative alignment (default page aligned)]\n"
+ " [-f (rotate \"from\" buffer to keep it out of cache)]\n"
+ " [-t (rotate \"to\" buffer to keep it out of cache)]\n"
+ "notes: measures memcpy()\n",
+ DEFS);
+
+ (void) sprintf(lm_header, "%8s", "size");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf++;
+ break;
+ case 't':
+ optt++;
+ break;
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ case 'a':
+ opta = sizetoint(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initworker(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ if (optf)
+ ts->ts_srcsize = 64 * 1024 * 1024;
+ else
+ ts->ts_srcsize = opts + opta;
+
+ if (optt)
+ ts->ts_destsize = 64 * 1024 * 1024;
+ else
+ ts->ts_destsize = (int)opts;
+
+
+ ts->ts_src = opta + (char *)valloc(ts->ts_srcsize);
+ ts->ts_dest = valloc(ts->ts_destsize);
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ char *src = ts->ts_src;
+ char *dest = ts->ts_dest;
+
+ int bump = (int)opts;
+
+ if (bump < 1024)
+ bump = 1024; /* avoid prefetched area */
+ for (i = 0; i < lm_optB; i++) {
+ (void) memcpy(dest, src, opts);
+ if (optf) {
+ src += bump;
+ if (src + opts > ts->ts_src + ts->ts_srcsize)
+ src = ts->ts_src;
+ }
+ if (optt) {
+ dest += bump;
+ if (dest + opts > ts->ts_dest + ts->ts_destsize)
+ dest = ts->ts_dest;
+ }
+ }
+
+ res->re_count = i;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%8lld", opts);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/memmove.c b/native/libMicro-0.4.0/memmove.c
new file mode 100644
index 0000000..822c885
--- /dev/null
+++ b/native/libMicro-0.4.0/memmove.c
@@ -0,0 +1,160 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * memmove
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "libmicro.h"
+
+#define DEFS 8192
+#define DEFR 1
+
+static long long opts = DEFS;
+static int optf;
+static int optt;
+static int opta;
+
+typedef struct {
+ char *ts_src;
+ char *ts_dest;
+ int ts_srcsize;
+ int ts_destsize;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "a:s:ft");
+
+ (void) sprintf(lm_usage,
+ " [-s buffer-size (default %d)]\n"
+ " [-a relative alignment (default page aligned)]\n"
+ " [-f (rotate \"from\" buffer to keep it out of cache)]\n"
+ " [-t (rotate \"to\" buffer to keep it out of cache)]\n"
+ "notes: measures memmove()\n",
+ DEFS);
+
+ (void) sprintf(lm_header, "%8s", "size");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf++;
+ break;
+ case 't':
+ optt++;
+ break;
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ case 'a':
+ opta = sizetoint(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initworker(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ if (optf)
+ ts->ts_srcsize = 64 * 1024 * 1024;
+ else
+ ts->ts_srcsize = opts + opta;
+
+ if (optt)
+ ts->ts_destsize = 64 * 1024 * 1024;
+ else
+ ts->ts_destsize = (int)opts;
+
+
+ ts->ts_src = opta + (char *)valloc(ts->ts_srcsize);
+ ts->ts_dest = valloc(ts->ts_destsize);
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ char *src = ts->ts_src;
+ char *dest = ts->ts_dest;
+
+ int bump = (int)opts;
+
+ if (bump < 1024)
+ bump = 1024; /* avoid prefetched area */
+ for (i = 0; i < lm_optB; i++) {
+ (void) memmove(dest, src, opts);
+ if (optf) {
+ src += bump;
+ if (src + opts > ts->ts_src + ts->ts_srcsize)
+ src = ts->ts_src;
+ }
+ if (optt) {
+ dest += bump;
+ if (dest + opts > ts->ts_dest + ts->ts_destsize)
+ dest = ts->ts_dest;
+ }
+ }
+
+ res->re_count = i;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%8lld", opts);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/memrand.c b/native/libMicro-0.4.0/memrand.c
new file mode 100644
index 0000000..13b403c
--- /dev/null
+++ b/native/libMicro-0.4.0/memrand.c
@@ -0,0 +1,146 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * memory access time check
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <string.h>
+
+#include "libmicro.h"
+
+static long opts = 1024*1024;
+
+typedef struct {
+ long **ts_data;
+ long ts_result;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "s:");
+
+ (void) sprintf(lm_usage,
+ " [-s size] number of bytes to "
+ " access (default %ld)\n"
+ "notes: measures \"random\" memory access times\n",
+ opts);
+
+ (void) sprintf(lm_header, "%8s", "size");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 's':
+ opts = sizetoint(optarg);
+ break;
+ default:
+ return (-1);
+ }
+
+ return (0);
+}
+
+int
+benchmark_initworker(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i, j;
+
+ ts->ts_data = malloc(opts);
+
+ if (ts->ts_data == NULL) {
+ return (1);
+ }
+
+ /*
+ * use lmbench style backwards stride
+ */
+
+ for (i = 0; i < opts / sizeof (long); i++) {
+ j = i - 128;
+ if (j < 0)
+ j = j + opts / sizeof (long);
+ ts->ts_data[i] = (long *)&(ts->ts_data[j]);
+ }
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ long **ptr = ts->ts_data;
+
+
+
+ for (i = 0; i < lm_optB; i += 10) {
+ ptr = (long **)*ptr;
+ ptr = (long **)*ptr;
+ ptr = (long **)*ptr;
+ ptr = (long **)*ptr;
+ ptr = (long **)*ptr;
+ ptr = (long **)*ptr;
+ ptr = (long **)*ptr;
+ ptr = (long **)*ptr;
+ ptr = (long **)*ptr;
+ ptr = (long **)*ptr;
+ }
+
+ ts->ts_result = (long)*ptr;
+
+ res->re_count = lm_optB;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%8ld ", opts);
+
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/memset.c b/native/libMicro-0.4.0/memset.c
new file mode 100644
index 0000000..4f28d26
--- /dev/null
+++ b/native/libMicro-0.4.0/memset.c
@@ -0,0 +1,169 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * memset
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "libmicro.h"
+
+#define DEFS 8192
+
+static long long opts = DEFS;
+static int opta = 0;
+static int optu = 0;
+
+static char *optas = "4k";
+
+typedef struct {
+ char *ts_buff;
+ int ts_size;
+ int ts_offset;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "a:us:");
+
+ (void) sprintf(lm_usage,
+ " [-s buffer-size (default %d)]\n"
+ " [-a alignment (force buffer alignment)]\n"
+ " [-u (try to always use uncached memory)]"
+ "notes: measures memset()\n",
+ DEFS);
+
+ (void) sprintf(lm_header, "%8s%16s", "size", "alignment");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'u':
+ optu = 1;
+ break;
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ case 'a':
+ opta = sizetoll(optarg);
+ if (opta > 4096)
+ opta = 0;
+ else
+ optas = optarg;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initworker(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int errors = 0;
+ int i;
+
+ if (optu) {
+ ts->ts_size = 1024 * 1024 * 64;
+ ts->ts_offset = opta;
+ } else {
+ ts->ts_size = opta + opts;
+ ts->ts_offset = opta;
+ }
+
+ if ((ts->ts_buff = (char *)valloc(ts->ts_size)) == NULL)
+ errors++;
+
+ for (i = 0; i < ts->ts_size; i++)
+ ts->ts_buff[i] = 0;
+ return (errors);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+
+
+ if (optu) {
+ char *buf = ts->ts_buff + ts->ts_offset;
+ char *end = ts->ts_buff + ts->ts_size;
+ int offset = ts->ts_offset;
+ for (i = 0; i < lm_optB; i ++) {
+ (void) memset(buf, 0, opts);
+ buf = (char *)(((unsigned long)buf + opts + 4095) &
+ ~4095) + offset;
+ if (buf + opts > end)
+ buf = ts->ts_buff + offset;
+ }
+ } else {
+ char *buf = ts->ts_buff + ts->ts_offset;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ (void) memset(buf, 0, opts);
+ (void) memset(buf, 0, opts);
+ (void) memset(buf, 0, opts);
+ (void) memset(buf, 0, opts);
+ (void) memset(buf, 0, opts);
+ (void) memset(buf, 0, opts);
+ (void) memset(buf, 0, opts);
+ (void) memset(buf, 0, opts);
+ (void) memset(buf, 0, opts);
+ (void) memset(buf, 0, opts);
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%8lld%12s", opts, optas);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/mk_tarball b/native/libMicro-0.4.0/mk_tarball
new file mode 100755
index 0000000..de56210
--- /dev/null
+++ b/native/libMicro-0.4.0/mk_tarball
@@ -0,0 +1,28 @@
+#!/bin/sh -x
+#
+# Copyright 2003 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+#
+# script to make tarball... args are contents to be inserted
+#
+
+libmicro_version=`bin/getpid -V`
+case $libmicro_version in
+[0-9]*)
+ ;;
+*)
+ echo "ERROR: cannot determine libMicro version"
+ exit 1
+esac
+dirname="libMicro-$libmicro_version"
+
+here=`pwd`
+target=$here/libMicro.tar
+tmpdir=/tmp/libmicro.$$
+mkdir -p $tmpdir/$dirname
+cp $* $tmpdir/$dirname
+cd $tmpdir
+tar cvf $target $dirname
+cd $here
+rm -rf $tmpdir
diff --git a/native/libMicro-0.4.0/mktime.c b/native/libMicro-0.4.0/mktime.c
new file mode 100644
index 0000000..615192e
--- /dev/null
+++ b/native/libMicro-0.4.0/mktime.c
@@ -0,0 +1,112 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * mktime
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ struct tm ts_tm1;
+ struct tm ts_tm2;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_usage,
+ "notes: measures mktime()\n");
+
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ time_t clock1;
+ time_t clock2;
+
+ clock1 = time(NULL);
+ clock2 = clock1 + 1;
+
+ (void) localtime_r(&clock1, &ts->ts_tm1);
+ (void) localtime_r(&clock2, &ts->ts_tm2);
+
+ return (0);
+}
+
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+ struct tm t1, t2;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ t1 = ts->ts_tm1;
+ t2 = ts->ts_tm2;
+ (void) mktime(&t1);
+ (void) mktime(&t2);
+
+ t1 = ts->ts_tm1;
+ t2 = ts->ts_tm2;
+ (void) mktime(&t1);
+ (void) mktime(&t2);
+
+ t1 = ts->ts_tm1;
+ t2 = ts->ts_tm2;
+ (void) mktime(&t1);
+ (void) mktime(&t2);
+
+ t1 = ts->ts_tm1;
+ t2 = ts->ts_tm2;
+ (void) mktime(&t1);
+ (void) mktime(&t2);
+
+ t1 = ts->ts_tm1;
+ t2 = ts->ts_tm2;
+ (void) mktime(&t1);
+ (void) mktime(&t2);
+ }
+ res->re_count = lm_optB;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/mmap.c b/native/libMicro-0.4.0/mmap.c
new file mode 100644
index 0000000..44b8b58
--- /dev/null
+++ b/native/libMicro-0.4.0/mmap.c
@@ -0,0 +1,198 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <sys/mman.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <strings.h>
+
+#include "libmicro.h"
+
+typedef volatile char vchar_t;
+
+typedef struct {
+ int ts_once;
+ vchar_t ** ts_map;
+ vchar_t ts_foo;
+} tsd_t;
+
+#define DEFF "/dev/zero"
+#define DEFL 8192
+
+static char *optf = DEFF;
+static long long optl = DEFL;
+static int optr = 0;
+static int opts = 0;
+static int optw = 0;
+static int fd = -1;
+static int anon = 0;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "f:l:rsw");
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-map (default %s)]\n"
+ " [-l mapping-length (default %d)]\n"
+ " [-r] (read a byte from each page)\n"
+ " [-w] (write a byte on each page)\n"
+ " [-s] (use MAP_SHARED)\n"
+ "notes: measures mmap()\n",
+ DEFF, DEFL);
+
+ (void) sprintf(lm_header, "%8s %5s", "length", "flags");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf = optarg;
+ anon = strcmp(optf, "MAP_ANON") == 0;
+ break;
+ case 'l':
+ optl = sizetoll(optarg);
+ break;
+ case 'r':
+ optr = 1;
+ break;
+ case 's':
+ opts = 1;
+ break;
+ case 'w':
+ optw = 1;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ if (!anon)
+ fd = open(optf, O_RDWR);
+
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int errors = 0;
+
+ if (ts->ts_once++ == 0) {
+ ts->ts_map = (vchar_t **)malloc(lm_optB * sizeof (void *));
+ if (ts->ts_map == NULL) {
+ errors++;
+ }
+ }
+
+ return (errors);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i, j;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (anon) {
+ ts->ts_map[i] = (vchar_t *)mmap(NULL, optl,
+ PROT_READ | PROT_WRITE,
+ MAP_ANON | (opts ? MAP_SHARED : MAP_PRIVATE),
+ -1, 0L);
+ } else {
+ ts->ts_map[i] = (vchar_t *)mmap(NULL, optl,
+ PROT_READ | PROT_WRITE,
+ opts ? MAP_SHARED : MAP_PRIVATE,
+ fd, 0L);
+ }
+
+ if (ts->ts_map[i] == MAP_FAILED) {
+ res->re_errors++;
+ continue;
+ }
+
+ if (optr) {
+ for (j = 0; j < optl; j += 4096) {
+ ts->ts_foo += ts->ts_map[i][j];
+ }
+ }
+ if (optw) {
+ for (j = 0; j < optl; j += 4096) {
+ ts->ts_map[i][j] = 1;
+ }
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+int
+benchmark_finibatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ (void) munmap((void *)ts->ts_map[i], optl);
+ }
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+ char flags[5];
+
+ flags[0] = anon ? 'a' : '-';
+ flags[1] = optr ? 'r' : '-';
+ flags[2] = optw ? 'w' : '-';
+ flags[3] = opts ? 's' : '-';
+ flags[4] = 0;
+
+ (void) sprintf(result, "%8lld %5s", optl, flags);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/mprotect.c b/native/libMicro-0.4.0/mprotect.c
new file mode 100644
index 0000000..5d08b9e
--- /dev/null
+++ b/native/libMicro-0.4.0/mprotect.c
@@ -0,0 +1,200 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <strings.h>
+
+#include "libmicro.h"
+
+typedef volatile char vchar_t;
+
+typedef struct {
+ int ts_batch;
+ int ts_res;
+} tsd_t;
+
+#define DEFF "/dev/zero"
+#define DEFL 8192
+
+static char *optf = DEFF;
+static long long optl = DEFL;
+static int optr = 0;
+static int optw = 0;
+static int opts = 0;
+static int optt = 0;
+static int fd = -1;
+static int anon = 0;
+static int foo = 0;
+static vchar_t *seg;
+static int pagesize;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "f:l:rstw");
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-map (default %s)]\n"
+ " [-l mapping-length (default %d)]\n"
+ " [-r] (read a byte from each page)\n"
+ " [-w] (write a byte on each page)\n"
+ " [-s] (use MAP_SHARED)\n"
+ " [-t] (touch each page after restoring permissions)\n"
+ "notes: measures mprotect()\n",
+ DEFF, DEFL);
+
+ (void) sprintf(lm_header, "%8s %5s", "size", "flags");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf = optarg;
+ anon = strcmp(optf, "MAP_ANON") == 0;
+ break;
+ case 'l':
+ optl = sizetoll(optarg);
+ break;
+ case 'r':
+ optr = 1;
+ break;
+ case 's':
+ opts = 1;
+ break;
+ case 't':
+ optt = 1;
+ break;
+ case 'w':
+ optw = 1;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ int flags;
+ int i;
+
+ if (!anon)
+ fd = open(optf, O_RDWR);
+
+ flags = opts ? MAP_SHARED : MAP_PRIVATE;
+ flags |= anon ? MAP_ANON : 0;
+
+ seg = (vchar_t *)mmap(NULL, lm_optB * optl, PROT_READ | PROT_WRITE,
+ flags, anon ? -1 : fd, 0L);
+
+ if (seg == MAP_FAILED) {
+ return (-1);
+ }
+
+ if (optr) {
+ for (i = 0; i < lm_optB * optl; i += 4096) {
+ foo += seg[i];
+ }
+ }
+
+ if (optw) {
+ for (i = 0; i < lm_optB * optl; i += 4096) {
+ seg[i] = 1;
+ }
+ }
+
+ pagesize = getpagesize();
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int us;
+ int prot = PROT_NONE;
+ int j, k;
+
+ us = (getpindex() * lm_optT) + gettindex();
+ for (i = 0; i < lm_optB; i++) {
+ switch ((us + ts->ts_batch + i) % 2) {
+ case 0:
+ prot = PROT_NONE;
+ if (optt) {
+ for (j = k = 0; j < optl; j += pagesize)
+ k += seg[i * optl + j];
+ ts->ts_res += k;
+ }
+ break;
+ default:
+ prot = PROT_READ | PROT_WRITE;
+ break;
+ }
+
+ if (mprotect((void *)&seg[i * optl], optl, prot) == -1) {
+ res->re_errors++;
+ }
+ }
+ res->re_count += lm_optB;
+ ts->ts_batch++;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+ char flags[6];
+
+ flags[0] = anon ? 'a' : '-';
+ flags[1] = optr ? 'r' : '-';
+ flags[2] = optw ? 'w' : '-';
+ flags[3] = opts ? 's' : '-';
+ flags[4] = optt ? 't' : '-';
+ flags[5] = 0;
+
+ (void) sprintf(result, "%8lld %5s", optl, flags);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/msync.c b/native/libMicro-0.4.0/msync.c
new file mode 100644
index 0000000..48b0510
--- /dev/null
+++ b/native/libMicro-0.4.0/msync.c
@@ -0,0 +1,190 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <sys/mman.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <strings.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ char *ts_map;
+ int ts_foo; /* defeat optimizers */
+} tsd_t;
+
+#define DEFF "/dev/zero"
+#define DEFL 8192
+
+static char *optf = DEFF;
+static long long optl = DEFL;
+static int optr = 0;
+static int opts = 0;
+static int optw = 0;
+static int opta = MS_SYNC;
+static int opti = 0;
+static int anon = 0;
+static int pagesize;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "af:il:rsw");
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-map (default %s)]\n"
+ " [-l mapping-length (default %d)]\n"
+ " [-r] (read a byte from each page between msyncs)\n"
+ " [-w] (write a byte to each page between msyncs)\n"
+ " [-s] (use MAP_SHARED instead of MAP_PRIVATE)\n"
+ " [-a (specify MS_ASYNC rather than default MS_SYNC)\n"
+ " [-i (specify MS_INVALIDATE)\n"
+ "notes: measures msync()\n",
+ DEFF, DEFL);
+
+ (void) sprintf(lm_header, "%8s %6s", "length", "flags");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'a':
+ opta = MS_ASYNC;
+ break;
+
+ case 'f':
+ optf = optarg;
+ break;
+
+ case 'i':
+ opti = MS_INVALIDATE;
+ break;
+
+ case 'l':
+ optl = sizetoll(optarg);
+ break;
+ case 'r':
+ optr = 1;
+ break;
+ case 's':
+ opts = 1;
+ break;
+ case 'w':
+ optw = 1;
+ break;
+ default:
+ return (-1);
+ }
+
+ pagesize = getpagesize();
+
+ return (0);
+}
+
+int
+benchmark_initworker(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ int fd;
+
+ if ((fd = open(optf, O_RDWR)) < 0) {
+ perror("open:");
+ return (1);
+ }
+
+ (void) ftruncate(fd, optl);
+
+ if ((ts->ts_map = (char *)mmap(NULL, optl,
+ PROT_READ | PROT_WRITE, opts ? MAP_SHARED : MAP_PRIVATE,
+ fd, 0L)) == MAP_FAILED) {
+ perror("mmap:");
+ (void) close(fd);
+ return (1);
+ }
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i, j;
+
+ for (i = 0; i < lm_optB; i++) {
+
+ if (msync(ts->ts_map, optl, opta | opti) < 0) {
+ perror("msync:");
+ res->re_errors++;
+ break;
+ }
+
+ if (optr) {
+ for (j = 0; j < optl; j += pagesize) {
+ ts->ts_foo += ts->ts_map[j];
+ }
+ }
+
+ if (optw) {
+ for (j = 0; j < optl; j += pagesize) {
+ ts->ts_map[j] = 1;
+ }
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+ char flags[6];
+
+ flags[0] = anon ? 'a' : '-';
+ flags[1] = optr ? 'r' : '-';
+ flags[2] = optw ? 'w' : '-';
+ flags[3] = opts ? 's' : '-';
+ flags[4] = opti ? 'i' : '-';
+ flags[5] = 0;
+
+ (void) sprintf(result, "%8lld %6s", optl, flags);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/multiview.sh b/native/libMicro-0.4.0/multiview.sh
new file mode 100644
index 0000000..75dea4b
--- /dev/null
+++ b/native/libMicro-0.4.0/multiview.sh
@@ -0,0 +1,201 @@
+#!/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms
+# of the Common Development and Distribution License
+# (the "License"). You may not use this file except
+# in compliance with the License.
+#
+# You can obtain a copy of the license at
+# src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL
+# HEADER in each file and include the License file at
+# usr/src/OPENSOLARIS.LICENSE. If applicable,
+# add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your
+# own identifying information: Portions Copyright [yyyy]
+# [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# output html comparison of several libmicro output data files
+# usage: multiview file1 file2 file3 file4 ...
+#
+# relative ranking is calculated using first as reference
+# color interpolation is done to indicate relative performance;
+# the redder the color, the slower the result, the greener the
+# faster
+
+/bin/nawk ' BEGIN {
+ benchmark_count = 0;
+ header_count = 0;
+}
+/^#/ {
+ continue;
+ }
+/errors/ {
+ continue;
+ }
+/^\!/ {
+ split($0, A_header, ":");
+ name = substr(A_header[1],2);
+ headers[name]=name;
+ header_data[name,FILENAME] = substr($0, length(name) + 3);
+ if (header_names[name] == 0) {
+ header_names[name] = ++header_count;
+ headers[header_count] = name;
+ }
+ continue;
+}
+
+ {
+ if(NF >= 7) {
+ if (benchmark_names[$1] == 0) {
+ benchmark_names[$1] = ++benchmark_count;
+ benchmarks[benchmark_count] = $1;
+ }
+ if ($6 == 0)
+ benchmark_data[$1,FILENAME] = $4;
+ else
+ benchmark_data[$1,FILENAME] = -1;
+ }
+}
+
+END {
+ printf("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n");
+ printf("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");
+ printf("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n");
+ printf("<head>\n");
+ printf("<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\" />\n");
+ printf("<meta name=\"author\" content=\"autogen\" />\n");
+ printf("<title>multiview comparison</title>\n")
+ printf("<style type=\"text/css\">\n");
+ printf("body { font-family: sans-serif; }\n");
+ printf("table { border-collapse: collapse; }\n");
+ printf("td { padding: 0.1em; border: 1px solid #ccc; text-align: right; }\n");
+ printf("td.header { text-align: left; }\n");
+ printf("pre { margin-top: 0em; margin-bottom: 0em; }\n");
+ printf("</style>\n");
+ printf("</head>\n");
+ printf("<body bgcolor=\"#ffffff\" link=\"#0000ee\" vlink=\"#cc0000\" alink=\"#0000ee\">\n");
+ printf("<table border=\"1\" cellspacing=\"1\">\n");
+ printf("<tbody>\n");
+ for(i = 1; i <= header_count; i++) {
+ hname = headers[i];
+ printf("<tr><td class=\"header\">%s</td>\n", hname);
+
+ for (j = 1; j < ARGC; j++) {
+ sub("^[\t ]+", "", header_data[hname, ARGV[j]]);
+ printf("<td class=\"header\">%s</td>\n", header_data[hname, ARGV[j]]);
+ }
+ printf("</tr>\n");
+ }
+ printf("<tr>\n");
+ printf("<th>BENCHMARK</th>\n");
+ printf("<th align=\"right\">USECS</th>\n");
+
+ for (i = 2; i < ARGC; i++)
+ printf("<th align=\"right\">USECS [percentage]</th>\n");
+
+ printf("</tr>\n");
+ for(i = 1; i < benchmark_count; i++) {
+ for(j = 1; j < benchmark_count; j++) {
+ if (benchmarks[j] > benchmarks[j + 1]) {
+ tmp = benchmarks[j];
+ benchmarks[j] = benchmarks[j+1];
+ benchmarks[j+1] = tmp;
+ }
+ }
+ }
+
+ for(i = 1; i <= benchmark_count; i++) {
+ name = benchmarks[i];
+ a = benchmark_data[name, ARGV[1]];
+
+ printf("<tr>\n");
+ printf("<td>%s</td>\n", name);
+ if (a > 0)
+ printf("<td><pre>%f</pre></td>\n", a);
+ else {
+ if (a < 0)
+ printf("<td bgcolor=\"#ff0000\">%s</td>\n", "ERRORS");
+ else
+ printf("<td>%s</td>\n", "missing");
+
+ for (j = 2; j < ARGC; j++)
+ printf("<td>%s</td>\n", "not computed");
+ continue;
+ }
+
+ for (j = 2; j < ARGC; j++) {
+ b = benchmark_data[name, ARGV[j]];
+ if (b > 0) {
+ factor = b/a;
+ bgcolor = colormap(factor);
+ if (factor > 1)
+ percentage = -(factor * 100 - 100);
+ if (factor <= 1)
+ percentage = 100/factor - 100;
+
+ printf("<td bgcolor=\"%s\"><pre>%11.5f[%#+7.1f%%]</pre></td>\n",
+ bgcolor, b, percentage);
+ }
+
+ else if (b < 0)
+ printf("<td bgcolor=\"#ff0000\">%s</td>\n", "ERRORS");
+ else
+ printf("<td>%25s</td>\n", "missing");
+
+ }
+ printf("</tr>\n");
+
+ }
+ printf("</tbody></table></body></html>\n");
+
+}
+
+function colormap(value, bgcolor, r, g, b)
+{
+ if (value <= .2)
+ value = .2;
+ if (value > 5)
+ value = 5;
+
+ if (value < .9) {
+ r = colorcalc(.2, value, .9, 0, 255);
+ g = colorcalc(.2, value, .9, 153, 255);
+ b = colorcalc(.2, value, .9, 0, 255);
+ bgcolor=sprintf("#%2.2x%2.2x%2.2x", r, g, b);
+ }
+ else if (value < 1.1)
+ bgcolor="#ffffff";
+ else {
+ r = 255;
+ g = colorcalc(1.1, value, 5, 255, 0);
+ b = colorcalc(1.1, value, 5, 255, 0);
+ bgcolor=sprintf("#%2.2x%2.2x%2.2x", r, g, b);
+ }
+
+ return (bgcolor);
+}
+
+function colorcalc(min, value, max, mincolor, maxcolor)
+{
+ return((value - min)/(max-min) * (maxcolor-mincolor) + mincolor);
+}
+
+' "$@"
+
+
diff --git a/native/libMicro-0.4.0/munmap.c b/native/libMicro-0.4.0/munmap.c
new file mode 100644
index 0000000..7979dbb
--- /dev/null
+++ b/native/libMicro-0.4.0/munmap.c
@@ -0,0 +1,192 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <strings.h>
+
+#include "libmicro.h"
+
+typedef volatile char vchar_t;
+
+typedef struct {
+ int ts_once;
+ vchar_t ** ts_map;
+ vchar_t ts_foo;
+} tsd_t;
+
+#define DEFF "/dev/zero"
+#define DEFL 8192
+
+static char *optf = DEFF;
+static long long optl = DEFL;
+static int optr = 0;
+static int optw = 0;
+static int opts = 0;
+static int fd = -1;
+static int anon = 0;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "f:l:rsw");
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-map (default %s)]\n"
+ " [-l mapping-length (default %d)]\n"
+ " [-r] (read a byte from each page)\n"
+ " [-w] (write a byte on each page)\n"
+ " [-s] (use MAP_SHARED)\n"
+ "notes: measures munmap()\n",
+ DEFF, DEFL);
+
+ (void) sprintf(lm_header, "%8s %5s", "size", "flags");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf = optarg;
+ anon = strcmp(optf, "MAP_ANON") == 0;
+ break;
+ case 'l':
+ optl = sizetoll(optarg);
+ break;
+ case 'r':
+ optr = 1;
+ break;
+ case 's':
+ opts = 1;
+ break;
+ case 'w':
+ optw = 1;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ if (!anon)
+ fd = open(optf, O_RDWR);
+
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i, j;
+ int errors = 0;
+
+ if (ts->ts_once++ == 0) {
+ ts->ts_map = (vchar_t **)malloc(lm_optB * sizeof (void *));
+ if (ts->ts_map == NULL) {
+ errors++;
+ }
+ }
+
+ for (i = 0; i < lm_optB; i++) {
+ if (anon) {
+ ts->ts_map[i] = (vchar_t *)mmap(NULL, optl,
+ PROT_READ | PROT_WRITE,
+ MAP_ANON | (opts ? MAP_SHARED : MAP_PRIVATE),
+ -1, 0L);
+ } else {
+ ts->ts_map[i] = (vchar_t *)mmap(NULL, optl,
+ PROT_READ | PROT_WRITE,
+ opts ? MAP_SHARED : MAP_PRIVATE,
+ fd, 0L);
+ }
+
+ if (ts->ts_map[i] == MAP_FAILED) {
+ errors++;
+ continue;
+ }
+ if (optr) {
+ for (j = 0; j < optl; j += 4096) {
+ ts->ts_foo += ts->ts_map[i][j];
+ }
+ }
+ if (optw) {
+ for (j = 0; j < optl; j += 4096) {
+ ts->ts_map[i][j] = 1;
+ }
+ }
+ }
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (munmap((void *)ts->ts_map[i], optl) == -1) {
+ res->re_errors++;
+ }
+ }
+ res->re_count += lm_optB;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+ char flags[5];
+
+ flags[0] = anon ? 'a' : '-';
+ flags[1] = optr ? 'r' : '-';
+ flags[2] = optw ? 'w' : '-';
+ flags[3] = opts ? 's' : '-';
+ flags[4] = 0;
+
+ (void) sprintf(result, "%8lld %5s", optl, flags);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/mutex.c b/native/libMicro-0.4.0/mutex.c
new file mode 100644
index 0000000..3c056af
--- /dev/null
+++ b/native/libMicro-0.4.0/mutex.c
@@ -0,0 +1,194 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * mutex
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <sys/mman.h>
+
+#include "libmicro.h"
+
+static int optt = 0;
+static int optp = 0;
+static int opth = 0;
+static int opto = 0;
+
+pthread_mutex_t *lock;
+
+typedef struct {
+ int ts_once;
+ pthread_mutex_t *ts_lock;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_usage,
+ " [-t] (create dummy thread so we are multithreaded)\n"
+ " [-p] (use inter-process mutex (not support everywhere))\n"
+ " [-h usecs] (specify mutex hold time (default 0)\n"
+ "notes: measures uncontended pthread_mutex_[un,]lock\n");
+
+ (void) sprintf(lm_optstr, "tph:o:");
+
+ (void) sprintf(lm_header, "%8s", "holdtime");
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'p':
+ optp = 1;
+ break;
+
+ case 't':
+ optt = 1;
+ break;
+
+ case 'h':
+ opth = sizetoint(optarg);
+ break;
+
+ case 'o':
+ opto = sizetoint(optarg);
+ break;
+
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+void *
+dummy(void *arg)
+{
+ (void) pause();
+ return (arg);
+}
+
+int
+benchmark_initrun()
+{
+ pthread_mutexattr_t attr;
+ int errors = 0;
+
+ /*LINTED*/
+ lock = (pthread_mutex_t *)mmap(NULL,
+ getpagesize(),
+ PROT_READ | PROT_WRITE,
+ optp?(MAP_ANON | MAP_SHARED):MAP_ANON|MAP_PRIVATE,
+ -1, 0L) + opto;
+
+ if (lock == MAP_FAILED) {
+ errors++;
+ } else {
+ (void) pthread_mutexattr_init(&attr);
+ if (optp)
+ (void) pthread_mutexattr_setpshared(&attr,
+ PTHREAD_PROCESS_SHARED);
+
+ if (pthread_mutex_init(lock, &attr) != 0)
+ errors++;
+ }
+
+ return (errors);
+}
+
+int
+benchmark_initworker(void *tsd)
+{
+ int errors = 0;
+ tsd_t *ts = (tsd_t *)tsd;
+
+
+ if (optt) {
+ pthread_t tid;
+
+
+
+ if (pthread_create(&tid, NULL, dummy, NULL) != 0) {
+ errors++;
+ }
+ }
+
+ ts->ts_lock = lock;
+
+ return (errors);
+}
+
+void
+spinme(int usecs)
+{
+ long long s = getusecs();
+
+ while (getusecs() - s < usecs)
+ ;
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i ++) {
+
+ (void) pthread_mutex_lock(ts->ts_lock);
+ if (opth)
+ spinme(opth);
+ (void) pthread_mutex_unlock(ts->ts_lock);
+
+ }
+
+ res->re_count = lm_optB;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%8d", opth);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/nop.c b/native/libMicro-0.4.0/nop.c
new file mode 100644
index 0000000..815691f
--- /dev/null
+++ b/native/libMicro-0.4.0/nop.c
@@ -0,0 +1,63 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * silly nop benchmark to test infrastructure
+ */
+
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "notes: measures nothing()\n");
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ int nop();
+
+ for (i = 0; i < lm_optB; i++)
+ (void) nop(); /* do nothing but the call */
+
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/open.c b/native/libMicro-0.4.0/open.c
new file mode 100644
index 0000000..7cdcd76
--- /dev/null
+++ b/native/libMicro-0.4.0/open.c
@@ -0,0 +1,138 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * benchmark open
+ */
+
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ int ts_once;
+ int *ts_fds;
+} tsd_t;
+
+#define DEFF "/dev/null"
+
+static char *optf = DEFF;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ lm_defB = 256;
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-open (default %s)]\n"
+ "notes: measures open()\n",
+ DEFF);
+
+ (void) sprintf(lm_optstr, "f:");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf = optarg;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ (void) setfdlimit(lm_optB * lm_optT + 10);
+
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int errors = 0;
+
+ if (ts->ts_once++ == 0) {
+ ts->ts_fds = (int *)malloc(lm_optB * sizeof (int));
+ if (ts->ts_fds == NULL) {
+ errors++;
+ }
+ for (i = 0; i < lm_optB; i++) {
+ ts->ts_fds[i] = -1;
+ }
+ }
+
+ return (errors);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ ts->ts_fds[i] = open(optf, O_RDONLY);
+ if (ts->ts_fds[i] < 0) {
+ res->re_errors++;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+int
+benchmark_finibatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ (void) close(ts->ts_fds[i]);
+ }
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/pipe.c b/native/libMicro-0.4.0/pipe.c
new file mode 100644
index 0000000..e873d9f
--- /dev/null
+++ b/native/libMicro-0.4.0/pipe.c
@@ -0,0 +1,566 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <pthread.h>
+#include <signal.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ int ts_once;
+ pid_t ts_child;
+ pthread_t ts_thread;
+ int ts_in;
+ int ts_out;
+ int ts_in2;
+ int ts_out2;
+ int ts_lsn;
+ struct sockaddr_in ts_add;
+} tsd_t;
+
+#define FIRSTPORT 12345
+
+static char *modes[] = {"st", "mt", "mp", NULL};
+#define MD_SINGLE 0
+#define MD_MULTITHREAD 1
+#define MD_MULTIPROCESS 2
+
+static char *xports[] = {"pipe", "fifo", "sock", "tcp",
+ NULL};
+#define XP_PIPES 0
+#define XP_FIFOS 1
+#define XP_SOCKETPAIR 2
+#define XP_LOCALTCP 3
+
+#define DEFM MD_SINGLE
+#define DEFS 1024
+#define DEFX XP_PIPES
+
+static int optm = DEFM;
+static size_t opts = DEFS;
+static int optx = DEFX;
+static void *rbuf = NULL;
+static void *wbuf = NULL;
+
+int readall(int s, void *buf, size_t len);
+void *loopback(void *arg);
+int prepare_pipes(tsd_t *tsd);
+int prepare_fifos(tsd_t *tsd);
+int cleanup_fifos(tsd_t *tsd);
+int prepare_socketpair(tsd_t *tsd);
+int prepare_localtcp(tsd_t *tsd);
+int prepare_localtcp_once(tsd_t *tsd);
+char *lookupa(int x, char *names[]);
+int lookup(char *x, char *names[]);
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "m:s:x:");
+
+ (void) sprintf(lm_usage,
+ " [-m mode (st|mt|mp, default %s)]\n"
+ " [-s buffer-size (default %d)]\n"
+ " [-x transport (pipe|fifo|sock|tcp, default %s)]\n"
+ "notes: measures write()/read() across various transports\n",
+ lookupa(DEFM, modes), DEFS, lookupa(DEFX, xports));
+
+ (void) sprintf(lm_header, "%2s %4s", "md", "xprt");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ int x;
+
+ switch (opt) {
+ case 'm':
+ x = lookup(optarg, modes);
+ if (x == -1)
+ return (-1);
+ optm = x;
+ break;
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ case 'x':
+ x = lookup(optarg, xports);
+ if (x == -1)
+ return (-1);
+ optx = x;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ if (optx == XP_FIFOS) {
+ if (geteuid() != 0) {
+ (void) printf("sorry, must be root to create fifos\n");
+ exit(1);
+ }
+ }
+
+ (void) setfdlimit(4 * lm_optT + 10);
+
+ rbuf = malloc(opts);
+ wbuf = malloc(opts);
+
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int result;
+ pid_t pid;
+ int i;
+
+ switch (optx) {
+ case XP_SOCKETPAIR:
+ result = prepare_socketpair(ts);
+ break;
+ case XP_LOCALTCP:
+ result = prepare_localtcp(ts);
+ break;
+ case XP_FIFOS:
+ result = prepare_fifos(ts);
+ break;
+ case XP_PIPES:
+ default:
+ result = prepare_pipes(ts);
+ break;
+ }
+ if (result == -1) {
+ return (1);
+ }
+
+ switch (optm) {
+ case MD_MULTITHREAD:
+ result = pthread_create(&ts->ts_thread, NULL, loopback, tsd);
+ if (result == -1) {
+ return (1);
+ }
+ break;
+ case MD_MULTIPROCESS:
+ pid = fork();
+ switch (pid) {
+ case 0:
+ (void) loopback(tsd);
+ exit(0);
+ break;
+ case -1:
+ return (-1);
+ default:
+ ts->ts_child = pid;
+ break;
+ }
+ break;
+ case MD_SINGLE:
+ default:
+ break;
+ }
+
+ /* Prime the loopback */
+ if (write(ts->ts_out, wbuf, opts) != opts) {
+ return (1);
+ }
+ if (readall(ts->ts_in, rbuf, opts) != opts) {
+ return (1);
+ }
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int n;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (write(ts->ts_out, wbuf, opts) != opts) {
+ res->re_errors++;
+ continue;
+ }
+
+ n = readall(ts->ts_in, rbuf, opts);
+ if (n == -1) {
+ res->re_errors++;
+ continue;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+int
+benchmark_finibatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ /* Terminate the loopback */
+ (void) write(ts->ts_out, wbuf, opts);
+ (void) readall(ts->ts_in, rbuf, opts);
+
+ switch (optm) {
+ case MD_MULTITHREAD:
+ (void) close(ts->ts_in2);
+ (void) close(ts->ts_out2);
+ (void) pthread_join(ts->ts_thread, NULL);
+ break;
+ case MD_MULTIPROCESS:
+ (void) close(ts->ts_in2);
+ (void) close(ts->ts_out2);
+ (void) waitpid(ts->ts_child, NULL, 0);
+ break;
+ case MD_SINGLE:
+ default:
+ break;
+ }
+
+ (void) close(ts->ts_in);
+ (void) close(ts->ts_out);
+
+ if (optx == XP_FIFOS) {
+ (void) cleanup_fifos(ts);
+ }
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%2s %4s",
+ lookupa(optm, modes), lookupa(optx, xports));
+
+ return (result);
+}
+
+int
+readall(int s, void *buf, size_t len)
+{
+ size_t n;
+ size_t total = 0;
+
+ for (;;) {
+ n = read(s, (void *)((long)buf + total), len - total);
+ if (n < 1) {
+ return (-1);
+ }
+ total += n;
+ if (total >= len) {
+ return (total);
+ }
+ }
+}
+
+void *
+loopback(void *arg)
+{
+ tsd_t *ts = (tsd_t *)arg;
+ int i, n, m;
+
+ /* Include priming and termination */
+ m = lm_optB + 2;
+
+ for (i = 0; i < m; i++) {
+ n = readall(ts->ts_in2, rbuf, opts);
+ if (n == -1) {
+ break;
+ }
+ if (write(ts->ts_out2, wbuf, opts) != opts) {
+ break;
+ }
+ }
+
+ return (NULL);
+}
+
+int
+prepare_localtcp_once(tsd_t *ts)
+{
+ int j;
+ int opt = 1;
+ struct hostent *host;
+
+ j = FIRSTPORT;
+
+ ts->ts_lsn = socket(AF_INET, SOCK_STREAM, 0);
+ if (ts->ts_lsn == -1) {
+ return (-1);
+ }
+
+ if (setsockopt(ts->ts_lsn, SOL_SOCKET, SO_REUSEADDR,
+ &opt, sizeof (int)) == -1) {
+ return (-1);
+ }
+
+ if ((host = gethostbyname("localhost")) == NULL) {
+ return (-1);
+ }
+
+ for (;;) {
+ (void) memset(&ts->ts_add, 0,
+ sizeof (struct sockaddr_in));
+ ts->ts_add.sin_family = AF_INET;
+ ts->ts_add.sin_port = htons(j++);
+ (void) memcpy(&ts->ts_add.sin_addr.s_addr,
+ host->h_addr_list[0], sizeof (struct in_addr));
+
+ if (bind(ts->ts_lsn,
+ (struct sockaddr *)&ts->ts_add,
+ sizeof (struct sockaddr_in)) == 0) {
+ break;
+ }
+
+ if (errno != EADDRINUSE) {
+ return (-1);
+ }
+ }
+
+ if (listen(ts->ts_lsn, 5) == -1) {
+ return (-1);
+ }
+
+ return (0);
+}
+
+int
+prepare_localtcp(tsd_t *ts)
+{
+ int result;
+ struct sockaddr_in addr;
+ int opt = 1;
+ socklen_t size;
+
+ if (ts->ts_once++ == 0) {
+ if (prepare_localtcp_once(ts) == -1) {
+ return (-1);
+ }
+ }
+
+ ts->ts_out = socket(AF_INET, SOCK_STREAM, 0);
+ if (ts->ts_out == -1) {
+ return (-1);
+ }
+
+ if (fcntl(ts->ts_out, F_SETFL, O_NDELAY) == -1) {
+ return (-1);
+ }
+
+ result = connect(ts->ts_out, (struct sockaddr *)&ts->ts_add,
+ sizeof (struct sockaddr_in));
+ if ((result == -1) && (errno != EINPROGRESS)) {
+ return (-1);
+ }
+
+ if (fcntl(ts->ts_out, F_SETFL, 0) == -1) {
+ return (-1);
+ }
+
+ size = sizeof (struct sockaddr);
+ result = accept(ts->ts_lsn, (struct sockaddr *)&addr, &size);
+ if (result == -1) {
+ return (-1);
+ }
+ ts->ts_out2 = result;
+
+ if (setsockopt(ts->ts_out, IPPROTO_TCP, TCP_NODELAY,
+ &opt, sizeof (int)) == -1) {
+ return (-1);
+ }
+
+ if (setsockopt(ts->ts_out2, IPPROTO_TCP, TCP_NODELAY,
+ &opt, sizeof (int)) == -1) {
+ return (-1);
+ }
+
+ if (optm == MD_SINGLE) {
+ ts->ts_in = ts->ts_out2;
+ } else {
+ ts->ts_in = ts->ts_out;
+ ts->ts_in2 = ts->ts_out2;
+ }
+
+ return (0);
+}
+
+int
+prepare_socketpair(tsd_t *ts)
+{
+ int s[2];
+
+ if (socketpair(PF_UNIX, SOCK_STREAM, 0, s) == -1) {
+ return (-1);
+ }
+
+ if (optm == MD_SINGLE) {
+ ts->ts_in = s[0];
+ ts->ts_out = s[1];
+ } else {
+ ts->ts_in = s[0];
+ ts->ts_out = s[0];
+ ts->ts_in2 = s[1];
+ ts->ts_out2 = s[1];
+ }
+
+ return (0);
+}
+
+int
+prepare_fifos(tsd_t *ts)
+{
+ char path[64];
+
+ (void) sprintf(path, "/tmp/pipe_%ld.%dA",
+ getpid(), pthread_self());
+ if (mknod(path, 0600, S_IFIFO) == -1) {
+ return (-1);
+ }
+
+ if (optm == MD_SINGLE) {
+ ts->ts_in = open(path, O_RDONLY);
+ ts->ts_out = open(path, O_WRONLY);
+ } else {
+ ts->ts_in = open(path, O_RDONLY);
+ ts->ts_out2 = open(path, O_WRONLY);
+
+ (void) sprintf(path, "/tmp/pipe_%ld.%dB",
+ getpid(), pthread_self());
+ if (mknod(path, 0600, S_IFIFO) == -1) {
+ return (-1);
+ }
+
+ ts->ts_in2 = open(path, O_RDONLY);
+ ts->ts_out = open(path, O_WRONLY);
+ }
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+cleanup_fifos(tsd_t *ts)
+{
+ char path[64];
+
+ (void) sprintf(path, "/tmp/pipe_%ld.%dA", getpid(), pthread_self());
+ (void) unlink(path);
+ (void) sprintf(path, "/tmp/pipe_%ld.%dB", getpid(), pthread_self());
+ (void) unlink(path);
+
+ return (0);
+}
+
+int
+prepare_pipes(tsd_t *ts)
+{
+ int p[2];
+
+ if (optm == MD_SINGLE) {
+ if (pipe(p) == -1) {
+ return (-1);
+ }
+ ts->ts_in = p[0];
+ ts->ts_out = p[1];
+
+ } else {
+ if (pipe(p) == -1) {
+ return (-1);
+ }
+ ts->ts_in = p[0];
+ ts->ts_out2 = p[1];
+
+ if (pipe(p) == -1) {
+ return (-1);
+ }
+ ts->ts_in2 = p[0];
+ ts->ts_out = p[1];
+ }
+
+ return (0);
+}
+
+char *
+lookupa(int x, char *names[])
+{
+ int i = 0;
+
+ while (names[i] != NULL) {
+ if (x == i) {
+ return (names[i]);
+ }
+ i++;
+ }
+ return (NULL);
+}
+
+int
+lookup(char *x, char *names[])
+{
+ int i = 0;
+
+ while (names[i] != NULL) {
+ if (strcmp(names[i], x) == 0) {
+ return (i);
+ }
+ i++;
+ }
+ return (-1);
+}
diff --git a/native/libMicro-0.4.0/poll.c b/native/libMicro-0.4.0/poll.c
new file mode 100644
index 0000000..5ef1287
--- /dev/null
+++ b/native/libMicro-0.4.0/poll.c
@@ -0,0 +1,218 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#define MAX(x, y) ((x) > (y) ? (x) : (y))
+#define MIN(x, y) ((x) > (y) ? (y) : (x))
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <poll.h>
+#include <sys/socket.h>
+
+#include "libmicro.h"
+
+#define DEFN 256
+
+static int optn = DEFN;
+static int optr = 0;
+static int optw = 0;
+static int optx = 0;
+static int *fds;
+static int target = 0;
+
+typedef struct pollfd pfd_t;
+
+typedef struct {
+ int ts_once;
+ pfd_t *ts_pfds;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "n:r:w:x");
+
+ (void) sprintf(lm_usage,
+ " [-n fds-per-thread (default %d)]\n"
+ " [-r readable-fds (default 0)]\n"
+ " [-w writeable-fds (default 0)]\n"
+ " [-x] (start -r option with highest fd first; "
+ "default is lowest first)\n"
+ "notes: measures poll()\n",
+ DEFN);
+
+ (void) sprintf(lm_header, "%8s %5s", "nfds", "flags");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'n':
+ optn = atoi(optarg);
+ break;
+ case 'r':
+ optr = atoi(optarg);
+ break;
+ case 'w':
+ optw = atoi(optarg);
+ break;
+ case 'x':
+ optx = 1;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ int i;
+ int j;
+ int pair[2];
+
+ if (optn % 2 != 0) {
+ (void) printf("ERROR: -n value must be even\n");
+ optn = optr = optw = 0;
+ return (-1);
+ }
+
+ if (optn < 0 || optr < 0 || optw < 0) {
+ (void) printf("ERROR: -n, -r and -w values must be > 0\n");
+ optn = optr = optw = 0;
+ return (-1);
+ }
+
+ if (optr > optn || optw > optn) {
+ (void) printf("ERROR: -r and -w values must be <= maxfd\n");
+ optn = optr = optw = 0;
+ return (-1);
+ }
+
+ fds = (int *)malloc(optn * sizeof (int));
+ if (fds == NULL) {
+ (void) printf("ERROR: malloc() failed\n");
+ optn = optr = optw = 0;
+ return (-1);
+ }
+
+ (void) setfdlimit(optn + 10);
+
+
+ for (i = 0; i < optn; i += 2) {
+ if (socketpair(PF_UNIX, SOCK_STREAM, 0, pair) == -1) {
+ (void) printf("ERROR: socketpair() failed\n");
+ return (-1);
+ }
+
+ fds[i] = MIN(pair[0], pair[1]);
+ fds[i+1] = MAX(pair[0], pair[1]);
+ }
+
+ if (optx) {
+ target = MIN(optr + optw, optn);
+ for (i = 0, j = optn - 1; i < optr; i++, j--) {
+ (void) write(fds[j+1 - (2*(j%2))], "", 1);
+ }
+ } else {
+ target = MAX(optr, optw);
+ for (i = 0; i < optr; i++) {
+ (void) write(fds[i+1 - (2*(i%2))], "", 1);
+ }
+ }
+
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int errors = 0;
+
+ if (ts->ts_once++ == 0) {
+ ts->ts_pfds = (pfd_t *)malloc(optn * sizeof (pfd_t));
+ if (ts->ts_pfds == NULL) {
+ errors++;
+ }
+
+ for (i = 0; i < optn; i++) {
+ ts->ts_pfds[i].fd = fds[i];
+ ts->ts_pfds[i].events = POLLIN;
+ }
+
+ for (i = 0; i < optw; i++) {
+ ts->ts_pfds[i].events |= POLLOUT;
+ }
+ }
+
+ return (errors);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (poll(ts->ts_pfds, optn, 0) != target) {
+ res->re_errors++;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+ char flags[4];
+
+ flags[0] = optr ? 'r' : '-';
+ flags[1] = optw ? 'w' : '-';
+ flags[2] = optx ? 'x' : '-';
+ flags[3] = 0;
+
+ (void) sprintf(result, "%8d %5s", optn, flags);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/pread.c b/native/libMicro-0.4.0/pread.c
new file mode 100644
index 0000000..51e15d9
--- /dev/null
+++ b/native/libMicro-0.4.0/pread.c
@@ -0,0 +1,142 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifdef linux
+#define _XOPEN_SOURCE 500
+#endif
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ char *ts_buf;
+} tsd_t;
+
+#define DEFF "/dev/zero"
+#define DEFS 1024
+
+static char *optf = DEFF;
+static long long opts = DEFS;
+static int optw = 0;
+static int fd = -1;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "wf:s:");
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-read (default %s)]\n"
+ " [-s buffer-size (default %d)]\n"
+ " [-w (write a byte to each page after read)]\n"
+ "notes: measures pread()\n",
+ DEFF, DEFS);
+
+ (void) sprintf(lm_header, "%8s", "size");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'w':
+ optw = getpagesize();
+ break;
+ case 'f':
+ optf = optarg;
+ break;
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ fd = open(optf, O_RDONLY);
+
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int errors = 0;
+
+ if (ts->ts_buf == NULL) {
+ ts->ts_buf = malloc(opts);
+ }
+
+ return (errors);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int j;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (pread(fd, ts->ts_buf, opts, 0) != opts) {
+ res->re_errors++;
+ }
+ if (optw) {
+ for (j = 0; j < opts; j += optw)
+ ts->ts_buf[j] = 0;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%8lld", opts);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/pthread_create.c b/native/libMicro-0.4.0/pthread_create.c
new file mode 100644
index 0000000..340d35c
--- /dev/null
+++ b/native/libMicro-0.4.0/pthread_create.c
@@ -0,0 +1,160 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <pthread.h>
+#include <errno.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ pthread_t *ts_threads;
+ pthread_attr_t *ts_attr;
+ pthread_mutex_t ts_lock;
+} tsd_t;
+
+static int opts = 0;
+
+int
+benchmark_init()
+{
+ lm_defN = "pthread";
+
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_usage,
+ " [-s stacksize] (specify stacksize)\n"
+ "notes: measures pthread_create\n");
+
+ (void) sprintf(lm_optstr, "s:");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ default:
+ return (-1);
+ }
+
+ return (0);
+}
+
+int
+benchmark_initworker(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int errors = 0;
+
+ ts->ts_threads = calloc(lm_optB, sizeof (pthread_t));
+ (void) pthread_mutex_init(&ts->ts_lock, NULL);
+
+ if (opts) {
+ ts->ts_attr = malloc(sizeof (pthread_attr_t));
+ (void) pthread_attr_init(ts->ts_attr);
+ if ((errors = pthread_attr_setstacksize(ts->ts_attr, opts))
+ != 0) {
+ errno = errors;
+ perror("pthread_attr_setstacksize");
+ }
+ } else
+ ts->ts_attr = NULL;
+
+ return (errors?1:0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ (void) pthread_mutex_lock(&ts->ts_lock);
+
+ return (0);
+}
+
+
+void *
+func(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ (void) pthread_mutex_lock(&ts->ts_lock);
+ (void) pthread_mutex_unlock(&ts->ts_lock);
+
+ return (tsd);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+ int error;
+
+ for (i = 0; i < lm_optB; i++) {
+ if ((error = pthread_create(ts->ts_threads + i,
+ ts->ts_attr, func, tsd)) != 0) {
+ errno = error;
+ perror("pthread_create");
+ ts->ts_threads[i] = 0;
+ res->re_errors++;
+ return (0);
+ }
+ }
+ res->re_count = lm_optB;
+
+ return (0);
+}
+
+int
+benchmark_finibatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int errors = 0;
+
+ (void) pthread_mutex_unlock(&ts->ts_lock);
+
+ for (i = 0; i < lm_optB; i++)
+ if (ts->ts_threads[i] == 0 ||
+ pthread_join(ts->ts_threads[i], NULL) < 0) {
+ errors++;
+ }
+ return (errors);
+}
diff --git a/native/libMicro-0.4.0/pwrite.c b/native/libMicro-0.4.0/pwrite.c
new file mode 100644
index 0000000..ab1374c
--- /dev/null
+++ b/native/libMicro-0.4.0/pwrite.c
@@ -0,0 +1,154 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifdef linux
+#define _XOPEN_SOURCE 500
+#endif
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ char *ts_buf;
+} tsd_t;
+
+#define DEFF "/dev/null"
+#define DEFS 1024
+
+static int optc = 0;
+static char *optf = DEFF;
+static long long opts = DEFS;
+static int fd = -1;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "cf:s:");
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-write (default %s)]\n"
+ " [-s buffer-size (default %d)]\n"
+ " [-c ] (make sure buffer is in cache)\n"
+ "notes: measures pwrite()\n",
+ DEFF, DEFS);
+
+ (void) sprintf(lm_header, "%8s", "size");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'c':
+ optc++;
+ break;
+ case 'f':
+ optf = optarg;
+ break;
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ fd = open(optf, O_WRONLY);
+ if (fd == -1) {
+ return (-1);
+ }
+
+ return (0);
+}
+
+int
+benchmark_finirun()
+{
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ if (ts->ts_buf == NULL) {
+ ts->ts_buf = malloc(opts);
+
+ /*
+ * bring buf into cache if specified.
+ */
+
+ if (optc)
+ for (i = 0; i < opts; i++)
+ ts->ts_buf[i] = 0;
+ }
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (pwrite(fd, ts->ts_buf, opts, 0) != opts) {
+ res->re_errors++;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%8lld", opts);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/read.c b/native/libMicro-0.4.0/read.c
new file mode 100644
index 0000000..32faf05
--- /dev/null
+++ b/native/libMicro-0.4.0/read.c
@@ -0,0 +1,143 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+
+#ifdef linux
+#define _XOPEN_SOURCE 500
+#endif
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ char *ts_buf;
+ int ts_fd;
+} tsd_t;
+
+#define DEFF "/dev/zero"
+#define DEFS 1024
+
+static char *optf = DEFF;
+static long long opts = DEFS;
+int optw = 0;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "f:s:w");
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-read (default %s)]\n"
+ " [-s buffer-size (default %d)]\n"
+ " [-w (store a byte to each page after read)]\n"
+ "notes: measures read()\n",
+ DEFF, DEFS);
+
+ (void) sprintf(lm_header, "%8s", "size");
+
+ lm_defB = 1;
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'w':
+ optw = getpagesize();
+ break;
+ case 'f':
+ optf = optarg;
+ break;
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ if (ts->ts_buf == NULL) {
+ ts->ts_buf = malloc(opts);
+ ts->ts_fd = open(optf, O_RDONLY);
+ }
+
+ (void) lseek(ts->ts_fd, 0, SEEK_SET);
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int j;
+ for (i = 0; i < lm_optB; i++) {
+ if (read(ts->ts_fd, ts->ts_buf, opts) != opts) {
+ res->re_errors++;
+ }
+ if (optw)
+ for (j = 0; j < opts; j += optw)
+ ts->ts_buf[j] = 0;
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%8lld", opts);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/realpath.c b/native/libMicro-0.4.0/realpath.c
new file mode 100644
index 0000000..540ebf7
--- /dev/null
+++ b/native/libMicro-0.4.0/realpath.c
@@ -0,0 +1,85 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+#define DEFF "/"
+#define MAXPATHLEN 1024
+
+static char *optf = DEFF;
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_optstr, "f:");
+
+ lm_tsdsize = 0;
+
+ (void) sprintf(lm_usage,
+ " [-f directory (default = %s)]\n"
+ "notes: measures realpath()\n",
+ DEFF);
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf = optarg;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ char path[MAXPATHLEN];
+
+ for (i = 0; i < lm_optB; i++) {
+ if (realpath(optf, path) == NULL)
+ res->re_errors++;
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/recurse.c b/native/libMicro-0.4.0/recurse.c
new file mode 100644
index 0000000..fe0930c
--- /dev/null
+++ b/native/libMicro-0.4.0/recurse.c
@@ -0,0 +1,110 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "libmicro.h"
+
+#define DEFD 100
+
+static int optd = DEFD;
+
+int recurse2(int x, int y, char *s);
+
+/*ARGSUSED*/
+int
+recurse1(int x, int y, char *s)
+{
+ char str[32];
+
+ if (x < y) {
+ return (recurse2(x + 1, y, str));
+ }
+
+ return (x);
+}
+
+int
+recurse2(int x, int y, char *s)
+{
+ char str[32];
+
+ if (x < y) {
+ return (recurse1(x + 1, y, str));
+ }
+
+ return (x);
+}
+
+int
+benchmark_init()
+{
+ lm_tsdsize = 0;
+
+ (void) sprintf(lm_optstr, "d:");
+
+ (void) sprintf(lm_usage,
+ " [-d depth-limit (default = %d)]\n"
+ "notes: measures recursion performance\n",
+ DEFD);
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'd':
+ optd = atoi(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ (void) recurse1(0, optd, NULL);
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/recurse2.c b/native/libMicro-0.4.0/recurse2.c
new file mode 100644
index 0000000..9f22890
--- /dev/null
+++ b/native/libMicro-0.4.0/recurse2.c
@@ -0,0 +1,46 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <string.h>
+
+int recurse1(int x, int y, char *s);
+
+/*ARGSUSED*/
+int
+recurse2(int x, int y, char *s)
+{
+ char str[32];
+
+ if (x < y) {
+ return (recurse1(x + 1, y, str));
+ }
+
+ return (x);
+}
diff --git a/native/libMicro-0.4.0/select.c b/native/libMicro-0.4.0/select.c
new file mode 100644
index 0000000..5edc37e
--- /dev/null
+++ b/native/libMicro-0.4.0/select.c
@@ -0,0 +1,214 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#define MAX(x, y) ((x) > (y) ? (x) : (y))
+#define MIN(x, y) ((x) > (y) ? (y) : (x))
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+
+#include "libmicro.h"
+
+#define DEFN 256
+
+static int optn = DEFN;
+static int optr = 0;
+static int optw = 0;
+static int optx = 0;
+static int *fds;
+static fd_set iset;
+static fd_set oset;
+static int maxfd = 0;
+static int target = 0;
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_optstr, "n:r:w:x");
+
+ lm_tsdsize = 0;
+
+ (void) sprintf(lm_usage,
+ " [-n fds-per-thread (default %d)]\n"
+ " [-r readable-fds (default 0)]\n"
+ " [-w writeable-fds (default 0)]\n"
+ " [-x] (start -r option with highest fd first; "
+ "default is lowest first)\n"
+ "notes: measures select()\n",
+ DEFN);
+
+ (void) sprintf(lm_header, "%8s %5s", "maxfd", "flags");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'n':
+ optn = atoi(optarg);
+ break;
+ case 'r':
+ optr = atoi(optarg);
+ break;
+ case 'w':
+ optw = atoi(optarg);
+ break;
+ case 'x':
+ optx = 1;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ int i;
+ int j;
+ int pair[2];
+
+ if (optn % 2 != 0) {
+ (void) printf("ERROR: -n value must be even\n");
+ optn = optr = optw = 0;
+ return (-1);
+ }
+
+ if (optn < 0 || optr < 0 || optw < 0) {
+ (void) printf("ERROR: -n, -r and -w values must be > 0\n");
+ optn = optr = optw = 0;
+ return (-1);
+ }
+
+ if (optr > optn || optw > optn) {
+ (void) printf("ERROR: -r and -w values must be <= maxfd\n");
+ optn = optr = optw = 0;
+ return (-1);
+ }
+
+ fds = (int *)malloc(optn * sizeof (int));
+ if (fds == NULL) {
+ (void) printf("ERROR: malloc() failed\n");
+ optn = optr = optw = 0;
+ return (-1);
+ }
+
+ (void) setfdlimit(optn + 10);
+
+ target = optr + optw;
+
+ FD_ZERO(&iset);
+ FD_ZERO(&oset);
+
+ for (i = 0; i < optn; i += 2) {
+ if (socketpair(PF_UNIX, SOCK_STREAM, 0, pair) == -1) {
+ (void) printf("ERROR: socketpair() failed\n");
+ return (-1);
+ }
+
+ fds[i] = MIN(pair[0], pair[1]);
+ fds[i+1] = MAX(pair[0], pair[1]);
+ maxfd = fds[i+1] + 1;
+
+ if (maxfd > FD_SETSIZE) {
+ (void) printf("WARNING: FD_SETSIZE is too small!\n");
+ return (-1);
+ }
+
+ FD_SET(fds[i], &iset);
+ FD_SET(fds[i+1], &iset);
+ }
+
+ for (i = 0; i < optw; i++) {
+ FD_SET(fds[i], &oset);
+ }
+ if (optx) {
+ for (i = 0, j = optn - 1; i < optr; i++, j--) {
+ (void) write(fds[j+1 - (2*(j%2))], "", 1);
+ }
+ } else {
+ for (i = 0; i < optr; i++) {
+ (void) write(fds[i+1 - (2*(i%2))], "", 1);
+ }
+ }
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ fd_set set1;
+ fd_set set2;
+ fd_set *my_iset = &set1;
+ fd_set *my_oset = NULL;
+ struct timeval tv = {0, 0};
+
+ if (optw) {
+ my_oset = &set2;
+ }
+
+ for (i = 0; i < lm_optB; i++) {
+ (void) memcpy(&set1, &iset, sizeof (fd_set));
+ (void) memcpy(&set2, &oset, sizeof (fd_set));
+
+ if (select(maxfd, my_iset, my_oset, NULL, &tv) != target) {
+ res->re_errors++;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+ char flags[4];
+
+ flags[0] = optr ? 'r' : '-';
+ flags[1] = optw ? 'w' : '-';
+ flags[2] = optx ? 'x' : '-';
+ flags[3] = 0;
+
+ (void) sprintf(result, "%8d %5s", optn, flags);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/semop.c b/native/libMicro-0.4.0/semop.c
new file mode 100644
index 0000000..9953a79
--- /dev/null
+++ b/native/libMicro-0.4.0/semop.c
@@ -0,0 +1,103 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/sem.h>
+
+#include "libmicro.h"
+
+
+typedef struct {
+ int ts_semid;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_usage, "notes: measures semop()\n");
+
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+
+ tsd_t *ts = (tsd_t *)tsd;
+
+ if ((ts->ts_semid = semget(IPC_PRIVATE, 2, 0600)) == -1) {
+ return (-1);
+ }
+
+ return (0);
+}
+
+int
+benchmark_finibatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ (void) semctl(ts->ts_semid, 0, IPC_RMID);
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+ struct sembuf s[1];
+
+ for (i = 0; i < lm_optB; i++) {
+ s[0].sem_num = 0;
+ s[0].sem_op = 1;
+ s[0].sem_flg = 0;
+ if (semop(ts->ts_semid, s, 1) == -1) {
+ res->re_errors++;
+ }
+ s[0].sem_num = 0;
+ s[0].sem_op = -1;
+ s[0].sem_flg = 0;
+ if (semop(ts->ts_semid, s, 1) == -1) {
+ res->re_errors++;
+ }
+ }
+
+ res->re_count += lm_optB;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/setcontext.c b/native/libMicro-0.4.0/setcontext.c
new file mode 100644
index 0000000..dad2849
--- /dev/null
+++ b/native/libMicro-0.4.0/setcontext.c
@@ -0,0 +1,67 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ucontext.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+
+ (void) sprintf(lm_usage, "notes: measures setcontext()\n");
+
+ lm_tsdsize = 0;
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ volatile int i;
+
+ ucontext_t uc;
+
+ i = 0;
+
+ (void) getcontext(&uc);
+
+ if (i++ < lm_optB)
+ (void) setcontext(&uc);
+
+ res->re_count += lm_optB;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/setsockopt.c b/native/libMicro-0.4.0/setsockopt.c
new file mode 100644
index 0000000..c48672e
--- /dev/null
+++ b/native/libMicro-0.4.0/setsockopt.c
@@ -0,0 +1,99 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ int ts_fd;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_usage, "setsockopt(TCP_NODELAY)\n");
+
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+
+ tsd_t *ts = (tsd_t *)tsd;
+
+ if ((ts->ts_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+ return (1);
+ return (0);
+}
+
+int
+benchmark_finibatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ (void) close(ts->ts_fd);
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+ int opt;
+
+ res->re_errors = 0;
+
+ for (i = 0; i < lm_optB; i++) {
+ opt = 1 & i;
+ if (setsockopt(ts->ts_fd, IPPROTO_TCP, TCP_NODELAY,
+ &opt, sizeof (int)) == -1) {
+ res->re_errors ++;
+ }
+ }
+ res->re_count += lm_optB;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/sigaction.c b/native/libMicro-0.4.0/sigaction.c
new file mode 100644
index 0000000..b0053b3
--- /dev/null
+++ b/native/libMicro-0.4.0/sigaction.c
@@ -0,0 +1,95 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+
+#include "libmicro.h"
+
+#ifdef __sun
+static void
+nop()
+{
+}
+#else
+static void
+nop(int sig)
+{
+}
+#endif
+
+
+typedef struct {
+ struct sigaction ts_act;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_usage, "notes: measures sigaction()\n");
+
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+
+ tsd_t *ts = (tsd_t *)tsd;
+ ts->ts_act.sa_handler = nop;
+ ts->ts_act.sa_flags = 0;
+ (void) sigemptyset(&ts->ts_act.sa_mask);
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+ struct sigaction oact;
+
+ res->re_errors = 0;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (sigaction(SIGUSR1, &ts->ts_act, &oact))
+ res->re_errors++;
+ }
+
+ res->re_count += lm_optB;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/siglongjmp.c b/native/libMicro-0.4.0/siglongjmp.c
new file mode 100644
index 0000000..b4dfd16
--- /dev/null
+++ b/native/libMicro-0.4.0/siglongjmp.c
@@ -0,0 +1,69 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <setjmp.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ jmp_buf ts_env;
+} tsd_t;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ lm_tsdsize = 0;
+
+ (void) sprintf(lm_usage, "notes: measures siglongjmp()\n");
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ int i = 0;
+
+ (void) sigsetjmp(ts->ts_env, 1);
+
+ if (i++ < lm_optB)
+ siglongjmp(ts->ts_env, 0);
+
+ res->re_count = lm_optB;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/signal.c b/native/libMicro-0.4.0/signal.c
new file mode 100644
index 0000000..f172905
--- /dev/null
+++ b/native/libMicro-0.4.0/signal.c
@@ -0,0 +1,100 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+
+#include "libmicro.h"
+
+
+#ifdef __sun
+static void
+nop()
+{
+}
+#else
+static void
+nop(int sig)
+{
+}
+#endif
+
+int
+benchmark_init()
+{
+ lm_tsdsize = 0;
+
+ (void) sprintf(lm_usage, "notes: measures signal()\n");
+
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ struct sigaction act;
+
+ act.sa_handler = nop;
+ act.sa_flags = 0;
+
+ (void) sigemptyset(&act.sa_mask);
+ (void) sigaction(SIGUSR1, &act, NULL);
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ int pid;
+
+ pid = getpid();
+
+ for (i = 0; i < lm_optB; i += 10) {
+ (void) kill(pid, SIGUSR1);
+ (void) kill(pid, SIGUSR1);
+ (void) kill(pid, SIGUSR1);
+ (void) kill(pid, SIGUSR1);
+ (void) kill(pid, SIGUSR1);
+ (void) kill(pid, SIGUSR1);
+ (void) kill(pid, SIGUSR1);
+ (void) kill(pid, SIGUSR1);
+ (void) kill(pid, SIGUSR1);
+ (void) kill(pid, SIGUSR1);
+ }
+ res->re_count += lm_optB;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/sigprocmask.c b/native/libMicro-0.4.0/sigprocmask.c
new file mode 100644
index 0000000..de89b46
--- /dev/null
+++ b/native/libMicro-0.4.0/sigprocmask.c
@@ -0,0 +1,84 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ lm_tsdsize = 0;
+
+ (void) sprintf(lm_usage, "notes: measures sigprocmask()\n");
+
+ return (0);
+}
+
+int
+benchmark_initrun()
+{
+ sigset_t iset;
+
+ (void) sigemptyset(&iset);
+ (void) sigprocmask(SIG_SETMASK, &iset, NULL);
+
+ return (0);
+}
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ sigset_t set0, set1;
+
+ (void) sigemptyset(&set0);
+ (void) sigaddset(&set0, SIGTERM);
+
+ for (i = 0; i < lm_optB; i += 10) {
+ (void) sigprocmask(SIG_SETMASK, &set0, &set1);
+ (void) sigprocmask(SIG_SETMASK, &set1, &set0);
+ (void) sigprocmask(SIG_SETMASK, &set0, &set1);
+ (void) sigprocmask(SIG_SETMASK, &set1, &set0);
+ (void) sigprocmask(SIG_SETMASK, &set0, &set1);
+ (void) sigprocmask(SIG_SETMASK, &set1, &set0);
+ (void) sigprocmask(SIG_SETMASK, &set0, &set1);
+ (void) sigprocmask(SIG_SETMASK, &set1, &set0);
+ (void) sigprocmask(SIG_SETMASK, &set0, &set1);
+ (void) sigprocmask(SIG_SETMASK, &set1, &set0);
+ }
+
+ res->re_count += lm_optB;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/socket.c b/native/libMicro-0.4.0/socket.c
new file mode 100644
index 0000000..496966d
--- /dev/null
+++ b/native/libMicro-0.4.0/socket.c
@@ -0,0 +1,157 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/socket.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ int ts_once;
+ int *ts_fds;
+} tsd_t;
+
+#define DEFF "PF_UNIX"
+
+static char *optf = DEFF;
+static int family;
+
+int
+lookup_family(char *name)
+{
+ if (strcmp("PF_UNIX", name) == 0) {
+ return (PF_UNIX);
+ } else if (strcmp("PF_INET", name) == 0) {
+ return (PF_INET);
+ } else if (strcmp("PF_INET6", name) == 0) {
+ return (PF_INET6);
+ }
+
+ return (-1);
+}
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ lm_defB = 256;
+
+ (void) sprintf(lm_optstr, "f:n");
+
+ (void) sprintf(lm_usage,
+ " [-f socket-family (default %s)]\n"
+ "notes: measures socket\n",
+ DEFF);
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf = optarg;
+ break;
+ default:
+ return (-1);
+ }
+
+ return (0);
+}
+
+
+int
+benchmark_initrun()
+{
+ (void) setfdlimit(lm_optB * lm_optT + 10);
+ family = lookup_family(optf);
+
+ return (0);
+}
+
+int
+benchmark_finirun()
+{
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+
+ if (ts->ts_once++ == 0) {
+ ts->ts_fds = (int *)malloc(lm_optB * sizeof (int));
+ if (ts->ts_fds == NULL) {
+ return (1);
+ }
+ for (i = 0; i < lm_optB; i++) {
+ ts->ts_fds[i] = -1;
+ }
+ }
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+
+ for (i = 0; i < lm_optB; i++) {
+ ts->ts_fds[i] = socket(family, SOCK_STREAM, 0);
+ if (ts->ts_fds[i] == -1) {
+ res->re_errors++;
+ }
+ }
+ res->re_count += lm_optB;
+
+ return (0);
+}
+
+int
+benchmark_finibatch(void *tsd)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+
+ for (i = 0; i < lm_optB; i++) {
+ (void) close(ts->ts_fds[i]);
+ }
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/socketpair.c b/native/libMicro-0.4.0/socketpair.c
new file mode 100644
index 0000000..ce880ce
--- /dev/null
+++ b/native/libMicro-0.4.0/socketpair.c
@@ -0,0 +1,118 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/socket.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ int ts_once;
+ int *ts_fds;
+} tsd_t;
+
+#define DEFN 256
+
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ lm_defB = 256;
+
+ (void) sprintf(lm_usage,
+ "notes: measures socketpair\n");
+
+ return (0);
+}
+
+
+int
+benchmark_initrun()
+{
+ (void) setfdlimit(lm_optB * lm_optT + 10);
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+
+ if (ts->ts_once++ == 0) {
+ ts->ts_fds = (int *)malloc(lm_optB * sizeof (int));
+ if (ts->ts_fds == NULL) {
+ return (1);
+ }
+ for (i = 0; i < lm_optB; i++) {
+ ts->ts_fds[i] = -1;
+ }
+ }
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+
+ res->re_count = 0;
+ res->re_errors = 0;
+
+ for (i = 0; i < lm_optB; i += 2) {
+ if (socketpair(PF_UNIX, SOCK_STREAM, 0, &ts->ts_fds[i])
+ == -1) {
+ res->re_errors++;
+ }
+ }
+ res->re_count = lm_optB / 2;
+
+ return (0);
+}
+
+int
+benchmark_finibatch(void *tsd)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+
+ for (i = 0; i < lm_optB; i++) {
+ (void) close(ts->ts_fds[i]);
+ }
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/stat.c b/native/libMicro-0.4.0/stat.c
new file mode 100644
index 0000000..cffccee
--- /dev/null
+++ b/native/libMicro-0.4.0/stat.c
@@ -0,0 +1,88 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "libmicro.h"
+
+#define DEFF "/dev/null"
+static char *optf = DEFF;
+
+int
+benchmark_init()
+{
+
+ (void) sprintf(lm_optstr, "f:");
+
+ lm_tsdsize = 0;
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-stat (default %s)]\n"
+ "notes: measures stat()\n",
+ DEFF);
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf = optarg;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ struct stat sbuf;
+
+ res->re_errors = 0;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (stat(optf, &sbuf) == -1)
+ res->re_errors++;
+ }
+
+ res->re_count += lm_optB;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/strcasecmp.c b/native/libMicro-0.4.0/strcasecmp.c
new file mode 100644
index 0000000..edb50af
--- /dev/null
+++ b/native/libMicro-0.4.0/strcasecmp.c
@@ -0,0 +1,150 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "libmicro.h"
+
+
+static int unaligned = 0;
+static int opts = 100;
+
+typedef struct {
+ int ts_once;
+ char *ts_a;
+ char *ts_b;
+ int ts_fakegcc;
+} tsd_t;
+
+int
+benchmark_init()
+{
+
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "s:n");
+
+ (void) sprintf(lm_usage,
+ " [-s string size (default %d)]\n"
+ " [-n causes unaligned cmp]\n"
+ "notes: measures strcasecmp()\n",
+ opts);
+
+ (void) sprintf(lm_header, "%8s", "size");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'n':
+ unaligned = 1;
+ break;
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ static char *demo =
+ "The quick brown fox jumps over the lazy dog.";
+
+ if (ts->ts_once++ == 0) {
+ int l = strlen(demo);
+ int i;
+
+ ts->ts_a = malloc(opts + 1);
+ ts->ts_b = malloc(opts + 1 + unaligned);
+ ts->ts_b += unaligned;
+
+ for (i = 0; i < opts; i++) {
+ ts->ts_a[i] = ts->ts_b[i] = demo[i%l];
+ }
+ ts->ts_a[opts] = 0;
+ ts->ts_b[opts] = 0;
+ }
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+
+ char *src = ts->ts_a;
+ char *src2 = ts->ts_b;
+ int *sum = &ts->ts_fakegcc;
+
+ res->re_errors = 0;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ *sum += strcasecmp(src, src2);
+ *sum += strcasecmp(src, src2);
+ *sum += strcasecmp(src, src2);
+ *sum += strcasecmp(src, src2);
+ *sum += strcasecmp(src, src2);
+ *sum += strcasecmp(src, src2);
+ *sum += strcasecmp(src, src2);
+ *sum += strcasecmp(src, src2);
+ *sum += strcasecmp(src, src2);
+ *sum += strcasecmp(src, src2);
+ }
+
+ res->re_count = lm_optB;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ if (unaligned == 0)
+ (void) sprintf(result, "%8d", opts);
+ else
+ (void) sprintf(result, "%8d <unaligned>", opts);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/strchr.c b/native/libMicro-0.4.0/strchr.c
new file mode 100644
index 0000000..d3050e8
--- /dev/null
+++ b/native/libMicro-0.4.0/strchr.c
@@ -0,0 +1,144 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "libmicro.h"
+
+static int unaligned = 0;
+static int opts = 100;
+
+typedef struct {
+ int ts_once;
+ char *ts_string;
+ char *ts_fakegcc;
+} tsd_t;
+
+int
+benchmark_init()
+{
+
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "s:n");
+
+ (void) sprintf(lm_usage,
+ " [-s string size (default %d)]\n"
+ " [-n causes unaligned strchr]\n"
+ "notes: measures strchr()\n",
+ opts);
+
+ (void) sprintf(lm_header, "%8s", "size");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'n':
+ unaligned = 1;
+ break;
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ static char *demo =
+ "The quick brown fox jumps over the lazy dog.";
+
+ if (ts->ts_once++ == 0) {
+ int l = strlen(demo);
+ int i;
+
+ ts->ts_string = malloc(opts + 1 + unaligned);
+ ts->ts_string += unaligned;
+
+
+ for (i = 0; i < opts; i++) {
+ ts->ts_string[i] = demo[i%l];
+ }
+
+ ts->ts_string[opts] = 0;
+
+ }
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+ char *src = ts->ts_string;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ ts->ts_fakegcc = strchr(src, 'X');
+ ts->ts_fakegcc = strchr(src, 'X');
+ ts->ts_fakegcc = strchr(src, 'X');
+ ts->ts_fakegcc = strchr(src, 'X');
+ ts->ts_fakegcc = strchr(src, 'X');
+ ts->ts_fakegcc = strchr(src, 'X');
+ ts->ts_fakegcc = strchr(src, 'X');
+ ts->ts_fakegcc = strchr(src, 'X');
+ ts->ts_fakegcc = strchr(src, 'X');
+ ts->ts_fakegcc = strchr(src, 'X');
+ }
+
+ res->re_count = lm_optB;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ if (unaligned == 0)
+ (void) sprintf(result, "%8d", opts);
+ else
+ (void) sprintf(result, "%8d <unaligned>", opts);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/strcmp.c b/native/libMicro-0.4.0/strcmp.c
new file mode 100644
index 0000000..8f40a87
--- /dev/null
+++ b/native/libMicro-0.4.0/strcmp.c
@@ -0,0 +1,147 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "libmicro.h"
+
+static int unaligned = 0;
+static int opts = 100;
+
+typedef struct {
+ int ts_once;
+ char *ts_a;
+ char *ts_b;
+ int ts_fakegcc;
+} tsd_t;
+
+int
+benchmark_init()
+{
+
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "s:n");
+
+ (void) sprintf(lm_usage,
+ " [-s string size (default %d)]\n"
+ " [-n causes unaligned cmp]\n"
+ "notes: measures strcmp()\n",
+ opts);
+
+ (void) sprintf(lm_header, "%8s", "size");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'n':
+ unaligned = 1;
+ break;
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ static char *demo =
+ "The quick brown fox jumps over the lazy dog.";
+
+ if (ts->ts_once++ == 0) {
+ int l = strlen(demo);
+ int i;
+
+ ts->ts_a = malloc(opts + 1);
+ ts->ts_b = malloc(opts + 1 + unaligned);
+ ts->ts_b += unaligned;
+
+ for (i = 0; i < opts; i++) {
+ ts->ts_a[i] = ts->ts_b[i] = demo[i%l];
+ }
+ ts->ts_a[opts] = 0;
+ ts->ts_b[opts] = 0;
+ }
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+ int *sum = &ts->ts_fakegcc;
+ char *src = ts->ts_a;
+ char *src2 = ts->ts_b;
+
+ res->re_errors = 0;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ *sum += strcmp(src, src2);
+ *sum += strcmp(src, src2);
+ *sum += strcmp(src, src2);
+ *sum += strcmp(src, src2);
+ *sum += strcmp(src, src2);
+ *sum += strcmp(src, src2);
+ *sum += strcmp(src, src2);
+ *sum += strcmp(src, src2);
+ *sum += strcmp(src, src2);
+ *sum += strcmp(src, src2);
+ }
+
+ res->re_count = lm_optB;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ if (unaligned == 0)
+ (void) sprintf(result, "%8d", opts);
+ else
+ (void) sprintf(result, "%8d <unaligned>", opts);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/strcpy.c b/native/libMicro-0.4.0/strcpy.c
new file mode 100644
index 0000000..7c1d479
--- /dev/null
+++ b/native/libMicro-0.4.0/strcpy.c
@@ -0,0 +1,145 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "libmicro.h"
+
+static int unaligned = 0;
+static int opts = 100;
+
+typedef struct {
+ int ts_once;
+ char *ts_a;
+ char *ts_b;
+} tsd_t;
+
+int
+benchmark_init()
+{
+
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "s:n");
+
+ (void) sprintf(lm_usage,
+ " [-s string size (default %d)]\n"
+ " [-n causes unaligned cmp]\n"
+ "notes: measures strcpy()\n",
+ opts);
+
+ (void) sprintf(lm_header, "%8s", "size");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'n':
+ unaligned = 1;
+ break;
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ static char *demo =
+ "The quick brown fox jumps over the lazy dog.";
+
+ if (ts->ts_once++ == 0) {
+ int l = strlen(demo);
+ int i;
+
+ ts->ts_a = malloc(opts + 1);
+ ts->ts_b = malloc(opts + 1 + unaligned);
+ ts->ts_b += unaligned;
+
+ for (i = 0; i < opts; i++) {
+ ts->ts_b[i] = demo[i%l];
+ }
+ ts->ts_b[opts] = 0;
+ }
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+
+ char *src = ts->ts_a;
+ char *src2 = ts->ts_b;
+
+ res->re_errors = 0;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ (void) strcpy(src, src2);
+ (void) strcpy(src, src2);
+ (void) strcpy(src, src2);
+ (void) strcpy(src, src2);
+ (void) strcpy(src, src2);
+ (void) strcpy(src, src2);
+ (void) strcpy(src, src2);
+ (void) strcpy(src, src2);
+ (void) strcpy(src, src2);
+ (void) strcpy(src, src2);
+ }
+
+ res->re_count = lm_optB;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ if (unaligned == 0)
+ (void) sprintf(result, "%8d", opts);
+ else
+ (void) sprintf(result, "%8d <unaligned>", opts);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/strftime.c b/native/libMicro-0.4.0/strftime.c
new file mode 100644
index 0000000..3aeca1c
--- /dev/null
+++ b/native/libMicro-0.4.0/strftime.c
@@ -0,0 +1,129 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include "libmicro.h"
+
+#define DEFF "%c"
+#define MAXSIZE 80
+
+static char *optf = DEFF;
+
+typedef struct {
+ int ts_once;
+ struct tm ts_tm1;
+ struct tm ts_tm2;
+} tsd_t;
+
+int
+benchmark_init()
+{
+
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "f:");
+
+ (void) sprintf(lm_usage,
+ " [-f format (default = \"%s\")]\n"
+ "notes: measures strftime()\n",
+ DEFF);
+
+ (void) sprintf(lm_header, "%8s", "format");
+
+ return (0);
+}
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+
+ case 'f':
+ optf = optarg;
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%8s", optf);
+
+ return (result);
+}
+
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+
+ static time_t clock1 = 0L;
+ static time_t clock2 = 1L;
+
+ (void) localtime_r(&clock1, &ts->ts_tm1);
+ (void) localtime_r(&clock2, &ts->ts_tm2);
+
+ return (0);
+}
+
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+ char s[MAXSIZE];
+
+ for (i = 0; i < lm_optB; i += 10) {
+ (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1);
+ (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2);
+ (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1);
+ (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2);
+ (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1);
+ (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2);
+ (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1);
+ (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2);
+ (void) strftime(s, MAXSIZE, optf, &ts->ts_tm1);
+ (void) strftime(s, MAXSIZE, optf, &ts->ts_tm2);
+ }
+ res->re_count = lm_optB;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/strlen.c b/native/libMicro-0.4.0/strlen.c
new file mode 100644
index 0000000..5806c61
--- /dev/null
+++ b/native/libMicro-0.4.0/strlen.c
@@ -0,0 +1,143 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "libmicro.h"
+
+static int unaligned = 0;
+static int opts = 100;
+
+typedef struct {
+ int ts_once;
+ char *ts_string;
+ int ts_fakegcc;
+} tsd_t;
+
+int
+benchmark_init()
+{
+
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "s:n");
+
+ (void) sprintf(lm_usage,
+ " [-s string size (default %d)]\n"
+ " [-n causes unaligned strlen]\n"
+ "notes: measures strlen()\n",
+ opts);
+
+ (void) sprintf(lm_header, "%8s", "size");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'n':
+ unaligned = 1;
+ break;
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ static char *demo =
+ "The quick brown fox jumps over the lazy dog.";
+
+ if (ts->ts_once++ == 0) {
+ int l = strlen(demo);
+ int i;
+
+ ts->ts_string = malloc(opts + 1 + unaligned);
+ ts->ts_string += unaligned;
+
+
+ for (i = 0; i < opts; i++) {
+ ts->ts_string[i] = demo[i%l];
+ }
+
+ ts->ts_string[opts] = 0;
+
+ }
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ tsd_t *ts = (tsd_t *)tsd;
+ char *src = ts->ts_string;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ ts->ts_fakegcc += strlen(src);
+ ts->ts_fakegcc += strlen(src);
+ ts->ts_fakegcc += strlen(src);
+ ts->ts_fakegcc += strlen(src);
+ ts->ts_fakegcc += strlen(src);
+ ts->ts_fakegcc += strlen(src);
+ ts->ts_fakegcc += strlen(src);
+ ts->ts_fakegcc += strlen(src);
+ ts->ts_fakegcc += strlen(src);
+ ts->ts_fakegcc += strlen(src);
+ }
+
+ res->re_count = lm_optB;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ if (unaligned == 0)
+ (void) sprintf(result, "%8d", opts);
+ else
+ (void) sprintf(result, "%8d <unaligned>", opts);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/strtol.c b/native/libMicro-0.4.0/strtol.c
new file mode 100644
index 0000000..02f8abc
--- /dev/null
+++ b/native/libMicro-0.4.0/strtol.c
@@ -0,0 +1,67 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ (void) sprintf(lm_usage, "note: measures strtol()");
+ lm_tsdsize = 0;
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ (void) strtol("1", NULL, 10);
+ (void) strtol("11", NULL, 10);
+ (void) strtol("123", NULL, 10);
+ (void) strtol("1234", NULL, 10);
+ (void) strtol("12345", NULL, 10);
+ (void) strtol("123456", NULL, 10);
+ (void) strtol("1234567", NULL, 10);
+ (void) strtol("12345678", NULL, 10);
+ (void) strtol("123456789", NULL, 10);
+ (void) strtol("1234567890", NULL, 10);
+ }
+ res->re_count = i;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/system.c b/native/libMicro-0.4.0/system.c
new file mode 100644
index 0000000..d70db26
--- /dev/null
+++ b/native/libMicro-0.4.0/system.c
@@ -0,0 +1,98 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "libmicro.h"
+
+#define DEFB 10
+#define DEFC "A=$$"
+
+static char *optc = DEFC;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = 0;
+
+ (void) sprintf(lm_optstr, "c:");
+
+ (void) sprintf(lm_usage,
+ " [-c command (default %s)]\n"
+ "notes: measures system()\n",
+ DEFC);
+
+ (void) sprintf(lm_header, "%8s", "command");
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'c':
+ optc = optarg;
+ break;
+ default:
+ return (-1);
+ }
+
+ return (0);
+}
+
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (system(optc) != 0) {
+ res->re_errors++;
+ }
+ }
+ res->re_count = lm_optB;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%8s", optc);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/tattle.c b/native/libMicro-0.4.0/tattle.c
new file mode 100644
index 0000000..59520f8
--- /dev/null
+++ b/native/libMicro-0.4.0/tattle.c
@@ -0,0 +1,154 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+#include <time.h>
+#include <tattle.h>
+#include "libmicro.h"
+#include <math.h>
+
+
+#ifdef USE_RDTSC
+#ifdef __GNUC__
+#define ENABLE_RDTSC 1
+#endif
+#endif
+
+/*
+ * dummy so we can link w/ libmicro
+ */
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ return (0);
+}
+
+static void
+cleanup(char *s)
+{
+ char *o = s;
+ char *e;
+
+ while (*s == ' ')
+ s++;
+
+ if (o != s)
+ (void) strcpy(o, s);
+
+ e = o;
+
+ while (*e != 0)
+ e++;
+
+ e--;
+
+ while (*e == ' ' && e > o)
+ *e-- = 0;
+
+}
+
+
+int
+main(int argc, char *argv[])
+{
+ int c;
+
+ if (strlen(compiler_version) > 30)
+ compiler_version[30] = 0;
+
+ cleanup(compiler_version);
+ cleanup(extra_compiler_flags);
+
+ while ((c = getopt(argc, argv, "vcfrsVTR")) != -1) {
+ switch (c) {
+ case 'V':
+ (void) printf("%s\n", LIBMICRO_VERSION);
+ break;
+ case 'v':
+ (void) printf("%s\n", compiler_version);
+ break;
+ case 'c':
+ (void) printf("%s\n", CC);
+ break;
+ case 'f':
+ if (strlen(extra_compiler_flags) == 0)
+ (void) printf("[none]\n");
+ else
+ (void) printf("%s\n", extra_compiler_flags);
+ break;
+
+ case 's':
+ (void) printf("%d\n", sizeof (long));
+ break;
+
+ case 'r':
+
+ (void) printf("%lld nsecs\n", get_nsecs_resolution());
+ break;
+
+ case 'R':
+#ifdef ENABLE_RDTSC
+ {
+ struct timeval s;
+ struct timeval f;
+ long long start_nsecs;
+ long long end_nsecs;
+ long elapsed_usecs;
+
+ gettimeofday(&s, NULL);
+ start_nsecs = rdtsc();
+ for (;;) {
+ gettimeofday(&f, NULL);
+ elapsed_usecs = (f.tv_sec - s.tv_sec) *
+ 1000000 + (f.tv_usec - s.tv_usec);
+ if (elapsed_usecs > 1000000)
+ break;
+ }
+ end_nsecs = rdtsc();
+ (void) printf("LIBMICRO_HZ=%lld\n",
+ (long long)elapsed_usecs *
+ (end_nsecs - start_nsecs) / 1000000LL);
+ }
+#else
+ (void) printf("\n");
+#endif
+ break;
+ }
+ }
+
+ exit(0);
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/time.c b/native/libMicro-0.4.0/time.c
new file mode 100644
index 0000000..d4d0fa8
--- /dev/null
+++ b/native/libMicro-0.4.0/time.c
@@ -0,0 +1,69 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+ lm_tsdsize = 0;
+
+ (void) sprintf(lm_usage,
+ "notes: measures time()\n");
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ (void) time(NULL);
+ (void) time(NULL);
+ (void) time(NULL);
+ (void) time(NULL);
+ (void) time(NULL);
+ (void) time(NULL);
+ (void) time(NULL);
+ (void) time(NULL);
+ (void) time(NULL);
+ (void) time(NULL);
+ }
+ res->re_count += lm_optB;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/times.c b/native/libMicro-0.4.0/times.c
new file mode 100644
index 0000000..6dc7515
--- /dev/null
+++ b/native/libMicro-0.4.0/times.c
@@ -0,0 +1,73 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/times.h>
+#include <limits.h>
+
+#include "libmicro.h"
+
+int
+benchmark_init()
+{
+
+ lm_tsdsize = 0;
+
+ (void) sprintf(lm_usage,
+ "notes: measures times()\n");
+
+ return (0);
+}
+
+/*ARGSUSED*/
+int
+benchmark(void *tsd, result_t *res)
+{
+ int i;
+ struct tms buf;
+
+ for (i = 0; i < lm_optB; i += 10) {
+ (void) times(&buf);
+ (void) times(&buf);
+ (void) times(&buf);
+ (void) times(&buf);
+ (void) times(&buf);
+ (void) times(&buf);
+ (void) times(&buf);
+ (void) times(&buf);
+ (void) times(&buf);
+ (void) times(&buf);
+ }
+ res->re_count += lm_optB;
+
+ return (0);
+}
diff --git a/native/libMicro-0.4.0/wrapper.sh b/native/libMicro-0.4.0/wrapper.sh
new file mode 100644
index 0000000..791643d
--- /dev/null
+++ b/native/libMicro-0.4.0/wrapper.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms
+# of the Common Development and Distribution License
+# (the "License"). You may not use this file except
+# in compliance with the License.
+#
+# You can obtain a copy of the license at
+# src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL
+# HEADER in each file and include the License file at
+# usr/src/OPENSOLARIS.LICENSE. If applicable,
+# add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your
+# own identifying information: Portions Copyright [yyyy]
+# [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+
+BASENAME=`basename $0`
+DIRNAME=`dirname $0`
+ARCH=`uname -m`
+
+exec $DIRNAME/../bin-$ARCH/$BASENAME "$@"
diff --git a/native/libMicro-0.4.0/write.c b/native/libMicro-0.4.0/write.c
new file mode 100644
index 0000000..0780274
--- /dev/null
+++ b/native/libMicro-0.4.0/write.c
@@ -0,0 +1,154 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifdef linux
+#define _XOPEN_SOURCE 500
+#endif
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#include "libmicro.h"
+
+typedef struct {
+ char *ts_buf;
+ int ts_fd;
+} tsd_t;
+
+#define DEFF "/dev/null"
+#define DEFS 1024
+
+static int optc = 0;
+static char *optf = DEFF;
+static long long opts = DEFS;
+static int optd;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "cdf:s:");
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-write (default %s)]\n"
+ " [-s buffer-size (default %d)]\n"
+ " [-c ] (make sure buffer is in cache)\n"
+#ifdef __sun
+ " [-d ] use directio"
+#endif
+ "notes: measures write()\n",
+ DEFF, DEFS);
+
+ (void) sprintf(lm_header, "%8s", "size");
+
+ lm_defB = 1;
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+
+ case 'd':
+ optd++;
+ break;
+ case 'c':
+ optc++;
+ break;
+ case 'f':
+ optf = optarg;
+ break;
+ case 's':
+ opts = sizetoll(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ if (ts->ts_buf == NULL) {
+ ts->ts_buf = malloc(opts);
+ ts->ts_fd = open(optf, O_WRONLY);
+
+#ifdef __sun
+ if (optd)
+ (void) directio(ts->ts_fd, DIRECTIO_ON);
+#endif
+ /*
+ * bring buf into cache if specified.
+ */
+
+ if (optc)
+ for (i = 0; i < opts; i++)
+ ts->ts_buf[i] = 0;
+ }
+
+ (void) lseek(ts->ts_fd, 0, SEEK_SET);
+
+ return (0);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (write(ts->ts_fd, ts->ts_buf, opts) != opts) {
+ res->re_errors++;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%8lld", opts);
+
+ return (result);
+}
diff --git a/native/libMicro-0.4.0/writev.c b/native/libMicro-0.4.0/writev.c
new file mode 100644
index 0000000..ac1bf2e
--- /dev/null
+++ b/native/libMicro-0.4.0/writev.c
@@ -0,0 +1,149 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms
+ * of the Common Development and Distribution License
+ * (the "License"). You may not use this file except
+ * in compliance with the License.
+ *
+ * You can obtain a copy of the license at
+ * src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing
+ * permissions and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL
+ * HEADER in each file and include the License file at
+ * usr/src/OPENSOLARIS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your
+ * own identifying information: Portions Copyright [yyyy]
+ * [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <sys/uio.h>
+#include <limits.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+
+#ifndef IOV_MAX
+#define IOV_MAX UIO_MAXIOV
+#endif
+
+#include "libmicro.h"
+
+typedef struct {
+ int ts_once;
+ struct iovec *ts_iov;
+ int ts_fd;
+} tsd_t;
+
+#define DEFF "/dev/null"
+#define DEFS 1024
+#define DEFV 10
+
+static char *optf = DEFF;
+static int opts = DEFS;
+static int optv = DEFV;
+
+int
+benchmark_init()
+{
+ lm_tsdsize = sizeof (tsd_t);
+
+ (void) sprintf(lm_optstr, "f:s:v:");
+
+ (void) sprintf(lm_usage,
+ " [-f file-to-write (default %s)]\n"
+ " [-s buffer-size (default %d)]\n"
+ " [-v vector-size (default %d)]\n"
+ "notes: measures writev()\n"
+ " IOV_MAX is %d\n"
+ " SSIZE_MAX is %ld\n",
+ DEFF, DEFS, DEFV, IOV_MAX, SSIZE_MAX);
+
+ (void) sprintf(lm_header, "%8s %4s", "size", "vec");
+
+ lm_defB = 1;
+
+ return (0);
+}
+
+int
+benchmark_optswitch(int opt, char *optarg)
+{
+ switch (opt) {
+ case 'f':
+ optf = optarg;
+ break;
+ case 's':
+ opts = sizetoint(optarg);
+ break;
+ case 'v':
+ optv = atoi(optarg);
+ break;
+ default:
+ return (-1);
+ }
+ return (0);
+}
+
+int
+benchmark_initbatch(void *tsd)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+ int errors = 0;
+
+ if (ts->ts_once++ == 0) {
+ ts->ts_fd = open(optf, O_WRONLY);
+ if (ts->ts_fd == -1) {
+ errors++;
+ }
+ ts->ts_iov = (struct iovec *)malloc(
+ optv * sizeof (struct iovec));
+ for (i = 0; i < optv; i++) {
+ ts->ts_iov[i].iov_base = malloc(opts);
+ ts->ts_iov[i].iov_len = opts;
+ }
+ }
+
+ (void) lseek(ts->ts_fd, 0, SEEK_SET);
+
+ return (errors);
+}
+
+int
+benchmark(void *tsd, result_t *res)
+{
+ tsd_t *ts = (tsd_t *)tsd;
+ int i;
+
+ for (i = 0; i < lm_optB; i++) {
+ if (writev(ts->ts_fd, ts->ts_iov, optv) != opts * optv) {
+ res->re_errors++;
+ }
+ }
+ res->re_count = i;
+
+ return (0);
+}
+
+char *
+benchmark_result()
+{
+ static char result[256];
+
+ (void) sprintf(result, "%8d %4d", opts, optv);
+
+ return (result);
+}
diff --git a/res/drawable-hdpi/crate.bmp b/res/drawable-hdpi/crate.bmp
new file mode 100644
index 0000000..73fe985
--- /dev/null
+++ b/res/drawable-hdpi/crate.bmp
Binary files differ
diff --git a/res/drawable-hdpi/glass.bmp b/res/drawable-hdpi/glass.bmp
new file mode 100644
index 0000000..1acf064
--- /dev/null
+++ b/res/drawable-hdpi/glass.bmp
Binary files differ
diff --git a/res/drawable-hdpi/icon.png b/res/drawable-hdpi/icon.png
new file mode 100644
index 0000000..1f34e32
--- /dev/null
+++ b/res/drawable-hdpi/icon.png
Binary files differ
diff --git a/res/drawable-hdpi/icon_auto.png b/res/drawable-hdpi/icon_auto.png
new file mode 100644
index 0000000..b572bbf
--- /dev/null
+++ b/res/drawable-hdpi/icon_auto.png
Binary files differ
diff --git a/res/drawable-ldpi/crate.bmp b/res/drawable-ldpi/crate.bmp
new file mode 100644
index 0000000..73fe985
--- /dev/null
+++ b/res/drawable-ldpi/crate.bmp
Binary files differ
diff --git a/res/drawable-ldpi/glass.bmp b/res/drawable-ldpi/glass.bmp
new file mode 100644
index 0000000..1acf064
--- /dev/null
+++ b/res/drawable-ldpi/glass.bmp
Binary files differ
diff --git a/res/drawable-ldpi/icon.png b/res/drawable-ldpi/icon.png
new file mode 100644
index 0000000..1f34e32
--- /dev/null
+++ b/res/drawable-ldpi/icon.png
Binary files differ
diff --git a/res/drawable-ldpi/icon_auto.png b/res/drawable-ldpi/icon_auto.png
new file mode 100644
index 0000000..b572bbf
--- /dev/null
+++ b/res/drawable-ldpi/icon_auto.png
Binary files differ
diff --git a/res/drawable-mdpi/crate.bmp b/res/drawable-mdpi/crate.bmp
new file mode 100644
index 0000000..73fe985
--- /dev/null
+++ b/res/drawable-mdpi/crate.bmp
Binary files differ
diff --git a/res/drawable-mdpi/glass.bmp b/res/drawable-mdpi/glass.bmp
new file mode 100644
index 0000000..1acf064
--- /dev/null
+++ b/res/drawable-mdpi/glass.bmp
Binary files differ
diff --git a/res/drawable-mdpi/icon.png b/res/drawable-mdpi/icon.png
new file mode 100644
index 0000000..1f34e32
--- /dev/null
+++ b/res/drawable-mdpi/icon.png
Binary files differ
diff --git a/res/drawable-mdpi/icon_auto.png b/res/drawable-mdpi/icon_auto.png
new file mode 100644
index 0000000..b572bbf
--- /dev/null
+++ b/res/drawable-mdpi/icon_auto.png
Binary files differ
diff --git a/res/drawable/crate.bmp b/res/drawable/crate.bmp
new file mode 100644
index 0000000..73fe985
--- /dev/null
+++ b/res/drawable/crate.bmp
Binary files differ
diff --git a/res/drawable/glass.bmp b/res/drawable/glass.bmp
new file mode 100644
index 0000000..1acf064
--- /dev/null
+++ b/res/drawable/glass.bmp
Binary files differ
diff --git a/res/drawable/icon.png b/res/drawable/icon.png
new file mode 100644
index 0000000..1f34e32
--- /dev/null
+++ b/res/drawable/icon.png
Binary files differ
diff --git a/res/drawable/icon_auto.png b/res/drawable/icon_auto.png
new file mode 100644
index 0000000..b572bbf
--- /dev/null
+++ b/res/drawable/icon_auto.png
Binary files differ
diff --git a/res/layout/gc.xml b/res/layout/gc.xml
new file mode 100644
index 0000000..8422b94
--- /dev/null
+++ b/res/layout/gc.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ >
+<ScrollView
+ android:id="@+id/myScrollView"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+>
+<AbsoluteLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ >
+ <TextView
+ android:id="@+id/myTextView1"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:typeface="monospace"
+ />
+
+</AbsoluteLayout>
+
+</ScrollView>
+</HorizontalScrollView>
diff --git a/res/layout/login_dialog.xml b/res/layout/login_dialog.xml
new file mode 100644
index 0000000..6a18dac
--- /dev/null
+++ b/res/layout/login_dialog.xml
@@ -0,0 +1,12 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/layout_root"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:padding="10dp"
+ >
+ <WebView android:id="@+id/web_view"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ />
+</LinearLayout>
diff --git a/res/layout/main.xml b/res/layout/main.xml
new file mode 100644
index 0000000..82aa47e
--- /dev/null
+++ b/res/layout/main.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical"
+ >
+
+ <ScrollView android:id="@+id/list_scroller"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="5"
+ >
+
+ <LinearLayout android:id="@+id/list_container"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical"
+ >
+
+ <ImageView android:id="@+id/banner_img"
+ android:src="@drawable/icon"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_gravity="center"
+ />
+ <TextView android:id="@+id/banner_info"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:gravity="center"
+ android:textSize="24px"
+ />
+
+ </LinearLayout>
+
+ </ScrollView>
+
+ <LinearLayout android:id="@+id/buttons_container"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ >
+ <Button android:id="@+id/btn_run"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/btn_run_text"
+ />
+ <Button android:id="@+id/btn_show"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/btn_show_text"
+ />
+ </LinearLayout>
+</LinearLayout>
+
diff --git a/res/layout/report.xml b/res/layout/report.xml
new file mode 100644
index 0000000..2df928e
--- /dev/null
+++ b/res/layout/report.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical"
+ >
+
+ <ScrollView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="5"
+ >
+ <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ >
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+ <TextView
+ android:id="@+id/report_text"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:typeface="monospace"
+ />
+ </LinearLayout>
+ </HorizontalScrollView>
+ </ScrollView>
+
+ <LinearLayout android:id="@+id/buttons_container"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ >
+ <Button android:id="@+id/btn_back"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/btn_back_text"
+ />
+ <Button android:id="@+id/btn_upload"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/btn_upload_text"
+ />
+ </LinearLayout>
+
+</LinearLayout>
+
diff --git a/res/layout/upload.xml b/res/layout/upload.xml
new file mode 100644
index 0000000..bb7d60c
--- /dev/null
+++ b/res/layout/upload.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ >
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/txtvw_upload_help"
+ android:textSize="28px"
+ />
+ <CheckBox
+ android:id="@+id/login"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/login"
+ />
+ <Button
+ android:id="@+id/login_google"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/btn_login_google"
+ />
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/txtvw_benchname"
+ />
+ <EditText
+ android:id="@+id/benchName"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/default_benchname"
+ />
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ />
+ <EditText
+ android:id="@+id/email"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ />
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/txtvw_api"
+ />
+ <EditText
+ android:id="@+id/api"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ />
+ <Button
+ android:id="@+id/send"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/btn_send_text"
+ />
+</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
new file mode 100644
index 0000000..1daa12c
--- /dev/null
+++ b/res/values/strings.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+<string name="btn_run_text">Run</string>
+<string name="btn_show_text">Show</string>
+<string name="btn_upload_text">Upload</string>
+
+<string name="txtvw_upload_help">Click "send" to upload to default page, or check "login" to create your own page (you need to get apikey from 0xBenchWeb first).</string>
+<string name="txtvw_benchname">Upload to benchmark page:</string>
+<string name="txtvw_email">Email:</string>
+<string name="txtvw_api">API Key:</string>
+<string name="btn_send_text">Send</string>
+<string name="btn_back_text">Done</string>
+<string name="btn_login_google">Login for API-key</string>
+
+<string name="default_benchname">PublicPage</string>
+<string name="default_appspot">0xbenchmark</string>
+<string name="default_email">ZXBench@gmail.com</string>
+<string name="default_api">32935947-ed54-43b3-b3b2-a38223c6ec47</string>
+
+<string name="login">Login</string>
+
+
+<!-- its not typo -->
+<string name="banner_info_text">Hell World!</string>
+</resources>
diff --git a/src/com/nea/nehe/lesson08/Cube.java b/src/com/nea/nehe/lesson08/Cube.java
new file mode 100644
index 0000000..412bd7a
--- /dev/null
+++ b/src/com/nea/nehe/lesson08/Cube.java
@@ -0,0 +1,335 @@
+/*
+ * Authors Name: Jeff Molofee (NeHe)
+ *
+ * Disclaimer:
+ * This program may crash your system or run poorly depending on your
+ * hardware. The program and code contained in this archive was scanned
+ * for virii and has passed all test before it was put online. If you
+ * use this code in project of your own, send a shout out to the author!
+ *
+ * Ported to Android by INsanityDesign:
+ * http://insanitydesign.com/wp/projects/nehe-android-ports/
+ */
+
+package com.nea.nehe.lesson08;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+
+import javax.microedition.khronos.opengles.GL10;
+import javax.microedition.khronos.opengles.GL11;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.opengl.GLUtils;
+
+/**
+ * This class is an object representation of
+ * a Cube containing the vertex information,
+ * texture coordinates, the vertex indices
+ * and drawing functionality, which is called
+ * by the renderer.
+ *
+ * @author Savas Ziplies (nea/INsanityDesign)
+ */
+public class Cube {
+
+ /** The buffer holding the vertices */
+ private FloatBuffer vertexBuffer;
+ /** The buffer holding the texture coordinates */
+ private FloatBuffer textureBuffer;
+ /** The buffer holding the indices */
+ private ByteBuffer indexBuffer;
+ /** The buffer holding the normals */
+ private FloatBuffer normalBuffer;
+
+ /** Our texture pointer */
+ private int[] textures = new int[3];
+
+ /** The initial vertex definition */
+ private float vertices[] = {
+ // Vertices according to faces
+ -1.0f, -1.0f, 1.0f, //v0
+ 1.0f, -1.0f, 1.0f, //v1
+ -1.0f, 1.0f, 1.0f, //v2
+ 1.0f, 1.0f, 1.0f, //v3
+
+ 1.0f, -1.0f, 1.0f, //...
+ 1.0f, -1.0f, -1.0f,
+ 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, -1.0f,
+
+ 1.0f, -1.0f, -1.0f,
+ -1.0f, -1.0f, -1.0f,
+ 1.0f, 1.0f, -1.0f,
+ -1.0f, 1.0f, -1.0f,
+
+ -1.0f, -1.0f, -1.0f,
+ -1.0f, -1.0f, 1.0f,
+ -1.0f, 1.0f, -1.0f,
+ -1.0f, 1.0f, 1.0f,
+
+ -1.0f, -1.0f, -1.0f,
+ 1.0f, -1.0f, -1.0f,
+ -1.0f, -1.0f, 1.0f,
+ 1.0f, -1.0f, 1.0f,
+
+ -1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f,
+ -1.0f, 1.0f, -1.0f,
+ 1.0f, 1.0f, -1.0f,
+ };
+
+ /** The initial normals for the lighting calculations */
+ private float normals[] = {
+ //Normals
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+ };
+
+ /** The initial texture coordinates (u, v) */
+ private float texture[] = {
+ //Mapping coordinates for the vertices
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+ };
+
+ /** The initial indices definition */
+ private byte indices[] = {
+ // Faces definition
+ 0, 1, 3, 0, 3, 2, // Face front
+ 4, 5, 7, 4, 7, 6, // Face right
+ 8, 9, 11, 8, 11, 10, // ...
+ 12, 13, 15, 12, 15, 14,
+ 16, 17, 19, 16, 19, 18,
+ 20, 21, 23, 20, 23, 22,
+ };
+
+ /**
+ * The Cube constructor.
+ *
+ * Initiate the buffers.
+ */
+ public Cube() {
+ //
+ ByteBuffer byteBuf = ByteBuffer.allocateDirect(vertices.length * 4);
+ byteBuf.order(ByteOrder.nativeOrder());
+ vertexBuffer = byteBuf.asFloatBuffer();
+ vertexBuffer.put(vertices);
+ vertexBuffer.position(0);
+
+ //
+ byteBuf = ByteBuffer.allocateDirect(texture.length * 4);
+ byteBuf.order(ByteOrder.nativeOrder());
+ textureBuffer = byteBuf.asFloatBuffer();
+ textureBuffer.put(texture);
+ textureBuffer.position(0);
+
+ //
+ byteBuf = ByteBuffer.allocateDirect(normals.length * 4);
+ byteBuf.order(ByteOrder.nativeOrder());
+ normalBuffer = byteBuf.asFloatBuffer();
+ normalBuffer.put(normals);
+ normalBuffer.position(0);
+
+ //
+ indexBuffer = ByteBuffer.allocateDirect(indices.length);
+ indexBuffer.put(indices);
+ indexBuffer.position(0);
+ }
+
+ /**
+ * The object own drawing function.
+ * Called from the renderer to redraw this instance
+ * with possible changes in values.
+ *
+ * @param gl - The GL Context
+ * @param filter - Which texture filter to be used
+ */
+ public void draw(GL10 gl, int filter) {
+ //Bind the texture according to the set texture filter
+ gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[filter]);
+
+ //Enable the vertex, texture and normal state
+ gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
+ gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
+ gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
+
+ //Set the face rotation
+ gl.glFrontFace(GL10.GL_CCW);
+
+ //Point to our buffers
+ gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
+ gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
+ gl.glNormalPointer(GL10.GL_FLOAT, 0, normalBuffer);
+
+ //Draw the vertices as triangles, based on the Index Buffer information
+ gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer);
+
+ //Disable the client state before leaving
+ gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
+ gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
+ gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
+ }
+
+ /**
+ * Load the textures
+ *
+ * @param gl - The GL Context
+ * @param context - The Activity context
+ */
+ public void loadGLTexture(GL10 gl, Context context) {
+ //Get the texture from the Android resource directory
+ InputStream is = context.getResources().openRawResource(org.zeroxlab.benchmark.R.drawable.glass);
+ Bitmap bitmap = null;
+ try {
+ //BitmapFactory is an Android graphics utility for images
+ bitmap = BitmapFactory.decodeStream(is);
+
+ } finally {
+ //Always clear and close
+ try {
+ is.close();
+ is = null;
+ } catch (IOException e) {
+ }
+ }
+
+ //Generate there texture pointer
+ gl.glGenTextures(3, textures, 0);
+
+ //Create Nearest Filtered Texture and bind it to texture 0
+ gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
+ gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST);
+ gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
+ GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
+
+ //Create Linear Filtered Texture and bind it to texture 1
+ gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[1]);
+ gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
+ gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
+ GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
+
+ //Create mipmapped textures and bind it to texture 2
+ gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[2]);
+ gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
+ gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_NEAREST);
+ /*
+ * This is a change to the original tutorial, as buildMipMap does not exist anymore
+ * in the Android SDK.
+ *
+ * We check if the GL context is version 1.1 and generate MipMaps by flag.
+ * Otherwise we call our own buildMipMap implementation
+ */
+ if(gl instanceof GL11) {
+ gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
+ GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
+
+ //
+ } else {
+ buildMipmap(gl, bitmap);
+ }
+
+ //Clean up
+ bitmap.recycle();
+ }
+
+ /**
+ * Our own MipMap generation implementation.
+ * Scale the original bitmap down, always by factor two,
+ * and set it as new mipmap level.
+ *
+ * Thanks to Mike Miller (with minor changes)!
+ *
+ * @param gl - The GL Context
+ * @param bitmap - The bitmap to mipmap
+ */
+ private void buildMipmap(GL10 gl, Bitmap bitmap) {
+ //
+ int level = 0;
+ //
+ int height = bitmap.getHeight();
+ int width = bitmap.getWidth();
+
+ //
+ while(height >= 1 || width >= 1) {
+ //First of all, generate the texture from our bitmap and set it to the according level
+ GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bitmap, 0);
+
+ //
+ if(height == 1 || width == 1) {
+ break;
+ }
+
+ //Increase the mipmap level
+ level++;
+
+ //
+ height /= 2;
+ width /= 2;
+ Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, width, height, true);
+
+ //Clean up
+ bitmap.recycle();
+ bitmap = bitmap2;
+ }
+ }
+}
diff --git a/src/com/nea/nehe/lesson08/Lesson08.java b/src/com/nea/nehe/lesson08/Lesson08.java
new file mode 100644
index 0000000..9b1553c
--- /dev/null
+++ b/src/com/nea/nehe/lesson08/Lesson08.java
@@ -0,0 +1,339 @@
+/*
+ * Authors Name: Jeff Molofee (NeHe)
+ *
+ * Disclaimer:
+ * This program may crash your system or run poorly depending on your
+ * hardware. The program and code contained in this archive was scanned
+ * for virii and has passed all test before it was put online. If you
+ * use this code in project of your own, send a shout out to the author!
+ *
+ * Ported to Android by INsanityDesign:
+ * http://insanitydesign.com/wp/projects/nehe-android-ports/
+ *
+ * Adapted by 0xlab developers.
+ */
+
+package com.nea.nehe.lesson08;
+
+import org.zeroxlab.benchmark.Tester;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+import android.content.Context;
+import android.opengl.GLSurfaceView;
+import android.opengl.GLU;
+import android.opengl.GLSurfaceView.Renderer;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+
+/**
+ * This is a port of the {@link http://nehe.gamedev.net} OpenGL
+ * tutorials to the Android 1.5 OpenGL ES platform. Thanks to
+ * NeHe and all contributors for their great tutorials and great
+ * documentation. This source should be used together with the
+ * textual explanations made at {@link http://nehe.gamedev.net}.
+ * The code is based on the original Visual C++ code with all
+ * comments made. It has been altered and extended to meet the
+ * Android requirements. The Java code has according comments.
+ *
+ * If you use this code or find it helpful, please visit and send
+ * a shout to the author under {@link http://www.insanitydesign.com/}
+ *
+ * @DISCLAIMER
+ * This source and the whole package comes without warranty. It may or may
+ * not harm your computer or cell phone. Please use with care. Any damage
+ * cannot be related back to the author. The source has been tested on a
+ * virtual environment and scanned for viruses and has passed all tests.
+ *
+ *
+ * This is an interpretation of "Lesson 08: Blending"
+ * for the Google Android platform.
+ *
+ * @author Savas Ziplies (nea/INsanityDesign)
+ */
+public class Lesson08 extends GLSurfaceView implements Renderer {
+
+ private Tester mTester;
+
+ /** Cube instance */
+ private Cube cube;
+
+ /* Rotation values */
+ private float xrot; //X Rotation
+ private float yrot; //Y Rotation
+
+ /* Rotation speed values */
+ private float xspeed; //X Rotation Speed
+ private float yspeed; //Y Rotation Speed
+
+ private float z = -5.0f; //Depth Into The Screen
+
+ private int filter = 0; //Which texture filter?
+
+ /** Is light enabled */
+ private boolean light = true;
+ /** Is blending enabled ( NEW ) */
+ private boolean blend = true;
+
+ /* The initial light values */
+ private float[] lightAmbient = {0.5f, 0.5f, 0.5f, 1.0f};
+ private float[] lightDiffuse = {1.0f, 1.0f, 1.0f, 1.0f};
+ private float[] lightPosition = {0.0f, 0.0f, 2.0f, 1.0f};
+
+ /* The buffers for our light values */
+ private FloatBuffer lightAmbientBuffer;
+ private FloatBuffer lightDiffuseBuffer;
+ private FloatBuffer lightPositionBuffer;
+
+ /* Variables and factor for the input handler */
+ private float oldX;
+ private float oldY;
+ private final float TOUCH_SCALE = 0.2f; //Proved to be good for normal rotation
+
+ /** The Activity Context */
+ private Context context;
+
+ /**
+ * Instance the Cube object and set the Activity Context
+ * handed over. Initiate the light buffers and set this
+ * class as renderer for this now GLSurfaceView.
+ * Request Focus and set if focusable in touch mode to
+ * receive the Input from Screen and Buttons
+ *
+ * @param context - The Activity Context
+ */
+ public Lesson08(Context context) {
+ super(context);
+
+ //Set this as Renderer
+ this.setRenderer(this);
+ //Request focus, otherwise buttons won't react
+ this.requestFocus();
+ this.setFocusableInTouchMode(true);
+
+ //
+ this.context = context;
+
+ //
+ ByteBuffer byteBuf = ByteBuffer.allocateDirect(lightAmbient.length * 4);
+ byteBuf.order(ByteOrder.nativeOrder());
+ lightAmbientBuffer = byteBuf.asFloatBuffer();
+ lightAmbientBuffer.put(lightAmbient);
+ lightAmbientBuffer.position(0);
+
+ byteBuf = ByteBuffer.allocateDirect(lightDiffuse.length * 4);
+ byteBuf.order(ByteOrder.nativeOrder());
+ lightDiffuseBuffer = byteBuf.asFloatBuffer();
+ lightDiffuseBuffer.put(lightDiffuse);
+ lightDiffuseBuffer.position(0);
+
+ byteBuf = ByteBuffer.allocateDirect(lightPosition.length * 4);
+ byteBuf.order(ByteOrder.nativeOrder());
+ lightPositionBuffer = byteBuf.asFloatBuffer();
+ lightPositionBuffer.put(lightPosition);
+ lightPositionBuffer.position(0);
+
+ //
+ cube = new Cube();
+ }
+
+ public void setSpeedAndTester(int speedX, int speedY, Tester tester) {
+ xspeed = speedX;
+ yspeed = speedY;
+ mTester = tester;
+ }
+
+ /**
+ * The Surface is created/init()
+ */
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ //And there'll be light!
+ gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbientBuffer); //Setup The Ambient Light
+ gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuseBuffer); //Setup The Diffuse Light
+ gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPositionBuffer); //Position The Light
+ gl.glEnable(GL10.GL_LIGHT0); //Enable Light 0
+
+ //Blending
+ gl.glColor4f(1.0f, 1.0f, 1.0f, 0.5f); //Full Brightness. 50% Alpha ( NEW )
+ gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE); //Set The Blending Function For Translucency ( NEW )
+
+ //Settings
+ gl.glDisable(GL10.GL_DITHER); //Disable dithering
+ gl.glEnable(GL10.GL_TEXTURE_2D); //Enable Texture Mapping
+ gl.glShadeModel(GL10.GL_SMOOTH); //Enable Smooth Shading
+ gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); //Black Background
+ gl.glClearDepthf(1.0f); //Depth Buffer Setup
+ gl.glEnable(GL10.GL_DEPTH_TEST); //Enables Depth Testing
+ gl.glDepthFunc(GL10.GL_LEQUAL); //The Type Of Depth Testing To Do
+
+ //Really Nice Perspective Calculations
+ gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
+
+ //Load the texture for the cube once during Surface creation
+ cube.loadGLTexture(gl, this.context);
+ }
+
+ /**
+ * Here we do our drawing
+ */
+ public void onDrawFrame(GL10 gl) {
+ //Clear Screen And Depth Buffer
+ gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
+ gl.glLoadIdentity(); //Reset The Current Modelview Matrix
+
+ //Check if the light flag has been set to enable/disable lighting
+ if(light) {
+ gl.glEnable(GL10.GL_LIGHTING);
+ } else {
+ gl.glDisable(GL10.GL_LIGHTING);
+ }
+
+ //Check if the blend flag has been set to enable/disable blending
+ if(blend) {
+ gl.glEnable(GL10.GL_BLEND); //Turn Blending On ( NEW )
+ gl.glDisable(GL10.GL_DEPTH_TEST); //Turn Depth Testing Off ( NEW )
+
+ } else {
+ gl.glDisable(GL10.GL_BLEND); //Turn Blending On ( NEW )
+ gl.glEnable(GL10.GL_DEPTH_TEST); //Turn Depth Testing Off ( NEW )
+ }
+
+ //Drawing
+ gl.glTranslatef(0.0f, 0.0f, z); //Move z units into the screen
+ gl.glScalef(0.8f, 0.8f, 0.8f); //Scale the Cube to 80 percent, otherwise it would be too large for the screen
+
+ //Rotate around the axis based on the rotation matrix (rotation, x, y, z)
+ gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f); //X
+ gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f); //Y
+
+ cube.draw(gl, filter); //Draw the Cube
+ gl.glFinish();
+ mTester.decreaseCounter();
+ //Change rotation factors
+ xrot += xspeed;
+ yrot += yspeed;
+ }
+
+
+ /**
+ * If the surface changes, reset the view
+ */
+ public void onSurfaceChanged(GL10 gl, int width, int height) {
+ if(height == 0) { //Prevent A Divide By Zero By
+ height = 1; //Making Height Equal One
+ }
+
+ gl.glViewport(0, 0, width, height); //Reset The Current Viewport
+ gl.glMatrixMode(GL10.GL_PROJECTION); //Select The Projection Matrix
+ gl.glLoadIdentity(); //Reset The Projection Matrix
+
+ //Calculate The Aspect Ratio Of The Window
+ GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f);
+
+ gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix
+ gl.glLoadIdentity(); //Reset The Modelview Matrix
+ }
+
+/* ***** Listener Events ***** */
+ /**
+ * Override the key listener to receive keyUp events.
+ *
+ * Check for the DPad presses left, right, up, down and middle.
+ * Change the rotation speed according to the presses
+ * or change the texture filter used through the middle press.
+ */
+ @Override
+ public boolean onKeyUp(int keyCode, KeyEvent event) {
+ //
+ if(keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
+ yspeed -= 0.1f;
+
+ } else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
+ yspeed += 0.1f;
+
+ } else if(keyCode == KeyEvent.KEYCODE_DPAD_UP) {
+ xspeed -= 0.1f;
+
+ } else if(keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
+ xspeed += 0.1f;
+
+ } else if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
+ filter += 1;
+ if(filter > 2) {
+ filter = 0;
+ }
+ }
+
+ //We handled the event
+ return true;
+ }
+
+ /**
+ * Override the touch screen listener.
+ *
+ * React to moves and presses on the touchscreen.
+ */
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ //
+ float x = event.getX();
+ float y = event.getY();
+
+ //If a touch is moved on the screen
+ if(event.getAction() == MotionEvent.ACTION_MOVE) {
+ //Calculate the change
+ float dx = x - oldX;
+ float dy = y - oldY;
+ //Define an upper area of 10% on the screen
+ int upperArea = this.getHeight() / 10;
+
+ //Zoom in/out if the touch move has been made in the upper
+ if(y < upperArea) {
+ z -= dx * TOUCH_SCALE / 2;
+
+ //Rotate around the axis otherwise
+ } else {
+ xrot += dy * TOUCH_SCALE;
+ yrot += dx * TOUCH_SCALE;
+ }
+
+ //A press on the screen
+ } else if(event.getAction() == MotionEvent.ACTION_UP) {
+ //Define an upper area of 10% to define a lower area
+ int upperArea = this.getHeight() / 10;
+ int lowerArea = this.getHeight() - upperArea;
+
+ //
+ if(y > lowerArea) {
+ //Change the blend setting if the lower area left has been pressed ( NEW )
+ if(x < (this.getWidth() / 2)) {
+ if(blend) {
+ blend = false;
+ } else {
+ blend = true;
+ }
+
+ //Change the light setting if the lower area right has been pressed
+ } else {
+ if(light) {
+ light = false;
+ } else {
+ light = true;
+ }
+ }
+ }
+ }
+
+ //Remember the values
+ oldX = x;
+ oldY = y;
+
+ //We handled the event
+ return true;
+ }
+}
diff --git a/src/com/nea/nehe/lesson08/Run.java b/src/com/nea/nehe/lesson08/Run.java
new file mode 100644
index 0000000..e266d2a
--- /dev/null
+++ b/src/com/nea/nehe/lesson08/Run.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ * Authored by: Julian Chu <walkingice@0xlab.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.nea.nehe.lesson08;
+
+import org.zeroxlab.benchmark.Tester;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * The initial Android Activity, setting and initiating
+ * the OpenGL ES Renderer Class @see Lesson08.java
+ *
+ * @author Savas Ziplies (nea/INsanityDesign)
+ */
+public class Run extends Tester {
+
+ public final static String FullName = "com.nea.nehe.lesson08.Run";
+
+ /** Our own OpenGL View overridden */
+ private Lesson08 lesson08;
+
+ @Override
+ public String getTag() {
+ return "Nehe08";
+ }
+
+ @Override
+ public int sleepBeforeStart() {
+ return 1200; // 1.2 second
+ }
+
+ @Override
+ public int sleepBetweenRound() {
+ return 0;
+ }
+
+ @Override
+ protected void oneRound() {
+// lesson08.requestRender();
+ }
+
+ /**
+ * Initiate our @see Lesson08.java,
+ * which is GLSurfaceView and Renderer
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ //Initiate our Lesson with this Activity Context handed over
+ lesson08 = new Lesson08(this);
+ lesson08.setSpeedAndTester(1, 1, this);
+ //Set the lesson as View to the Activity
+ setContentView(lesson08);
+ startTester();
+ }
+
+ /**
+ * Remember to resume our Lesson
+ */
+ @Override
+ protected void onResume() {
+ super.onResume();
+ lesson08.onResume();
+ }
+
+ /**
+ * Also pause our Lesson
+ */
+ @Override
+ protected void onPause() {
+ super.onPause();
+ lesson08.onPause();
+ }
+
+}
+
diff --git a/src/com/nea/nehe/lesson16/Cube.java b/src/com/nea/nehe/lesson16/Cube.java
new file mode 100644
index 0000000..7e0d82b
--- /dev/null
+++ b/src/com/nea/nehe/lesson16/Cube.java
@@ -0,0 +1,343 @@
+/*
+ * Authors Name: Jeff Molofee (NeHe)
+ *
+ * Disclaimer:
+ * This program may crash your system or run poorly depending on your
+ * hardware. The program and code contained in this archive was scanned
+ * for virii and has passed all test before it was put online. If you
+ * use this code in project of your own, send a shout out to the author!
+ *
+ * Ported to Android by INsanityDesign:
+ * http://insanitydesign.com/wp/projects/nehe-android-ports/
+ */
+
+package com.nea.nehe.lesson16;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+
+import javax.microedition.khronos.opengles.GL10;
+import javax.microedition.khronos.opengles.GL11;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.opengl.GLUtils;
+
+/**
+ * This class is an object representation of
+ * a Cube containing the vertex information,
+ * texture coordinates, the vertex indices
+ * and drawing functionality, which is called
+ * by the renderer.
+ *
+ * @author Savas Ziplies (nea/INsanityDesign)
+ */
+public class Cube {
+
+ /** The buffer holding the vertices */
+ private FloatBuffer vertexBuffer;
+ /** The buffer holding the texture coordinates */
+ private FloatBuffer textureBuffer;
+ /** The buffer holding the indices */
+ private ByteBuffer indexBuffer;
+ /** The buffer holding the normals */
+ private FloatBuffer normalBuffer;
+
+ /** Our texture pointer */
+ private int[] textures = new int[3];
+
+ /** The initial vertex definition */
+ private float vertices[] = {
+ //Vertices according to faces
+ -1.0f, -1.0f, 1.0f, //v0
+ 1.0f, -1.0f, 1.0f, //v1
+ -1.0f, 1.0f, 1.0f, //v2
+ 1.0f, 1.0f, 1.0f, //v3
+
+ 1.0f, -1.0f, 1.0f, // ...
+ 1.0f, -1.0f, -1.0f,
+ 1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, -1.0f,
+
+ 1.0f, -1.0f, -1.0f,
+ -1.0f, -1.0f, -1.0f,
+ 1.0f, 1.0f, -1.0f,
+ -1.0f, 1.0f, -1.0f,
+
+ -1.0f, -1.0f, -1.0f,
+ -1.0f, -1.0f, 1.0f,
+ -1.0f, 1.0f, -1.0f,
+ -1.0f, 1.0f, 1.0f,
+
+ -1.0f, -1.0f, -1.0f,
+ 1.0f, -1.0f, -1.0f,
+ -1.0f, -1.0f, 1.0f,
+ 1.0f, -1.0f, 1.0f,
+
+ -1.0f, 1.0f, 1.0f,
+ 1.0f, 1.0f, 1.0f,
+ -1.0f, 1.0f, -1.0f,
+ 1.0f, 1.0f, -1.0f,
+ };
+
+ /**
+ * The initial normals for the lighting calculations
+ *
+ * The normals are not necessarily correct from a
+ * real world perspective, as I am too lazy to write
+ * these all on my own. But you get the idea and see
+ * what I mean if you run the demo.
+ */
+ private float normals[] = {
+ // Normals
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+
+ 0.0f, 0.0f, 1.0f,
+ 0.0f, 0.0f, -1.0f,
+ 0.0f, 1.0f, 0.0f,
+ 0.0f, -1.0f, 0.0f,
+ };
+
+ /** The initial texture coordinates (u, v) */
+ private float texture[] = {
+ //Mapping coordinates for the vertices
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+
+ 0.0f, 0.0f,
+ 0.0f, 1.0f,
+ 1.0f, 0.0f,
+ 1.0f, 1.0f,
+ };
+
+ /** The initial indices definition */
+ private byte indices[] = {
+ // Faces definition
+ 0, 1, 3, 0, 3, 2, // Face front
+ 4, 5, 7, 4, 7, 6, // Face right
+ 8, 9, 11, 8, 11, 10, // ...
+ 12, 13, 15, 12, 15, 14,
+ 16, 17, 19, 16, 19, 18,
+ 20, 21, 23, 20, 23, 22,
+ };
+
+ /**
+ * The Cube constructor.
+ *
+ * Initiate the buffers.
+ */
+ public Cube() {
+ //
+ ByteBuffer byteBuf = ByteBuffer.allocateDirect(vertices.length * 4);
+ byteBuf.order(ByteOrder.nativeOrder());
+ vertexBuffer = byteBuf.asFloatBuffer();
+ vertexBuffer.put(vertices);
+ vertexBuffer.position(0);
+
+ //
+ byteBuf = ByteBuffer.allocateDirect(texture.length * 4);
+ byteBuf.order(ByteOrder.nativeOrder());
+ textureBuffer = byteBuf.asFloatBuffer();
+ textureBuffer.put(texture);
+ textureBuffer.position(0);
+
+ //
+ byteBuf = ByteBuffer.allocateDirect(normals.length * 4);
+ byteBuf.order(ByteOrder.nativeOrder());
+ normalBuffer = byteBuf.asFloatBuffer();
+ normalBuffer.put(normals);
+ normalBuffer.position(0);
+
+ //
+ indexBuffer = ByteBuffer.allocateDirect(indices.length);
+ indexBuffer.put(indices);
+ indexBuffer.position(0);
+ }
+
+ /**
+ * The object own drawing function.
+ * Called from the renderer to redraw this instance
+ * with possible changes in values.
+ *
+ * @param gl - The GL Context
+ * @param filter - Which texture filter to be used
+ */
+ public void draw(GL10 gl, int filter) {
+ //Bind the texture according to the set texture filter
+ gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[filter]);
+
+ //Enable the vertex, texture and normal state
+ gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
+ gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
+ gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
+
+ //Set the face rotation
+ gl.glFrontFace(GL10.GL_CCW);
+
+ //Point to our buffers
+ gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
+ gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
+ gl.glNormalPointer(GL10.GL_FLOAT, 0, normalBuffer);
+
+ //Draw the vertices as triangles, based on the Index Buffer information
+ gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer);
+
+ //Disable the client state before leaving
+ gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
+ gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
+ gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
+ }
+
+ /**
+ * Load the textures
+ *
+ * @param gl - The GL Context
+ * @param context - The Activity context
+ */
+ public void loadGLTexture(GL10 gl, Context context) {
+ //Get the texture from the Android resource directory
+ InputStream is = context.getResources().openRawResource(org.zeroxlab.benchmark.R.drawable.crate);
+ Bitmap bitmap = null;
+ try {
+ //BitmapFactory is an Android graphics utility for images
+ bitmap = BitmapFactory.decodeStream(is);
+
+ } finally {
+ //Always clear and close
+ try {
+ is.close();
+ is = null;
+ } catch (IOException e) {
+ }
+ }
+
+ //Generate there texture pointer
+ gl.glGenTextures(3, textures, 0);
+
+ //Create Nearest Filtered Texture and bind it to texture 0
+ gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
+ gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST);
+ gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
+ GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
+
+ //Create Linear Filtered Texture and bind it to texture 1
+ gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[1]);
+ gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
+ gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
+ GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
+
+ //Create mipmapped textures and bind it to texture 2
+ gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[2]);
+ gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
+ gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_NEAREST);
+ /*
+ * This is a change to the original tutorial, as buildMipMap does not exist anymore
+ * in the Android SDK.
+ *
+ * We check if the GL context is version 1.1 and generate MipMaps by flag.
+ * Otherwise we call our own buildMipMap implementation
+ */
+ if(gl instanceof GL11) {
+ gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
+ GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
+
+ //
+ } else {
+ buildMipmap(gl, bitmap);
+ }
+
+ //Clean up
+ bitmap.recycle();
+ }
+
+ /**
+ * Our own MipMap generation implementation.
+ * Scale the original bitmap down, always by factor two,
+ * and set it as new mipmap level.
+ *
+ * Thanks to Mike Miller (with minor changes)!
+ *
+ * @param gl - The GL Context
+ * @param bitmap - The bitmap to mipmap
+ */
+ private void buildMipmap(GL10 gl, Bitmap bitmap) {
+ //
+ int level = 0;
+ //
+ int height = bitmap.getHeight();
+ int width = bitmap.getWidth();
+
+ //
+ while(height >= 1 || width >= 1) {
+ //First of all, generate the texture from our bitmap and set it to the according level
+ GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bitmap, 0);
+
+ //
+ if(height == 1 || width == 1) {
+ break;
+ }
+
+ //Increase the mipmap level
+ level++;
+
+ //
+ height /= 2;
+ width /= 2;
+ Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, width, height, true);
+
+ //Clean up
+ bitmap.recycle();
+ bitmap = bitmap2;
+ }
+ }
+}
+
diff --git a/src/com/nea/nehe/lesson16/Lesson16.java b/src/com/nea/nehe/lesson16/Lesson16.java
new file mode 100644
index 0000000..0109305
--- /dev/null
+++ b/src/com/nea/nehe/lesson16/Lesson16.java
@@ -0,0 +1,366 @@
+/*
+ * Authors Name: Jeff Molofee (NeHe)
+ *
+ * Disclaimer:
+ * This program may crash your system or run poorly depending on your
+ * hardware. The program and code contained in this archive was scanned
+ * for virii and has passed all test before it was put online. If you
+ * use this code in project of your own, send a shout out to the author!
+ *
+ * Ported to Android by INsanityDesign:
+ * http://insanitydesign.com/wp/projects/nehe-android-ports/
+ *
+ * Adapted by 0xlab developers.
+ */
+
+package com.nea.nehe.lesson16;
+
+import org.zeroxlab.benchmark.Tester;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+import android.content.Context;
+import android.opengl.GLSurfaceView;
+import android.opengl.GLU;
+import android.opengl.GLSurfaceView.Renderer;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+
+/**
+ * This is a port of the {@link http://nehe.gamedev.net} OpenGL
+ * tutorials to the Android 1.5 OpenGL ES platform. Thanks to
+ * NeHe and all contributors for their great tutorials and great
+ * documentation. This source should be used together with the
+ * textual explanations made at {@link http://nehe.gamedev.net}.
+ * The code is based on the original Visual C++ code with all
+ * comments made. It has been altered and extended to meet the
+ * Android requirements. The Java code has according comments.
+ *
+ * If you use this code or find it helpful, please visit and send
+ * a shout to the author under {@link http://www.insanitydesign.com/}
+ *
+ * @DISCLAIMER
+ * This source and the whole package comes without warranty. It may or may
+ * not harm your computer or cell phone. Please use with care. Any damage
+ * cannot be related back to the author. The source has been tested on a
+ * virtual environment and scanned for viruses and has passed all tests.
+ *
+ *
+ * This is an interpretation of "Lesson 16: Cool Looking Fog"
+ * for the Google Android platform.
+ *
+ * @author Savas Ziplies (nea/INsanityDesign)
+ */
+public class Lesson16 extends GLSurfaceView implements Renderer {
+
+ private Tester mTester;
+
+ /** Cube instance */
+ private Cube cube;
+
+ /* Rotation values */
+ private float xrot; //X Rotation
+ private float yrot; //Y Rotation
+
+ /* Rotation speed values */
+ private float xspeed; //X Rotation Speed
+ private float yspeed; //Y Rotation Speed
+
+ private float z = -5.0f; //Depth Into The Screen
+
+ private int filter = 0; //Which texture filter?
+
+ /** Is light enabled */
+ private boolean light = false;
+
+ private int fogFilter = 0; //Which Fog To Use ( NEW )
+ /*
+ * Init the three fog filters we will use
+ * and the fog color ( NEW )
+ */
+ private int fogMode[]= {
+ GL10.GL_EXP,
+ GL10.GL_EXP2,
+ GL10.GL_LINEAR
+ };
+ private float[] fogColor = {0.5f, 0.5f, 0.5f, 1.0f};
+ private FloatBuffer fogColorBuffer; //The Fog Color Buffer ( NEW )
+
+ /*
+ * The initial light values for ambient and diffuse
+ * as well as the light position
+ */
+ private float[] lightAmbient = {0.5f, 0.5f, 0.5f, 1.0f};
+ private float[] lightDiffuse = {1.0f, 1.0f, 1.0f, 1.0f};
+ private float[] lightPosition = {0.0f, 0.0f, 2.0f, 1.0f};
+
+ /* The buffers for our light values */
+ private FloatBuffer lightAmbientBuffer;
+ private FloatBuffer lightDiffuseBuffer;
+ private FloatBuffer lightPositionBuffer;
+
+ /*
+ * These variables store the previous X and Y
+ * values as well as a fix touch scale factor.
+ * These are necessary for the rotation transformation
+ * added to this lesson, based on the screen touches.
+ */
+ private float oldX;
+ private float oldY;
+ private final float TOUCH_SCALE = 0.2f; //Proved to be good for normal rotation
+
+ /** The Activity Context */
+ private Context context;
+
+ /**
+ * Instance the Cube object and set the Activity Context
+ * handed over. Initiate the light and fog buffers and set
+ * this class as renderer for this now GLSurfaceView.
+ * Request Focus and set if focusable in touch mode to
+ * receive the Input from Screen and Buttons
+ *
+ * @param context - The Activity Context
+ */
+ public Lesson16(Context context) {
+ super(context);
+
+ //Set this as Renderer
+ this.setRenderer(this);
+ //Request focus, otherwise buttons won't react
+ this.requestFocus();
+ this.setFocusableInTouchMode(true);
+
+ //
+ this.context = context;
+
+ //
+ ByteBuffer byteBuf = ByteBuffer.allocateDirect(lightAmbient.length * 4);
+ byteBuf.order(ByteOrder.nativeOrder());
+ lightAmbientBuffer = byteBuf.asFloatBuffer();
+ lightAmbientBuffer.put(lightAmbient);
+ lightAmbientBuffer.position(0);
+
+ byteBuf = ByteBuffer.allocateDirect(lightDiffuse.length * 4);
+ byteBuf.order(ByteOrder.nativeOrder());
+ lightDiffuseBuffer = byteBuf.asFloatBuffer();
+ lightDiffuseBuffer.put(lightDiffuse);
+ lightDiffuseBuffer.position(0);
+
+ byteBuf = ByteBuffer.allocateDirect(lightPosition.length * 4);
+ byteBuf.order(ByteOrder.nativeOrder());
+ lightPositionBuffer = byteBuf.asFloatBuffer();
+ lightPositionBuffer.put(lightPosition);
+ lightPositionBuffer.position(0);
+
+ //Build the new Buffer ( NEW )
+ byteBuf = ByteBuffer.allocateDirect(fogColor.length * 4);
+ byteBuf.order(ByteOrder.nativeOrder());
+ fogColorBuffer = byteBuf.asFloatBuffer();
+ fogColorBuffer.put(fogColor);
+ fogColorBuffer.position(0);
+
+ //
+ cube = new Cube();
+ }
+
+ public void setSpeedAndTester(int speedX, int speedY, Tester tester) {
+ xspeed = speedX;
+ yspeed = speedY;
+ mTester = tester;
+ }
+
+ /**
+ * The Surface is created/init()
+ */
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ //And there'll be light!
+ gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbientBuffer); //Setup The Ambient Light
+ gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuseBuffer); //Setup The Diffuse Light
+ gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPositionBuffer); //Position The Light
+ gl.glEnable(GL10.GL_LIGHT0); //Enable Light 0
+
+ //Settings
+ gl.glDisable(GL10.GL_DITHER); //Disable dithering
+ gl.glEnable(GL10.GL_TEXTURE_2D); //Enable Texture Mapping
+ gl.glShadeModel(GL10.GL_SMOOTH); //Enable Smooth Shading
+ gl.glClearColor(0.5f, 0.5f, 0.5f, 1.0f); //We'll Clear To The Color Of The Fog ( Modified )
+ gl.glClearDepthf(1.0f); //Depth Buffer Setup
+ gl.glEnable(GL10.GL_DEPTH_TEST); //Enables Depth Testing
+ gl.glDepthFunc(GL10.GL_LEQUAL); //The Type Of Depth Testing To Do
+
+ //The Fog/The Mist
+ gl.glFogf(GL10.GL_FOG_MODE, fogMode[fogFilter]); //Fog Mode ( NEW )
+ gl.glFogfv(GL10.GL_FOG_COLOR, fogColorBuffer); //Set Fog Color ( NEW )
+ gl.glFogf(GL10.GL_FOG_DENSITY, 0.35f); //How Dense Will The Fog Be ( NEW )
+ gl.glHint(GL10.GL_FOG_HINT, GL10.GL_DONT_CARE); //Fog Hint Value ( NEW )
+ gl.glFogf(GL10.GL_FOG_START, 1.0f); //Fog Start Depth ( NEW )
+ gl.glFogf(GL10.GL_FOG_END, 5.0f); //Fog End Depth ( NEW )
+ gl.glEnable(GL10.GL_FOG); //Enables GL_FOG ( NEW )
+
+ //Really Nice Perspective Calculations
+ gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
+
+ //Load the texture for the cube once during Surface creation
+ cube.loadGLTexture(gl, this.context);
+ }
+
+ /**
+ * Here we do our drawing
+ */
+ public void onDrawFrame(GL10 gl) {
+ //Clear Screen And Depth Buffer
+ gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
+ gl.glLoadIdentity(); //Reset The Current Modelview Matrix
+
+ //Check if the light flag has been set to enable/disable lighting
+ if(light) {
+ gl.glEnable(GL10.GL_LIGHTING);
+ } else {
+ gl.glDisable(GL10.GL_LIGHTING);
+ }
+
+ //Set Fog Mode ( NEW )
+ gl.glFogf(GL10.GL_FOG_MODE, fogMode[fogFilter]);
+
+ //Drawing
+ gl.glTranslatef(0.0f, 0.0f, z); //Move z units into the screen
+ gl.glScalef(0.8f, 0.8f, 0.8f); //Scale the Cube to 80 percent, otherwise it would be too large for the screen
+
+ //Rotate around the axis based on the rotation matrix (rotation, x, y, z)
+ gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f); //X
+ gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f); //Y
+
+ cube.draw(gl, filter); //Draw the Cube
+
+ gl.glFinish(); // ensuer the previous gl commands complete
+ mTester.decreaseCounter();
+
+ //Change rotation factors
+ xrot += xspeed;
+ yrot += yspeed;
+ }
+
+ /**
+ * If the surface changes, reset the view
+ */
+ public void onSurfaceChanged(GL10 gl, int width, int height) {
+ if(height == 0) { //Prevent A Divide By Zero By
+ height = 1; //Making Height Equal One
+ }
+
+ gl.glViewport(0, 0, width, height); //Reset The Current Viewport
+ gl.glMatrixMode(GL10.GL_PROJECTION); //Select The Projection Matrix
+ gl.glLoadIdentity(); //Reset The Projection Matrix
+
+ //Calculate The Aspect Ratio Of The Window
+ GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 100.0f);
+
+ gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix
+ gl.glLoadIdentity(); //Reset The Modelview Matrix
+ }
+
+/* ***** Listener Events ***** */
+ /**
+ * Override the key listener to receive keyUp events.
+ *
+ * Check for the DPad presses left, right, up, down and middle.
+ * Change the rotation speed according to the presses
+ * or change the texture filter used through the middle press.
+ */
+ @Override
+ public boolean onKeyUp(int keyCode, KeyEvent event) {
+ //
+ if(keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
+ yspeed -= 0.1f;
+
+ } else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
+ yspeed += 0.1f;
+
+ } else if(keyCode == KeyEvent.KEYCODE_DPAD_UP) {
+ xspeed -= 0.1f;
+
+ } else if(keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
+ xspeed += 0.1f;
+
+ } else if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
+ filter += 1;
+ if(filter > 2) {
+ filter = 0;
+ }
+ }
+
+ //We handled the event
+ return true;
+ }
+
+ /**
+ * Override the touch screen listener.
+ *
+ * React to moves and presses on the touchscreen.
+ */
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ //
+ float x = event.getX();
+ float y = event.getY();
+
+ //If a touch is moved on the screen
+ if(event.getAction() == MotionEvent.ACTION_MOVE) {
+ //Calculate the change
+ float dx = x - oldX;
+ float dy = y - oldY;
+ //Define an upper area of 10% on the screen
+ int upperArea = this.getHeight() / 10;
+
+ //Zoom in/out if the touch move has been made in the upper
+ if(y < upperArea) {
+ z -= dx * TOUCH_SCALE / (this.getWidth() /16);
+
+ //Rotate around the axis otherwise
+ } else {
+ xrot += dy * TOUCH_SCALE;
+ yrot += dx * TOUCH_SCALE;
+ }
+
+ //A press on the screen
+ } else if(event.getAction() == MotionEvent.ACTION_UP) {
+ //Define an upper area of 10% to define a lower area
+ int upperArea = this.getHeight() / 10;
+ int lowerArea = this.getHeight() - upperArea;
+
+ //
+ if(y > lowerArea) {
+ //Change the blend setting if the lower area left has been pressed
+ if(x < (this.getWidth() / 2)) {
+ fogFilter += 1; //Increase fogFilter By One ( NEW )
+
+ //Is fogFilter Greater Than 2? ( NEW )
+ if(fogFilter > 2) {
+ fogFilter = 0; //If So, Set fogFilter To Zero back again ( NEW )
+ }
+
+ //Change the light setting if the lower area right has been pressed
+ } else {
+ if(light) {
+ light = false;
+ } else {
+ light = true;
+ }
+ }
+ }
+ }
+
+ //Remember the values
+ oldX = x;
+ oldY = y;
+
+ //We handled the event
+ return true;
+ }
+}
+
diff --git a/src/com/nea/nehe/lesson16/Run.java b/src/com/nea/nehe/lesson16/Run.java
new file mode 100644
index 0000000..8853cdb
--- /dev/null
+++ b/src/com/nea/nehe/lesson16/Run.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ * Authored by: Julian Chu <walkingice@0xlab.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.nea.nehe.lesson16;
+
+import org.zeroxlab.benchmark.Tester;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+/**
+ * The initial Android Activity, setting and initiating
+ * the OpenGL ES Renderer Class @see Lesson16.java
+ *
+ * @author Savas Ziplies (nea/INsanityDesign)
+ */
+public class Run extends Tester {
+
+ public final static String FullName = "com.nea.nehe.lesson16.Run";
+
+ /** Our own OpenGL View overridden */
+ private Lesson16 lesson16;
+
+ @Override
+ public String getTag() {
+ return "Nehe16";
+ }
+
+ @Override
+ public int sleepBeforeStart() {
+ return 1200; //1.2 second
+ }
+
+ @Override
+ public int sleepBetweenRound() {
+ return 0;
+ }
+
+ @Override
+ protected void oneRound() {
+// lesson16.requestRender();
+ }
+
+ /**
+ * Initiate our @see Lesson16.java,
+ * which is GLSurfaceView and Renderer
+ */
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ //Initiate our Lesson with this Activity Context handed over
+ lesson16 = new Lesson16(this);
+ lesson16.setSpeedAndTester(1, 1, this);
+ //Set the lesson as View to the Activity
+ setContentView(lesson16);
+ startTester();
+ }
+
+ /**
+ * Remember to resume our Lesson
+ */
+ @Override
+ protected void onResume() {
+ super.onResume();
+ lesson16.onResume();
+ }
+
+ /**
+ * Also pause our Lesson
+ */
+ @Override
+ protected void onPause() {
+ super.onPause();
+ lesson16.onPause();
+ }
+
+}
diff --git a/src/jnt/scimark2/Constants.java b/src/jnt/scimark2/Constants.java
new file mode 100644
index 0000000..afeeb0c
--- /dev/null
+++ b/src/jnt/scimark2/Constants.java
@@ -0,0 +1,37 @@
+package jnt.scimark2;
+
+public class Constants
+{
+
+ public static final double RESOLUTION_DEFAULT = 2.0; /*secs*/
+ public static final int RANDOM_SEED = 101010;
+
+ // default: small (cache-contained) problem sizes
+ //
+ public static final int FFT_SIZE = 1024; // must be a power of two
+ public static final int SOR_SIZE =100; // NxN grid
+ public static final int SPARSE_SIZE_M = 1000;
+ public static final int SPARSE_SIZE_nz = 5000;
+ public static final int LU_SIZE = 100;
+
+ // large (out-of-cache) problem sizes
+ //
+ public static final int LG_FFT_SIZE = 1048576; // must be a power of two
+ public static final int LG_SOR_SIZE =1000; // NxN grid
+ public static final int LG_SPARSE_SIZE_M = 100000;
+ public static final int LG_SPARSE_SIZE_nz =1000000;
+ public static final int LG_LU_SIZE = 1000;
+
+ // tiny problem sizes (used to mainly to preload network classes
+ // for applet, so that network download times
+ // are factored out of benchmark.)
+ //
+ public static final int TINY_FFT_SIZE = 16; // must be a power of two
+ public static final int TINY_SOR_SIZE =10; // NxN grid
+ public static final int TINY_SPARSE_SIZE_M = 10;
+ public static final int TINY_SPARSE_SIZE_N = 10;
+ public static final int TINY_SPARSE_SIZE_nz = 50;
+ public static final int TINY_LU_SIZE = 10;
+
+}
+
diff --git a/src/jnt/scimark2/FFT.java b/src/jnt/scimark2/FFT.java
new file mode 100644
index 0000000..fc6a3e2
--- /dev/null
+++ b/src/jnt/scimark2/FFT.java
@@ -0,0 +1,192 @@
+package jnt.scimark2;
+
+/** Computes FFT's of complex, double precision data where n is an integer power of 2.
+ * This appears to be slower than the Radix2 method,
+ * but the code is smaller and simpler, and it requires no extra storage.
+ * <P>
+ *
+ * @author Bruce R. Miller bruce.miller@nist.gov,
+ * @author Derived from GSL (Gnu Scientific Library),
+ * @author GSL's FFT Code by Brian Gough bjg@vvv.lanl.gov
+ */
+
+ /* See {@link ComplexDoubleFFT ComplexDoubleFFT} for details of data layout.
+ */
+
+public class FFT {
+
+ public static final double num_flops(int N)
+ {
+ double Nd = (double) N;
+ double logN = (double) log2(N);
+
+ return (5.0*Nd-2)*logN + 2*(Nd+1);
+ }
+
+
+ /** Compute Fast Fourier Transform of (complex) data, in place.*/
+ public static void transform (double data[]) {
+ transform_internal(data, -1);
+ }
+
+ /** Compute Inverse Fast Fourier Transform of (complex) data, in place.*/
+ public static void inverse (double data[]) {
+ transform_internal(data, +1);
+ // Normalize
+ int nd=data.length;
+ int n =nd/2;
+ double norm=1/((double) n);
+ for(int i=0; i<nd; i++)
+ data[i] *= norm;
+ }
+
+ /** Accuracy check on FFT of data. Make a copy of data, Compute the FFT, then
+ * the inverse and compare to the original. Returns the rms difference.*/
+ public static double test(double data[]) {
+ int nd = data.length;
+ // Make duplicate for comparison
+ double copy[] = new double[nd];
+ System.arraycopy(data,0,copy,0,nd);
+ // Transform & invert
+ transform(data);
+ inverse(data);
+ // Compute RMS difference.
+ double diff = 0.0;
+ for(int i=0; i<nd; i++) {
+ double d = data[i]-copy[i];
+ diff += d*d;
+ }
+ return Math.sqrt(diff/nd);
+ }
+
+ /** Make a random array of n (complex) elements. */
+ public static double[] makeRandom(int n) {
+ int nd = 2*n;
+ double data[] = new double[nd];
+ for(int i=0; i<nd; i++)
+ data[i]= Math.random();
+ return data;
+ }
+
+ /** Simple Test routine. */
+ public static void main(String args[]) {
+ if (args.length == 0) {
+ int n = 1024;
+ System.out.println("n="+n+" => RMS Error="+test(makeRandom(n)));
+ }
+ for(int i=0; i<args.length; i++) {
+ int n = Integer.parseInt(args[i]);
+ System.out.println("n="+n+" => RMS Error="+test(makeRandom(n)));
+ }
+ }
+ /* ______________________________________________________________________ */
+
+ protected static int log2 (int n) {
+ int log = 0;
+ for(int k=1; k < n; k *= 2, log++);
+ if (n != (1 << log))
+ throw new Error("FFT: Data length is not a power of 2!: "+n);
+ return log;
+ }
+
+ protected static void transform_internal (double data[], int direction) {
+ if (data.length == 0) return;
+ int n = data.length/2;
+ if (n == 1) return; // Identity operation!
+ int logn = log2(n);
+
+ /* bit reverse the input data for decimation in time algorithm */
+ bitreverse(data) ;
+
+ /* apply fft recursion */
+ /* this loop executed log2(N) times */
+ for (int bit = 0, dual = 1; bit < logn; bit++, dual *= 2) {
+ double w_real = 1.0;
+ double w_imag = 0.0;
+
+ double theta = 2.0 * direction * Math.PI / (2.0 * (double) dual);
+ double s = Math.sin(theta);
+ double t = Math.sin(theta / 2.0);
+ double s2 = 2.0 * t * t;
+
+ /* a = 0 */
+ for (int b = 0; b < n; b += 2 * dual) {
+ int i = 2*b ;
+ int j = 2*(b + dual);
+
+ double wd_real = data[j] ;
+ double wd_imag = data[j+1] ;
+
+ data[j] = data[i] - wd_real;
+ data[j+1] = data[i+1] - wd_imag;
+ data[i] += wd_real;
+ data[i+1]+= wd_imag;
+ }
+
+ /* a = 1 .. (dual-1) */
+ for (int a = 1; a < dual; a++) {
+ /* trignometric recurrence for w-> exp(i theta) w */
+ {
+ double tmp_real = w_real - s * w_imag - s2 * w_real;
+ double tmp_imag = w_imag + s * w_real - s2 * w_imag;
+ w_real = tmp_real;
+ w_imag = tmp_imag;
+ }
+ for (int b = 0; b < n; b += 2 * dual) {
+ int i = 2*(b + a);
+ int j = 2*(b + a + dual);
+
+ double z1_real = data[j];
+ double z1_imag = data[j+1];
+
+ double wd_real = w_real * z1_real - w_imag * z1_imag;
+ double wd_imag = w_real * z1_imag + w_imag * z1_real;
+
+ data[j] = data[i] - wd_real;
+ data[j+1] = data[i+1] - wd_imag;
+ data[i] += wd_real;
+ data[i+1]+= wd_imag;
+ }
+ }
+ }
+ }
+
+
+ protected static void bitreverse(double data[]) {
+ /* This is the Goldrader bit-reversal algorithm */
+ int n=data.length/2;
+ int nm1 = n-1;
+ int i=0;
+ int j=0;
+ for (; i < nm1; i++) {
+
+ //int ii = 2*i;
+ int ii = i << 1;
+
+ //int jj = 2*j;
+ int jj = j << 1;
+
+ //int k = n / 2 ;
+ int k = n >> 1;
+
+ if (i < j) {
+ double tmp_real = data[ii];
+ double tmp_imag = data[ii+1];
+ data[ii] = data[jj];
+ data[ii+1] = data[jj+1];
+ data[jj] = tmp_real;
+ data[jj+1] = tmp_imag;
+ }
+
+ while (k <= j) {
+ //j = j - k ;
+ j -= k;
+
+ //k = k / 2 ;
+ k >>= 1 ;
+ }
+ j += k ;
+ }
+ }
+}
+
diff --git a/src/jnt/scimark2/Jacobi.java b/src/jnt/scimark2/Jacobi.java
new file mode 100644
index 0000000..69b8ada
--- /dev/null
+++ b/src/jnt/scimark2/Jacobi.java
@@ -0,0 +1,40 @@
+package jnt.scimark2;
+
+public class Jacobi
+{
+ public static final double num_flops(int M, int N, int num_iterations)
+ {
+ double Md = (double) M;
+ double Nd = (double) N;
+ double num_iterD = (double) num_iterations;
+
+ return (Md-1)*(Nd-1)*num_iterD*6.0;
+ }
+
+ public static final void SOR(double omega, double G[][], int num_iterations)
+ {
+ int M = G.length;
+ int N = G[0].length;
+
+ double omega_over_four = omega * 0.25;
+ double one_minus_omega = 1.0 - omega;
+
+ // update interior points
+ //
+ int Mm1 = M-1;
+ int Nm1 = N-1;
+ for (int p=0; p<num_iterations; p++)
+ {
+ for (int i=1; i<Mm1; i++)
+ {
+ double[] Gi = G[i];
+ double[] Gim1 = G[i-1];
+ double[] Gip1 = G[i+1];
+ for (int j=1; j<Nm1; j++)
+ Gi[j] = omega_over_four * (Gim1[j] + Gip1[j] + Gi[j-1]
+ + Gi[j+1]) + one_minus_omega * Gi[j];
+ }
+ }
+ }
+}
+
diff --git a/src/jnt/scimark2/LU.java b/src/jnt/scimark2/LU.java
new file mode 100644
index 0000000..762a5ee
--- /dev/null
+++ b/src/jnt/scimark2/LU.java
@@ -0,0 +1,268 @@
+package jnt.scimark2;
+
+/**
+ LU matrix factorization. (Based on TNT implementation.)
+ Decomposes a matrix A into a triangular lower triangular
+ factor (L) and an upper triangular factor (U) such that
+ A = L*U. By convnetion, the main diagonal of L consists
+ of 1's so that L and U can be stored compactly in
+ a NxN matrix.
+
+
+*/
+public class LU
+{
+ /**
+ Returns a <em>copy</em> of the compact LU factorization.
+ (useful mainly for debugging.)
+
+ @return the compact LU factorization. The U factor
+ is stored in the upper triangular portion, and the L
+ factor is stored in the lower triangular portion.
+ The main diagonal of L consists (by convention) of
+ ones, and is not explicitly stored.
+ */
+
+
+ public static final double num_flops(int N) {
+ // rougly 2/3*N^3
+
+ double Nd = (double) N;
+
+ return (2.0 * Nd *Nd *Nd/ 3.0);
+ }
+
+ protected static double[] new_copy(double x[]) {
+ int N = x.length;
+ double T[] = new double[N];
+ for (int i=0; i<N; i++)
+ T[i] = x[i];
+ return T;
+ }
+
+
+ protected static double[][] new_copy(double A[][]) {
+ int M = A.length;
+ int N = A[0].length;
+
+ double T[][] = new double[M][N];
+
+ for (int i=0; i<M; i++) {
+ double Ti[] = T[i];
+ double Ai[] = A[i];
+ for (int j=0; j<N; j++)
+ Ti[j] = Ai[j];
+ }
+
+ return T;
+ }
+
+
+
+ public static int[] new_copy(int x[]) {
+ int N = x.length;
+ int T[] = new int[N];
+ for (int i=0; i<N; i++)
+ T[i] = x[i];
+ return T;
+ }
+
+ protected static final void insert_copy(double B[][], double A[][]) {
+ int M = A.length;
+ int N = A[0].length;
+
+ int remainder = N & 3; // N mod 4;
+
+ for (int i=0; i<M; i++) {
+ double Bi[] = B[i];
+ double Ai[] = A[i];
+ for (int j=0; j<remainder; j++)
+ Bi[j] = Ai[j];
+ for (int j=remainder; j<N; j+=4) {
+ Bi[j] = Ai[j];
+ Bi[j+1] = Ai[j+1];
+ Bi[j+2] = Ai[j+2];
+ Bi[j+3] = Ai[j+3];
+ }
+ }
+
+ }
+ public double[][] getLU() {
+ return new_copy(LU_);
+ }
+
+ /**
+ Returns a <em>copy</em> of the pivot vector.
+
+ @return the pivot vector used in obtaining the
+ LU factorzation. Subsequent solutions must
+ permute the right-hand side by this vector.
+
+ */
+ public int[] getPivot() {
+ return new_copy(pivot_);
+ }
+
+ /**
+ Initalize LU factorization from matrix.
+
+ @param A (in) the matrix to associate with this
+ factorization.
+ */
+ public LU( double A[][] ) {
+ int M = A.length;
+ int N = A[0].length;
+
+ //if ( LU_ == null || LU_.length != M || LU_[0].length != N)
+ LU_ = new double[M][N];
+
+ insert_copy(LU_, A);
+
+ //if (pivot_.length != M)
+ pivot_ = new int[M];
+
+ factor(LU_, pivot_);
+ }
+
+ /**
+ Solve a linear system, with pre-computed factorization.
+
+ @param b (in) the right-hand side.
+ @return solution vector.
+ */
+ public double[] solve(double b[]) {
+ double x[] = new_copy(b);
+
+ solve(LU_, pivot_, x);
+ return x;
+ }
+
+
+/**
+ LU factorization (in place).
+
+ @param A (in/out) On input, the matrix to be factored.
+ On output, the compact LU factorization.
+
+ @param pivit (out) The pivot vector records the
+ reordering of the rows of A during factorization.
+
+ @return 0, if OK, nozero value, othewise.
+*/
+public static int factor(double A[][], int pivot[]) {
+
+
+
+ int N = A.length;
+ int M = A[0].length;
+
+ int minMN = Math.min(M,N);
+
+ for (int j=0; j<minMN; j++) {
+ // find pivot in column j and test for singularity.
+
+ int jp=j;
+
+ double t = Math.abs(A[j][j]);
+ for (int i=j+1; i<M; i++) {
+ double ab = Math.abs(A[i][j]);
+ if ( ab > t) {
+ jp = i;
+ t = ab;
+ }
+ }
+
+ pivot[j] = jp;
+
+ // jp now has the index of maximum element
+ // of column j, below the diagonal
+
+ if ( A[jp][j] == 0 )
+ return 1; // factorization failed because of zero pivot
+
+
+ if (jp != j) {
+ // swap rows j and jp
+ double tA[] = A[j];
+ A[j] = A[jp];
+ A[jp] = tA;
+ }
+
+ if (j<M-1) // compute elements j+1:M of jth column
+ {
+ // note A(j,j), was A(jp,p) previously which was
+ // guarranteed not to be zero (Label #1)
+ //
+ double recp = 1.0 / A[j][j];
+
+ for (int k=j+1; k<M; k++)
+ A[k][j] *= recp;
+ }
+
+
+ if (j < minMN-1) {
+ // rank-1 update to trailing submatrix: E = E - x*y;
+ //
+ // E is the region A(j+1:M, j+1:N)
+ // x is the column vector A(j+1:M,j)
+ // y is row vector A(j,j+1:N)
+
+
+ for (int ii=j+1; ii<M; ii++) {
+ double Aii[] = A[ii];
+ double Aj[] = A[j];
+ double AiiJ = Aii[j];
+ for (int jj=j+1; jj<N; jj++)
+ Aii[jj] -= AiiJ * Aj[jj];
+
+ }
+ }
+ }
+
+ return 0;
+}
+
+
+ /**
+ Solve a linear system, using a prefactored matrix
+ in LU form.
+
+
+ @param LU (in) the factored matrix in LU form.
+ @param pivot (in) the pivot vector which lists
+ the reordering used during the factorization
+ stage.
+ @param b (in/out) On input, the right-hand side.
+ On output, the solution vector.
+ */
+ public static void solve(double LU[][], int pvt[], double b[]) {
+ int M = LU.length;
+ int N = LU[0].length;
+ int ii=0;
+
+ for (int i=0; i<M; i++) {
+ int ip = pvt[i];
+ double sum = b[ip];
+
+ b[ip] = b[i];
+ if (ii==0)
+ for (int j=ii; j<i; j++)
+ sum -= LU[i][j] * b[j];
+ else
+ if (sum == 0.0)
+ ii = i;
+ b[i] = sum;
+ }
+
+ for (int i=N-1; i>=0; i--) {
+ double sum = b[i];
+ for (int j=i+1; j<N; j++)
+ sum -= LU[i][j] * b[j];
+ b[i] = sum / LU[i][i];
+ }
+ }
+
+
+ private double LU_[][];
+ private int pivot_[];
+}
diff --git a/src/jnt/scimark2/MonteCarlo.java b/src/jnt/scimark2/MonteCarlo.java
new file mode 100644
index 0000000..16ba519
--- /dev/null
+++ b/src/jnt/scimark2/MonteCarlo.java
@@ -0,0 +1,64 @@
+package jnt.scimark2;
+
+/**
+ Estimate Pi by approximating the area of a circle.
+
+ How: generate N random numbers in the unit square, (0,0) to (1,1)
+ and see how are within a radius of 1 or less, i.e.
+ <pre>
+
+ sqrt(x^2 + y^2) < r
+
+ </pre>
+ since the radius is 1.0, we can square both sides
+ and avoid a sqrt() computation:
+ <pre>
+
+ x^2 + y^2 <= 1.0
+
+ </pre>
+ this area under the curve is (Pi * r^2)/ 4.0,
+ and the area of the unit of square is 1.0,
+ so Pi can be approximated by
+ <pre>
+ # points with x^2+y^2 < 1
+ Pi =~ -------------------------- * 4.0
+ total # points
+
+ </pre>
+
+*/
+
+public class MonteCarlo
+{
+ final static int SEED = 113;
+
+ public static final double num_flops(int Num_samples) {
+ // 3 flops in x^2+y^2 and 1 flop in random routine
+
+ return ((double) Num_samples)* 4.0;
+
+ }
+
+
+
+ public static final double integrate(int Num_samples) {
+
+ Random R = new Random(SEED);
+
+
+ int under_curve = 0;
+ for (int count=0; count<Num_samples; count++) {
+ double x= R.nextDouble();
+ double y= R.nextDouble();
+
+ if ( x*x + y*y <= 1.0)
+ under_curve ++;
+
+ }
+
+ return ((double) under_curve / Num_samples) * 4.0;
+ }
+
+
+}
diff --git a/src/jnt/scimark2/README b/src/jnt/scimark2/README
new file mode 100644
index 0000000..63b4ba8
--- /dev/null
+++ b/src/jnt/scimark2/README
@@ -0,0 +1,67 @@
+
+ SciMark 2.0 Java Numerical Benchmark
+
+ Roldan Pozo, Bruce Miller
+
+ NIST
+
+SciMark 2.0 is a composite Java benchmark measuring the performance of
+numerical kernels occurring in scientific and engineering applications.
+It consists of five kernels which typify computational routines
+commonly found in numeric codes: Fast Fourier Transforms (FFTs),
+Jacobi Successive Over-relaxation (SOR), Sparse matrix-multiply,
+Monte Carlo integration, and dense LU matrix factorization.
+
+(See http://www.math.nist.gov/scimark for further information
+and latest updates.)
+
+
+1) INSTALLATION
+
+Unpack the contents of archive into a subdirectory on your
+CLASSPATH. Be sure to keep the directory structure of the
+file contents.
+
+2) COMPILING THE BENCHMARKS (optional)
+
+From the directory above this one, issue the command:
+
+ >javac -O commandline.java
+
+This should compile main benchmark driver and dependent files.
+
+3) RUNNING THE BENCHMARKS
+
+From the directory above this one, issue the command:
+
+ >java jnt.scimark2.commandline
+
+or
+ >java jnt.scimark2.commandline -large
+
+to run the large problem size version. (Note that this one
+takes considerably longer to run.)
+
+After a few minutes, the program should respond with
+the benchmark results, e.g.
+
+ >javac jnt.scimark2.commandline
+
+ SciMark 2.0a
+
+ Composite Score: 20.791595999749727
+ FFT (4096): 30.260047144878346
+ Jacobi SOR (100x100): 33.074935359763934
+ Monte Carlo (25000): 11.510791361970528
+ Sparse matmult (nz=25000), 10 iterations: 8.007507030681996
+ LU (100x100): 21.104699101453836
+
+ java.vendor: Sun Microsystems Inc.
+ java.version: 1.2
+ os.arch: x86
+ os.name: Windows NT
+ os.version: 4.0
+
+One can send these results to "pozo@nist.gov".
+
+/* ---------------------- END OF README -----------------------------*/
diff --git a/src/jnt/scimark2/Random.java b/src/jnt/scimark2/Random.java
new file mode 100644
index 0000000..6300cc0
--- /dev/null
+++ b/src/jnt/scimark2/Random.java
@@ -0,0 +1,257 @@
+package jnt.scimark2;
+
+/* Random.java based on Java Numerical Toolkit (JNT) Random.UniformSequence
+ class. We do not use Java's own java.util.Random so that we can compare
+ results with equivalent C and Fortran coces.
+*/
+
+public class Random {
+
+
+/* ------------------------------------------------------------------------------
+ CLASS VARIABLES
+ ------------------------------------------------------------------------------ */
+
+ int seed = 0;
+
+ private int m[];
+ private int i = 4;
+ private int j = 16;
+
+ private final int mdig = 32;
+ private final int one = 1;
+ private final int m1 = (one << mdig-2) + ((one << mdig-2)-one);
+ private final int m2 = one << mdig/2;
+
+ /* For mdig = 32 : m1 = 2147483647, m2 = 65536
+ For mdig = 64 : m1 = 9223372036854775807, m2 = 4294967296
+ */
+
+ private double dm1 = 1.0 / (double) m1;
+
+ private boolean haveRange = false;
+ private double left = 0.0;
+ private double right = 1.0;
+ private double width = 1.0;
+
+
+/* ------------------------------------------------------------------------------
+ CONSTRUCTORS
+ ------------------------------------------------------------------------------ */
+
+/**
+ Initializes a sequence of uniformly distributed quasi random numbers with a
+ seed based on the system clock.
+*/
+ public Random () {
+ initialize( (int) System.currentTimeMillis());
+ }
+
+/**
+ Initializes a sequence of uniformly distributed quasi random numbers on a
+ given half-open interval [left,right) with a seed based on the system
+ clock.
+
+@param <B>left</B> (double)<BR>
+
+ The left endpoint of the half-open interval [left,right).
+
+@param <B>right</B> (double)<BR>
+
+ The right endpoint of the half-open interval [left,right).
+*/
+ public Random ( double left, double right) {
+ initialize( (int) System.currentTimeMillis() );
+ this.left = left;
+ this.right = right;
+ width = right - left;
+ haveRange = true;
+ }
+
+/**
+ Initializes a sequence of uniformly distributed quasi random numbers with a
+ given seed.
+
+@param <B>seed</B> (int)<BR>
+
+ The seed of the random number generator. Two sequences with the same
+ seed will be identical.
+*/
+ public Random (int seed) {
+ initialize( seed);
+ }
+
+/**
+ Initializes a sequence of uniformly distributed quasi random numbers
+ with a given seed on a given half-open interval [left,right).
+
+@param <B>seed</B> (int)<BR>
+
+ The seed of the random number generator. Two sequences with the same
+ seed will be identical.
+
+@param <B>left</B> (double)<BR>
+
+ The left endpoint of the half-open interval [left,right).
+
+@param <B>right</B> (double)<BR>
+
+ The right endpoint of the half-open interval [left,right).
+*/
+ public Random (int seed, double left, double right) {
+ initialize( seed);
+ this.left = left;
+ this.right = right;
+ width = right - left;
+ haveRange = true;
+ }
+
+/* ------------------------------------------------------------------------------
+ PUBLIC METHODS
+ ------------------------------------------------------------------------------ */
+
+/**
+ Returns the next random number in the sequence.
+*/
+ public final synchronized double nextDouble () {
+
+ int k;
+ double nextValue;
+
+ k = m[i] - m[j];
+ if (k < 0) k += m1;
+ m[j] = k;
+
+ if (i == 0)
+ i = 16;
+ else i--;
+
+ if (j == 0)
+ j = 16 ;
+ else j--;
+
+ if (haveRange)
+ return left + dm1 * (double) k * width;
+ else
+ return dm1 * (double) k;
+
+ }
+
+/**
+ Returns the next N random numbers in the sequence, as
+ a vector.
+*/
+ public final synchronized void nextDoubles (double x[]) {
+
+ int N = x.length;
+ int remainder = N & 3; // N mod 4
+
+ if (haveRange) {
+ for (int count=0; count<N; count++) {
+ int k = m[i] - m[j];
+
+ if (i == 0) i = 16;
+ else i--;
+
+ if (k < 0) k += m1;
+ m[j] = k;
+
+ if (j == 0) j = 16;
+ else j--;
+
+ x[count] = left + dm1 * (double) k * width;
+ }
+ }
+ else
+ {
+
+ for (int count=0; count<remainder; count++) {
+ int k = m[i] - m[j];
+
+ if (i == 0) i = 16;
+ else i--;
+
+ if (k < 0) k += m1;
+ m[j] = k;
+
+ if (j == 0) j = 16;
+ else j--;
+
+
+ x[count] = dm1 * (double) k;
+ }
+
+ for (int count=remainder; count<N; count+=4) {
+ int k = m[i] - m[j];
+ if (i == 0) i = 16;
+ else i--;
+ if (k < 0) k += m1;
+ m[j] = k;
+ if (j == 0) j = 16;
+ else j--;
+ x[count] = dm1 * (double) k;
+
+
+ k = m[i] - m[j];
+ if (i == 0) i = 16;
+ else i--;
+ if (k < 0) k += m1;
+ m[j] = k;
+ if (j == 0) j = 16;
+ else j--;
+ x[count+1] = dm1 * (double) k;
+
+
+ k = m[i] - m[j];
+ if (i == 0) i = 16;
+ else i--;
+ if (k < 0) k += m1;
+ m[j] = k;
+ if (j == 0) j = 16;
+ else j--;
+ x[count+2] = dm1 * (double) k;
+
+
+ k = m[i] - m[j];
+ if (i == 0) i = 16;
+ else i--;
+ if (k < 0) k += m1;
+ m[j] = k;
+ if (j == 0) j = 16;
+ else j--;
+ x[count+3] = dm1 * (double) k;
+ }
+ }
+ }
+
+
+/*----------------------------------------------------------------------------
+ PRIVATE METHODS
+ ------------------------------------------------------------------------ */
+
+ private void initialize (int seed) {
+
+ int jseed, k0, k1, j0, j1, iloop;
+
+ this.seed = seed;
+
+ m = new int[17];
+
+ jseed = Math.min(Math.abs(seed),m1);
+ if (jseed % 2 == 0) --jseed;
+ k0 = 9069 % m2;
+ k1 = 9069 / m2;
+ j0 = jseed % m2;
+ j1 = jseed / m2;
+ for (iloop = 0; iloop < 17; ++iloop) {
+ jseed = j0 * k0;
+ j1 = (jseed / m2 + j0 * k1 + j1 * k0) % (m2 / 2);
+ j0 = jseed % m2;
+ m[iloop] = j0 + m2 * j1;
+ }
+ i = 4;
+ j = 16;
+
+ }
+
+}
diff --git a/src/jnt/scimark2/SOR.java b/src/jnt/scimark2/SOR.java
new file mode 100644
index 0000000..4d91343
--- /dev/null
+++ b/src/jnt/scimark2/SOR.java
@@ -0,0 +1,41 @@
+package jnt.scimark2;
+
+public class SOR
+{
+ public static final double num_flops(int M, int N, int num_iterations)
+ {
+ double Md = (double) M;
+ double Nd = (double) N;
+ double num_iterD = (double) num_iterations;
+
+ return (Md-1)*(Nd-1)*num_iterD*6.0;
+ }
+
+ public static final void execute(double omega, double G[][], int
+ num_iterations)
+ {
+ int M = G.length;
+ int N = G[0].length;
+
+ double omega_over_four = omega * 0.25;
+ double one_minus_omega = 1.0 - omega;
+
+ // update interior points
+ //
+ int Mm1 = M-1;
+ int Nm1 = N-1;
+ for (int p=0; p<num_iterations; p++)
+ {
+ for (int i=1; i<Mm1; i++)
+ {
+ double[] Gi = G[i];
+ double[] Gim1 = G[i-1];
+ double[] Gip1 = G[i+1];
+ for (int j=1; j<Nm1; j++)
+ Gi[j] = omega_over_four * (Gim1[j] + Gip1[j] + Gi[j-1]
+ + Gi[j+1]) + one_minus_omega * Gi[j];
+ }
+ }
+ }
+}
+
diff --git a/src/jnt/scimark2/SparseCompRow.java b/src/jnt/scimark2/SparseCompRow.java
new file mode 100644
index 0000000..bef520b
--- /dev/null
+++ b/src/jnt/scimark2/SparseCompRow.java
@@ -0,0 +1,42 @@
+package jnt.scimark2;
+
+public class SparseCompRow
+{
+ /* multiple iterations used to make kernel have roughly
+ same granulairty as other Scimark kernels. */
+
+ public static double num_flops(int N, int nz, int num_iterations) {
+ /* Note that if nz does not divide N evenly, then the
+ actual number of nonzeros used is adjusted slightly.
+ */
+ int actual_nz = (nz/N) * N;
+ return ((double)actual_nz) * 2.0 * ((double) num_iterations);
+ }
+
+
+ /* computes a matrix-vector multiply with a sparse matrix
+ held in compress-row format. If the size of the matrix
+ in MxN with nz nonzeros, then the val[] is the nz nonzeros,
+ with its ith entry in column col[i]. The integer vector row[]
+ is of size M+1 and row[i] points to the begining of the
+ ith row in col[].
+ */
+
+ public static void matmult( double y[], double val[], int row[],
+ int col[], double x[], int NUM_ITERATIONS) {
+ int M = row.length - 1;
+
+ for (int reps=0; reps<NUM_ITERATIONS; reps++) {
+
+ for (int r=0; r<M; r++) {
+ double sum = 0.0;
+ int rowR = row[r];
+ int rowRp1 = row[r+1];
+ for (int i=rowR; i<rowRp1; i++)
+ sum += x[ col[i] ] * val[i];
+ y[r] = sum;
+ }
+ }
+ }
+
+}
diff --git a/src/jnt/scimark2/Stopwatch.java b/src/jnt/scimark2/Stopwatch.java
new file mode 100644
index 0000000..724bbc8
--- /dev/null
+++ b/src/jnt/scimark2/Stopwatch.java
@@ -0,0 +1,121 @@
+package jnt.scimark2;
+
+/**
+
+ Provides a stopwatch to measure elapsed time.
+
+<P>
+<DL>
+<DT><B>Example of use:</B></DT>
+<DD>
+<p>
+<pre>
+ Stopwatch Q = new Stopwatch;
+<p>
+ Q.start();
+ //
+ // code to be timed here ...
+ //
+ Q.stop();
+ System.out.println("elapsed time was: " + Q.read() + " seconds.");
+</pre>
+
+@author Roldan Pozo
+@version 14 October 1997, revised 1999-04-24
+*/
+public class Stopwatch
+{
+ private boolean running;
+ private double last_time;
+ private double total;
+
+
+/**
+ Return system time (in seconds)
+
+*/
+ public final static double seconds()
+ {
+ return (System.currentTimeMillis() * 0.001);
+ }
+
+/**
+ Return system time (in seconds)
+
+*/
+ public void reset()
+ {
+ running = false;
+ last_time = 0.0;
+ total=0.0;
+ }
+
+ public Stopwatch()
+ {
+ reset();
+ }
+
+
+/**
+ Start (and reset) timer
+
+*/
+ public void start()
+ {
+ if (!running)
+ {
+ running = true;
+ total = 0.0;
+ last_time = seconds();
+ }
+ }
+
+/**
+ Resume timing, after stopping. (Does not wipe out
+ accumulated times.)
+
+*/
+ public void resume()
+ {
+ if (!running)
+ {
+ last_time = seconds();
+ running = true;
+ }
+ }
+
+
+/**
+ Stop timer
+
+*/
+ public double stop()
+ {
+ if (running)
+ {
+ total += seconds() - last_time;
+ running = false;
+ }
+ return total;
+ }
+
+
+/**
+ Display the elapsed time (in seconds)
+
+*/
+ public double read()
+ {
+ if (running)
+ {
+ total += seconds() - last_time;
+ last_time = seconds();
+ }
+ return total;
+ }
+
+}
+
+
+
+
diff --git a/src/jnt/scimark2/commandline.java b/src/jnt/scimark2/commandline.java
new file mode 100644
index 0000000..2ab8574
--- /dev/null
+++ b/src/jnt/scimark2/commandline.java
@@ -0,0 +1,92 @@
+package jnt.scimark2;
+
+import java.util.Properties;
+
+import org.zeroxlab.benchmark.TesterScimark2;
+import android.os.Bundle;
+
+/**
+ SciMark2: A Java numerical benchmark measuring performance
+ of computational kernels for FFTs, Monte Carlo simulation,
+ sparse matrix computations, Jacobi SOR, and dense LU matrix
+ factorizations.
+*/
+
+
+public class commandline
+{
+
+ /* Benchmark 5 kernels with individual Mflops.
+ "results[0]" has the average Mflop rate.
+
+ */
+
+
+ public static String main(Bundle info) {
+ // default to the (small) cache-contained version
+
+ double min_time = Constants.RESOLUTION_DEFAULT;
+
+ int FFT_size = Constants.FFT_SIZE;
+ int SOR_size = Constants.SOR_SIZE;
+ int Sparse_size_M = Constants.SPARSE_SIZE_M;
+ int Sparse_size_nz = Constants.SPARSE_SIZE_nz;
+ int LU_size = Constants.LU_SIZE;
+
+ // run the benchmark
+
+ double res[] = new double[6];
+ Random R = new Random(Constants.RANDOM_SEED);
+
+ res[1] = kernel.measureFFT( FFT_size, min_time, R);
+ res[2] = kernel.measureSOR( SOR_size, min_time, R);
+ res[3] = kernel.measureMonteCarlo(min_time, R);
+ res[4] = kernel.measureSparseMatmult( Sparse_size_M,
+ Sparse_size_nz, min_time, R);
+ res[5] = kernel.measureLU( LU_size, min_time, R);
+
+
+ res[0] = (res[1] + res[2] + res[3] + res[4] + res[5]) / 5;
+
+
+ // print out results
+
+
+
+ System.out.println();
+ System.out.println("SciMark 2.0a");
+ System.out.println();
+
+ System.out.println("Composite Score: " + res[0]);
+ info.putDouble(TesterScimark2.COMPOSITE, res[0]);
+
+ System.out.print("FFT ("+FFT_size+"): ");
+ if (res[1]==0.0)
+ System.out.println(" ERROR, INVALID NUMERICAL RESULT!");
+ else
+ System.out.println(res[1]);
+ info.putDouble(TesterScimark2.FFT, res[1]);
+
+ System.out.println("SOR ("+SOR_size+"x"+ SOR_size+"): "
+ + " " + res[2]);
+ info.putDouble(TesterScimark2.SOR, res[2]);
+
+ System.out.println("Monte Carlo : " + res[3]);
+ info.putDouble(TesterScimark2.MONTECARLO, res[3]);
+
+ System.out.println("Sparse matmult (N="+ Sparse_size_M+
+ ", nz=" + Sparse_size_nz + "): " + res[4]);
+ info.putDouble(TesterScimark2.SPARSEMATMULT, res[4]);
+
+ System.out.print("LU (" + LU_size + "x" + LU_size + "): ");
+ if (res[5]==0.0)
+ System.out.println(" ERROR, INVALID NUMERICAL RESULT!");
+ else
+ System.out.println(res[5]);
+ info.putDouble(TesterScimark2.LU, res[5]);
+
+ return "";
+
+ }
+
+}
diff --git a/src/jnt/scimark2/kernel.java b/src/jnt/scimark2/kernel.java
new file mode 100644
index 0000000..e886fa1
--- /dev/null
+++ b/src/jnt/scimark2/kernel.java
@@ -0,0 +1,268 @@
+package jnt.scimark2;
+
+public class kernel
+{
+ // each measurement returns approx Mflops
+
+
+ public static double measureFFT(int N, double mintime, Random R) {
+ // initialize FFT data as complex (N real/img pairs)
+
+ double x[] = RandomVector(2*N, R);
+ double oldx[] = NewVectorCopy(x);
+ long cycles = 1;
+ Stopwatch Q = new Stopwatch();
+
+ while(true) {
+ Q.start();
+ for (int i=0; i<cycles; i++) {
+ FFT.transform(x); // forward transform
+ FFT.inverse(x); // backward transform
+ }
+ Q.stop();
+ if (Q.read() >= mintime)
+ break;
+
+ cycles *= 2;
+ }
+ // approx Mflops
+
+ final double EPS = 1.0e-10;
+ if ( FFT.test(x) / N > EPS )
+ return 0.0;
+
+ return FFT.num_flops(N)*cycles/ Q.read() * 1.0e-6;
+ }
+
+
+ public static double measureSOR(int N, double min_time, Random R) {
+ double G[][] = RandomMatrix(N, N, R);
+
+ Stopwatch Q = new Stopwatch();
+ int cycles=1;
+ while(true) {
+ Q.start();
+ SOR.execute(1.25, G, cycles);
+ Q.stop();
+ if (Q.read() >= min_time) break;
+
+ cycles *= 2;
+ }
+ // approx Mflops
+ return SOR.num_flops(N, N, cycles) / Q.read() * 1.0e-6;
+ }
+
+ public static double measureMonteCarlo(double min_time, Random R) {
+ Stopwatch Q = new Stopwatch();
+
+ int cycles=1;
+ while(true) {
+ Q.start();
+ MonteCarlo.integrate(cycles);
+ Q.stop();
+ if (Q.read() >= min_time) break;
+
+ cycles *= 2;
+ }
+ // approx Mflops
+ return MonteCarlo.num_flops(cycles) / Q.read() * 1.0e-6;
+ }
+
+
+ public static double measureSparseMatmult(int N, int nz,
+ double min_time, Random R) {
+ // initialize vector multipliers and storage for result
+ // y = A*y;
+
+ double x[] = RandomVector(N, R);
+ double y[] = new double[N];
+
+ // initialize square sparse matrix
+ //
+ // for this test, we create a sparse matrix wit M/nz nonzeros
+ // per row, with spaced-out evenly between the begining of the
+ // row to the main diagonal. Thus, the resulting pattern looks
+ // like
+ // +-----------------+
+ // +* +
+ // +*** +
+ // +* * * +
+ // +** * * +
+ // +** * * +
+ // +* * * * +
+ // +* * * * +
+ // +* * * * +
+ // +-----------------+
+ //
+ // (as best reproducible with integer artihmetic)
+ // Note that the first nr rows will have elements past
+ // the diagonal.
+
+ int nr = nz/N; // average number of nonzeros per row
+ int anz = nr *N; // _actual_ number of nonzeros
+
+
+ double val[] = RandomVector(anz, R);
+ int col[] = new int[anz];
+ int row[] = new int[N+1];
+
+ row[0] = 0;
+ for (int r=0; r<N; r++) {
+ // initialize elements for row r
+
+ int rowr = row[r];
+ row[r+1] = rowr + nr;
+ int step = r/ nr;
+ if (step < 1) step = 1; // take at least unit steps
+
+
+ for (int i=0; i<nr; i++)
+ col[rowr+i] = i*step;
+
+ }
+
+ Stopwatch Q = new Stopwatch();
+
+ int cycles=1;
+ while(true) {
+ Q.start();
+ SparseCompRow.matmult(y, val, row, col, x, cycles);
+ Q.stop();
+ if (Q.read() >= min_time) break;
+
+ cycles *= 2;
+ }
+ // approx Mflops
+ return SparseCompRow.num_flops(N, nz, cycles) / Q.read() * 1.0e-6;
+ }
+
+
+ public static double measureLU(int N, double min_time, Random R) {
+ // compute approx Mlfops, or O if LU yields large errors
+
+ double A[][] = RandomMatrix(N, N, R);
+ double lu[][] = new double[N][N];
+ int pivot[] = new int[N];
+
+ Stopwatch Q = new Stopwatch();
+
+ int cycles=1;
+ while(true) {
+ Q.start();
+ for (int i=0; i<cycles; i++) {
+ CopyMatrix(lu, A);
+ LU.factor(lu, pivot);
+ }
+ Q.stop();
+ if (Q.read() >= min_time) break;
+
+ cycles *= 2;
+ }
+
+
+ // verify that LU is correct
+ double b[] = RandomVector(N, R);
+ double x[] = NewVectorCopy(b);
+
+ LU.solve(lu, pivot, x);
+
+ final double EPS = 1.0e-12;
+ if ( normabs(b, matvec(A,x)) / N > EPS )
+ return 0.0;
+
+
+ // else return approx Mflops
+ //
+ return LU.num_flops(N) * cycles / Q.read() * 1.0e-6;
+ }
+
+
+ private static double[] NewVectorCopy(double x[]) {
+ int N = x.length;
+
+ double y[] = new double[N];
+ for (int i=0; i<N; i++)
+ y[i] = x[i];
+
+ return y;
+ }
+
+ private static void CopyVector(double B[], double A[]) {
+ int N = A.length;
+
+ for (int i=0; i<N; i++)
+ B[i] = A[i];
+ }
+
+
+ private static double normabs(double x[], double y[]) {
+ int N = x.length;
+ double sum = 0.0;
+
+ for (int i=0; i<N; i++)
+ sum += Math.abs(x[i]-y[i]);
+
+ return sum;
+ }
+
+ private static void CopyMatrix(double B[][], double A[][]) {
+ int M = A.length;
+ int N = A[0].length;
+
+ int remainder = N & 3; // N mod 4;
+
+ for (int i=0; i<M; i++) {
+ double Bi[] = B[i];
+ double Ai[] = A[i];
+ for (int j=0; j<remainder; j++)
+ Bi[j] = Ai[j];
+ for (int j=remainder; j<N; j+=4) {
+ Bi[j] = Ai[j];
+ Bi[j+1] = Ai[j+1];
+ Bi[j+2] = Ai[j+2];
+ Bi[j+3] = Ai[j+3];
+ }
+ }
+ }
+
+ private static double[][] RandomMatrix(int M, int N, Random R) {
+ double A[][] = new double[M][N];
+
+ for (int i=0; i<N; i++)
+ for (int j=0; j<N; j++)
+ A[i][j] = R.nextDouble();
+ return A;
+ }
+
+ private static double[] RandomVector(int N, Random R) {
+ double A[] = new double[N];
+
+ for (int i=0; i<N; i++)
+ A[i] = R.nextDouble();
+ return A;
+ }
+
+ private static double[] matvec(double A[][], double x[]) {
+ int N = x.length;
+ double y[] = new double[N];
+
+ matvec(A, x, y);
+
+ return y;
+ }
+
+ private static void matvec(double A[][], double x[], double y[]) {
+ int M = A.length;
+ int N = A[0].length;
+
+ for (int i=0; i<M; i++) {
+ double sum = 0.0;
+ double Ai[] = A[i];
+ for (int j=0; j<N; j++)
+ sum += Ai[j] * x[j];
+
+ y[i] = sum;
+ }
+ }
+
+}
diff --git a/src/org/itri/teapot/MyGLSurfaceView.java b/src/org/itri/teapot/MyGLSurfaceView.java
new file mode 100644
index 0000000..2019075
--- /dev/null
+++ b/src/org/itri/teapot/MyGLSurfaceView.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2008-2009 Koansin Tan
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Origin: http://code.google.com/p/android-utah-teapot/
+ */
+
+package org.itri.teapot;
+
+import org.zeroxlab.benchmark.Tester;
+
+import android.content.Context;
+import android.opengl.GLSurfaceView;
+import android.util.Log;
+
+class MyGLSurfaceView extends GLSurfaceView {
+ private TeapotRenderer mMyRenderer;
+ private Tester mTester;
+ private float xspeed;
+ private float yspeed;
+ private float zspeed;
+
+ public MyGLSurfaceView(Context context) {
+ super(context);
+ }
+
+ @Override
+ public void setRenderer(GLSurfaceView.Renderer renderer) {
+ mMyRenderer = (TeapotRenderer) renderer;
+ super.setRenderer(renderer);
+ }
+}
diff --git a/src/org/itri/teapot/TeapotES.java b/src/org/itri/teapot/TeapotES.java
new file mode 100644
index 0000000..229ebb3
--- /dev/null
+++ b/src/org/itri/teapot/TeapotES.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2008-2009 Koansin Tan
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Origin: http://code.google.com/p/android-utah-teapot/
+ */
+
+package org.itri.teapot;
+
+import org.zeroxlab.benchmark.Tester;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuItem;
+
+//public class TeapotES extends Tester implements SensorEventListener {
+public class TeapotES extends Tester {
+
+ public final static String FullName = "org.itri.teapot.TeapotES";
+
+ /** Our own OpenGL View overridden */
+ private MyGLSurfaceView mGLSurfaceView;
+
+ @Override
+ public String getTag() {
+ return "Teapot";
+ }
+
+ @Override
+ public int sleepBeforeStart() {
+ return 1200; // 1.2 second
+ }
+
+ @Override
+ public int sleepBetweenRound() {
+ return 1500; // 15 ms
+ }
+
+ @Override
+ protected void oneRound() {
+// mGLSurfaceView.requestRender();
+ }
+
+ public static final int ACCEL_ID = Menu.FIRST;
+ public static final int COMPASS_ID = Menu.FIRST + 1;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mGLSurfaceView = new MyGLSurfaceView(this);
+ mGLSurfaceView.setRenderer(new TeapotRenderer(5,1,1,this));
+ setContentView(mGLSurfaceView);
+ startTester();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mGLSurfaceView.onResume();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ mGLSurfaceView.onPause();
+ }
+
+}
diff --git a/src/org/itri/teapot/TeapotRenderer.java b/src/org/itri/teapot/TeapotRenderer.java
new file mode 100644
index 0000000..25233cc
--- /dev/null
+++ b/src/org/itri/teapot/TeapotRenderer.java
@@ -0,0 +1,1921 @@
+/*
+ * Copyright (C) 2008-2009 Koansin Tan
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Origin: http://code.google.com/p/android-utah-teapot/
+ */
+
+package org.itri.teapot;
+
+import org.zeroxlab.benchmark.Tester;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+import java.nio.ShortBuffer;
+
+import javax.microedition.khronos.egl.EGL10;
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+import android.util.Log;
+import android.opengl.GLSurfaceView;
+
+
+public class TeapotRenderer implements GLSurfaceView.Renderer {
+ static float teapot_vertices[] = { 0.0663056f, 0.117825f, 2.10688e-008f,
+ 0.0672f, 0.1152f, 2.05994e-008f, 0.0639726f, 0.117825f, 0.0178043f,
+ 0.0648356f, 0.1152f, 0.0180445f, 0.0573666f, 0.117825f, 0.0336931f,
+ 0.0581404f, 0.1152f, 0.0341476f, 0.0470769f, 0.117825f, 0.0470769f,
+ 0.047712f, 0.1152f, 0.047712f, 0.033693f, 0.117825f, 0.0573666f,
+ 0.0341476f, 0.1152f, 0.0581404f, 0.0178043f, 0.117825f, 0.0639726f,
+ 0.0180444f, 0.1152f, 0.0648356f, 0f, 0.117825f, 0.0663056f, 0f,
+ 0.1152f, 0.0672f, 0.0664444f, 0.1194f, 2.13504e-008f, 0.0641066f,
+ 0.1194f, 0.0178416f, 0.0574868f, 0.1194f, 0.0337636f, 0.0471755f,
+ 0.1194f, 0.0471756f, 0.0337636f, 0.1194f, 0.0574868f, 0.0178416f,
+ 0.1194f, 0.0641066f, 0f, 0.1194f, 0.0664444f, 0.06735f, 0.119925f,
+ 2.14443e-008f, 0.0649803f, 0.119925f, 0.0180847f, 0.0582702f,
+ 0.119925f, 0.0342238f, 0.0478185f, 0.119925f, 0.0478185f,
+ 0.0342238f, 0.119925f, 0.0582702f, 0.0180847f, 0.119925f,
+ 0.0649803f, 0f, 0.119925f, 0.06735f, 0.0687556f, 0.1194f,
+ 2.13504e-008f, 0.0663364f, 0.1194f, 0.0184622f, 0.0594863f,
+ 0.1194f, 0.034938f, 0.0488164f, 0.1194f, 0.0488164f, 0.034938f,
+ 0.1194f, 0.0594863f, 0.0184621f, 0.1194f, 0.0663364f, 0f, 0.1194f,
+ 0.0687556f, 0.0703944f, 0.117825f, 2.10688e-008f, 0.0679176f,
+ 0.117825f, 0.0189022f, 0.0609042f, 0.117825f, 0.0357708f,
+ 0.0499801f, 0.117825f, 0.0499801f, 0.0357708f, 0.117825f,
+ 0.0609042f, 0.0189022f, 0.117825f, 0.0679176f, 0f, 0.117825f,
+ 0.0703944f, 0.072f, 0.1152f, 2.05994e-008f, 0.0694667f, 0.1152f,
+ 0.0193333f, 0.0622933f, 0.1152f, 0.0365867f, 0.05112f, 0.1152f,
+ 0.05112f, 0.0365867f, 0.1152f, 0.0622933f, 0.0193333f, 0.1152f,
+ 0.0694667f, 0f, 0.1152f, 0.072f, -0.0178043f, 0.117825f,
+ 0.0639726f, -0.0180444f, 0.1152f, 0.0648356f, -0.033693f,
+ 0.117825f, 0.0573666f, -0.0341476f, 0.1152f, 0.0581404f,
+ -0.0470769f, 0.117825f, 0.0470769f, -0.047712f, 0.1152f, 0.047712f,
+ -0.0573666f, 0.117825f, 0.033693f, -0.0581404f, 0.1152f,
+ 0.0341476f, -0.0639726f, 0.117825f, 0.0178043f, -0.0648356f,
+ 0.1152f, 0.0180445f, -0.0663056f, 0.117825f, 2.10688e-008f,
+ -0.0672f, 0.1152f, 2.05994e-008f, -0.0178416f, 0.1194f, 0.0641066f,
+ -0.0337636f, 0.1194f, 0.0574867f, -0.0471756f, 0.1194f, 0.0471756f,
+ -0.0574867f, 0.1194f, 0.0337636f, -0.0641066f, 0.1194f, 0.0178416f,
+ -0.0664444f, 0.1194f, 2.13504e-008f, -0.0180847f, 0.119925f,
+ 0.0649803f, -0.0342238f, 0.119925f, 0.0582702f, -0.0478185f,
+ 0.119925f, 0.0478185f, -0.0582702f, 0.119925f, 0.0342238f,
+ -0.0649803f, 0.119925f, 0.0180847f, -0.06735f, 0.119925f,
+ 2.14443e-008f, 0f, 0.1194f, 0.0687556f, -0.0184621f, 0.1194f,
+ 0.0663364f, -0.034938f, 0.1194f, 0.0594863f, -0.0488164f, 0.1194f,
+ 0.0488164f, -0.0594863f, 0.1194f, 0.034938f, -0.0663364f, 0.1194f,
+ 0.0184621f, -0.0687556f, 0.1194f, 2.13504e-008f, 0f, 0.117825f,
+ 0.0703944f, -0.0189022f, 0.117825f, 0.0679176f, -0.0357708f,
+ 0.117825f, 0.0609042f, -0.0499801f, 0.117825f, 0.0499801f,
+ -0.0609042f, 0.117825f, 0.0357708f, -0.0679176f, 0.117825f,
+ 0.0189022f, -0.0703944f, 0.117825f, 2.10688e-008f, -0.0193333f,
+ 0.1152f, 0.0694667f, -0.0365867f, 0.1152f, 0.0622933f, -0.05112f,
+ 0.1152f, 0.05112f, -0.0622933f, 0.1152f, 0.0365867f, -0.0694667f,
+ 0.1152f, 0.0193333f, -0.072f, 0.1152f, 2.05994e-008f, -0.0663055f,
+ 0.117825f, 2.10688e-008f, -0.0639726f, 0.117825f, -0.0178043f,
+ -0.0648356f, 0.1152f, -0.0180444f, -0.0573666f, 0.117825f,
+ -0.033693f, -0.0581404f, 0.1152f, -0.0341475f, -0.0470769f,
+ 0.117825f, -0.0470769f, -0.047712f, 0.1152f, -0.047712f,
+ -0.033693f, 0.117825f, -0.0573666f, -0.0341476f, 0.1152f,
+ -0.0581404f, -0.0178043f, 0.117825f, -0.0639726f, -0.0180444f,
+ 0.1152f, -0.0648356f, 0f, 0.117825f, -0.0663055f, 0f, 0.1152f,
+ -0.0672f, -0.0664444f, 0.1194f, 2.13504e-008f, -0.0641066f,
+ 0.1194f, -0.0178416f, -0.0574867f, 0.1194f, -0.0337636f,
+ -0.0471756f, 0.1194f, -0.0471756f, -0.0337636f, 0.1194f,
+ -0.0574868f, -0.0178416f, 0.1194f, -0.0641066f, 0f, 0.1194f,
+ -0.0664444f, -0.0649803f, 0.119925f, -0.0180847f, -0.0582702f,
+ 0.119925f, -0.0342238f, -0.0478185f, 0.119925f, -0.0478185f,
+ -0.0342238f, 0.119925f, -0.0582702f, -0.0180847f, 0.119925f,
+ -0.0649803f, 0f, 0.119925f, -0.06735f, -0.0663364f, 0.1194f,
+ -0.0184621f, -0.0594863f, 0.1194f, -0.034938f, -0.0488164f,
+ 0.1194f, -0.0488164f, -0.034938f, 0.1194f, -0.0594863f,
+ -0.0184621f, 0.1194f, -0.0663364f, 0f, 0.1194f, -0.0687556f,
+ -0.0703944f, 0.117825f, 2.10688e-008f, -0.0679176f, 0.117825f,
+ -0.0189022f, -0.0609042f, 0.117825f, -0.0357708f, -0.0499801f,
+ 0.117825f, -0.0499801f, -0.0357708f, 0.117825f, -0.0609042f,
+ -0.0189022f, 0.117825f, -0.0679176f, 0f, 0.117825f, -0.0703944f,
+ -0.0694667f, 0.1152f, -0.0193333f, -0.0622933f, 0.1152f,
+ -0.0365867f, -0.05112f, 0.1152f, -0.05112f, -0.0365867f, 0.1152f,
+ -0.0622933f, -0.0193333f, 0.1152f, -0.0694667f, 0f, 0.1152f,
+ -0.072f, 0.0178043f, 0.117825f, -0.0639726f, 0.0180444f, 0.1152f,
+ -0.0648356f, 0.033693f, 0.117825f, -0.0573666f, 0.0341476f,
+ 0.1152f, -0.0581404f, 0.0470769f, 0.117825f, -0.0470769f,
+ 0.047712f, 0.1152f, -0.047712f, 0.0573666f, 0.117825f, -0.033693f,
+ 0.0581404f, 0.1152f, -0.0341475f, 0.0639726f, 0.117825f,
+ -0.0178043f, 0.0648356f, 0.1152f, -0.0180444f, 0.0663055f,
+ 0.117825f, 2.10688e-008f, 0.0178416f, 0.1194f, -0.0641066f,
+ 0.0337636f, 0.1194f, -0.0574867f, 0.0471756f, 0.1194f, -0.0471756f,
+ 0.0574868f, 0.1194f, -0.0337636f, 0.0641066f, 0.1194f, -0.0178415f,
+ 0.0664444f, 0.1194f, 2.13504e-008f, 0.0180847f, 0.119925f,
+ -0.0649803f, 0.0342238f, 0.119925f, -0.0582702f, 0.0478185f,
+ 0.119925f, -0.0478185f, 0.0582702f, 0.119925f, -0.0342238f,
+ 0.0649803f, 0.119925f, -0.0180847f, 0.0184621f, 0.1194f,
+ -0.0663364f, 0.034938f, 0.1194f, -0.0594863f, 0.0488164f, 0.1194f,
+ -0.0488164f, 0.0594863f, 0.1194f, -0.034938f, 0.0663364f, 0.1194f,
+ -0.0184621f, 0.0687556f, 0.1194f, 2.13504e-008f, 0.0189022f,
+ 0.117825f, -0.0679176f, 0.0357708f, 0.117825f, -0.0609042f,
+ 0.0499801f, 0.117825f, -0.0499801f, 0.0609042f, 0.117825f,
+ -0.0357708f, 0.0679176f, 0.117825f, -0.0189022f, 0.0703944f,
+ 0.117825f, 2.10688e-008f, 0.0193333f, 0.1152f, -0.0694667f,
+ 0.0365867f, 0.1152f, -0.0622933f, 0.05112f, 0.1152f, -0.05112f,
+ 0.0622933f, 0.1152f, -0.0365867f, 0.0694667f, 0.1152f, -0.0193333f,
+ 0.0779444f, 0.102617f, 1.83493e-008f, 0.075202f, 0.102617f,
+ 0.0209295f, 0.0694667f, 0.1152f, 0.0193333f, 0.0674364f, 0.102617f,
+ 0.0396073f, 0.0622933f, 0.1152f, 0.0365867f, 0.0553406f, 0.102617f,
+ 0.0553406f, 0.0396073f, 0.102617f, 0.0674364f, 0.0365867f, 0.1152f,
+ 0.0622933f, 0.0209296f, 0.102617f, 0.0752019f, 0.0193334f, 0.1152f,
+ 0.0694667f, 0f, 0.102617f, 0.0779444f, 0.0835556f, 0.0901333f,
+ 1.61171e-008f, 0.0806156f, 0.0901333f, 0.0224362f, 0.072291f,
+ 0.0901333f, 0.0424586f, 0.0593244f, 0.0901334f, 0.0593245f,
+ 0.0424586f, 0.0901333f, 0.072291f, 0.0224362f, 0.0901333f,
+ 0.0806156f, 0f, 0.0901333f, 0.0835556f, 0.0885f, 0.07785f,
+ 1.39207e-008f, 0.0853861f, 0.07785f, 0.0237639f, 0.0765689f,
+ 0.07785f, 0.0449711f, 0.062835f, 0.07785f, 0.062835f, 0.0449711f,
+ 0.07785f, 0.0765689f, 0.0237639f, 0.07785f, 0.0853861f, 0f,
+ 0.07785f, 0.0885f, 0.0924444f, 0.0658667f, 1.17779e-008f,
+ 0.0891918f, 0.0658667f, 0.024823f, 0.0799816f, 0.0658667f,
+ 0.0469755f, 0.0656356f, 0.0658667f, 0.0656356f, 0.0469755f,
+ 0.0658667f, 0.0799816f, 0.0248231f, 0.0658667f, 0.0891918f, 0f,
+ 0.0658667f, 0.0924444f, 0.0950556f, 0.0542833f, 9.7066e-009f,
+ 0.091711f, 0.0542833f, 0.0255242f, 0.0822407f, 0.0542833f,
+ 0.0483023f, 0.0674895f, 0.0542833f, 0.0674895f, 0.0483023f,
+ 0.0542833f, 0.0822406f, 0.0255242f, 0.0542833f, 0.091711f, 0f,
+ 0.0542833f, 0.0950556f, 0.096f, 0.0432f, 7.72476e-009f, 0.0926222f,
+ 0.0432f, 0.0257778f, 0.0830578f, 0.0432f, 0.0487822f, 0.06816f,
+ 0.0432f, 0.06816f, 0.0487822f, 0.0432f, 0.0830578f, 0.0257778f,
+ 0.0432f, 0.0926222f, 0f, 0.0432f, 0.096f, 0f, 0.102617f,
+ 0.0779444f, -0.0209295f, 0.102617f, 0.075202f, -0.0193333f,
+ 0.1152f, 0.0694667f, -0.0396073f, 0.102617f, 0.0674364f,
+ -0.0365867f, 0.1152f, 0.0622933f, -0.0553405f, 0.102617f,
+ 0.0553405f, -0.0674364f, 0.102617f, 0.0396073f, -0.0622933f,
+ 0.1152f, 0.0365867f, -0.075202f, 0.102617f, 0.0209296f,
+ -0.0694667f, 0.1152f, 0.0193334f, -0.0779444f, 0.102617f,
+ 1.83493e-008f, 0f, 0.0901333f, 0.0835555f, -0.0224362f, 0.0901333f,
+ 0.0806156f, -0.0424586f, 0.0901333f, 0.072291f, -0.0593244f,
+ 0.0901334f, 0.0593244f, -0.072291f, 0.0901334f, 0.0424586f,
+ -0.0806156f, 0.0901333f, 0.0224362f, -0.0835555f, 0.0901333f,
+ 1.61171e-008f, -0.0237639f, 0.07785f, 0.0853861f, -0.0449711f,
+ 0.07785f, 0.0765689f, -0.062835f, 0.07785f, 0.062835f, -0.0765689f,
+ 0.07785f, 0.0449711f, -0.0853861f, 0.07785f, 0.0237639f, -0.0885f,
+ 0.07785f, 1.39207e-008f, 0f, 0.0658667f, 0.0924444f, -0.024823f,
+ 0.0658667f, 0.0891918f, -0.0469755f, 0.0658667f, 0.0799816f,
+ -0.0656356f, 0.0658667f, 0.0656356f, -0.0799816f, 0.0658667f,
+ 0.0469755f, -0.0891918f, 0.0658667f, 0.0248231f, -0.0924444f,
+ 0.0658667f, 1.17779e-008f, 0f, 0.0542833f, 0.0950556f, -0.0255242f,
+ 0.0542833f, 0.091711f, -0.0483023f, 0.0542833f, 0.0822407f,
+ -0.0674894f, 0.0542834f, 0.0674894f, -0.0822406f, 0.0542834f,
+ 0.0483023f, -0.091711f, 0.0542833f, 0.0255242f, -0.0950556f,
+ 0.0542833f, 9.70661e-009f, -0.0257778f, 0.0432f, 0.0926222f,
+ -0.0487822f, 0.0432f, 0.0830578f, -0.06816f, 0.0432f, 0.06816f,
+ -0.0830578f, 0.0432f, 0.0487822f, -0.0926222f, 0.0432f, 0.0257778f,
+ -0.096f, 0.0432f, 7.72476e-009f, -0.0779444f, 0.102617f,
+ 1.83493e-008f, -0.075202f, 0.102617f, -0.0209295f, -0.0694667f,
+ 0.1152f, -0.0193333f, -0.0674364f, 0.102617f, -0.0396073f,
+ -0.0622933f, 0.1152f, -0.0365866f, -0.0553406f, 0.102617f,
+ -0.0553406f, -0.0396073f, 0.102617f, -0.0674364f, -0.0365867f,
+ 0.1152f, -0.0622933f, -0.0209296f, 0.102617f, -0.0752019f,
+ -0.0193334f, 0.1152f, -0.0694667f, 0f, 0.102617f, -0.0779444f,
+ -0.0835556f, 0.0901333f, 1.61171e-008f, -0.0806156f, 0.0901333f,
+ -0.0224362f, -0.072291f, 0.0901333f, -0.0424586f, -0.0593244f,
+ 0.0901333f, -0.0593244f, -0.0424586f, 0.0901333f, -0.072291f,
+ -0.0224362f, 0.0901333f, -0.0806156f, 0f, 0.0901333f, -0.0835556f,
+ -0.0853861f, 0.07785f, -0.0237639f, -0.0765689f, 0.07785f,
+ -0.0449711f, -0.062835f, 0.07785f, -0.062835f, -0.0449711f,
+ 0.07785f, -0.0765689f, -0.0237639f, 0.07785f, -0.0853861f, 0f,
+ 0.07785f, -0.0885f, -0.0924444f, 0.0658666f, 1.17779e-008f,
+ -0.0891918f, 0.0658666f, -0.024823f, -0.0799816f, 0.0658666f,
+ -0.0469755f, -0.0656356f, 0.0658666f, -0.0656356f, -0.0469755f,
+ 0.0658666f, -0.0799816f, -0.0248231f, 0.0658666f, -0.0891918f, 0f,
+ 0.0658666f, -0.0924444f, -0.0950556f, 0.0542833f, 9.7066e-009f,
+ -0.091711f, 0.0542833f, -0.0255242f, -0.0822407f, 0.0542833f,
+ -0.0483023f, -0.0674894f, 0.0542833f, -0.0674894f, -0.0483023f,
+ 0.0542833f, -0.0822407f, -0.0255242f, 0.0542833f, -0.091711f, 0f,
+ 0.0542833f, -0.0950556f, -0.0926222f, 0.0432f, -0.0257778f,
+ -0.0830578f, 0.0432f, -0.0487822f, -0.06816f, 0.0432f, -0.06816f,
+ -0.0487822f, 0.0432f, -0.0830578f, -0.0257778f, 0.0432f,
+ -0.0926222f, 0f, 0.0432f, -0.096f, 0.0209295f, 0.102617f,
+ -0.075202f, 0.0193333f, 0.1152f, -0.0694667f, 0.0396073f,
+ 0.102617f, -0.0674364f, 0.0365867f, 0.1152f, -0.0622933f,
+ 0.0553406f, 0.102617f, -0.0553406f, 0.0674364f, 0.102617f,
+ -0.0396073f, 0.0622933f, 0.1152f, -0.0365867f, 0.0752019f,
+ 0.102617f, -0.0209295f, 0.0694667f, 0.1152f, -0.0193333f,
+ 0.0779444f, 0.102617f, 1.83493e-008f, 0.0224362f, 0.0901333f,
+ -0.0806156f, 0.0424586f, 0.0901333f, -0.072291f, 0.0593244f,
+ 0.0901333f, -0.0593244f, 0.072291f, 0.0901333f, -0.0424586f,
+ 0.0806156f, 0.0901333f, -0.0224362f, 0.0835556f, 0.0901333f,
+ 1.61171e-008f, 0.0237639f, 0.07785f, -0.0853861f, 0.0449711f,
+ 0.07785f, -0.0765689f, 0.062835f, 0.07785f, -0.062835f, 0.0765689f,
+ 0.07785f, -0.0449711f, 0.0853861f, 0.07785f, -0.0237639f,
+ 0.024823f, 0.0658666f, -0.0891918f, 0.0469755f, 0.0658666f,
+ -0.0799816f, 0.0656356f, 0.0658666f, -0.0656356f, 0.0799816f,
+ 0.0658666f, -0.0469755f, 0.0891918f, 0.0658666f, -0.0248231f,
+ 0.0924444f, 0.0658666f, 1.17779e-008f, 0.0255242f, 0.0542833f,
+ -0.091711f, 0.0483023f, 0.0542833f, -0.0822407f, 0.0674894f,
+ 0.0542833f, -0.0674894f, 0.0822407f, 0.0542833f, -0.0483023f,
+ 0.091711f, 0.0542833f, -0.0255242f, 0.0950556f, 0.0542833f,
+ 9.7066e-009f, 0.0257778f, 0.0432f, -0.0926222f, 0.0487822f,
+ 0.0432f, -0.0830578f, 0.06816f, 0.0432f, -0.06816f, 0.0830578f,
+ 0.0432f, -0.0487822f, 0.0926222f, 0.0432f, -0.0257778f, 0.0942222f,
+ 0.0332833f, 5.95152e-009f, 0.090907f, 0.0332833f, 0.0253004f,
+ 0.0815197f, 0.0332833f, 0.0478788f, 0.0668978f, 0.0332833f,
+ 0.0668978f, 0.0478789f, 0.0332833f, 0.0815197f, 0.0253004f,
+ 0.0332833f, 0.090907f, 0f, 0.0332833f, 0.0942222f, 0.0897778f,
+ 0.0250667f, 4.48227e-009f, 0.0866189f, 0.0250667f, 0.024107f,
+ 0.0776744f, 0.0250667f, 0.0456204f, 0.0637422f, 0.0250667f,
+ 0.0637422f, 0.0456204f, 0.0250667f, 0.0776744f, 0.024107f,
+ 0.0250667f, 0.0866189f, 0f, 0.0250667f, 0.0897778f, 0.084f,
+ 0.01845f, 3.29912e-009f, 0.0810445f, 0.01845f, 0.0225556f,
+ 0.0726756f, 0.01845f, 0.0426844f, 0.05964f, 0.01845f, 0.05964f,
+ 0.0426845f, 0.01845f, 0.0726755f, 0.0225556f, 0.01845f, 0.0810444f,
+ 0f, 0.01845f, 0.084f, 0.0782222f, 0.0133334f, 2.38419e-009f,
+ 0.07547f, 0.0133333f, 0.0210041f, 0.0676767f, 0.0133333f,
+ 0.0397485f, 0.0555378f, 0.0133333f, 0.0555378f, 0.0397485f,
+ 0.0133333f, 0.0676767f, 0.0210041f, 0.0133333f, 0.07547f, 0f,
+ 0.0133333f, 0.0782222f, 0.0737778f, 0.00961668f, 1.7196e-009f,
+ 0.0711819f, 0.00961668f, 0.0198107f, 0.0638315f, 0.00961668f,
+ 0.03749f, 0.0523822f, 0.00961668f, 0.0523822f, 0.0374901f,
+ 0.00961668f, 0.0638314f, 0.0198107f, 0.00961668f, 0.0711819f, 0f,
+ 0.00961668f, 0.0737778f, 0.072f, 0.0072f, 1.28746e-009f,
+ 0.0694667f, 0.0072f, 0.0193333f, 0.0622933f, 0.00719999f,
+ 0.0365867f, 0.05112f, 0.00719999f, 0.05112f, 0.0365867f,
+ 0.00719999f, 0.0622933f, 0.0193334f, 0.00719999f, 0.0694667f, 0f,
+ 0.00719999f, 0.072f, -0.0253004f, 0.0332833f, 0.090907f,
+ -0.0478788f, 0.0332833f, 0.0815197f, -0.0668978f, 0.0332833f,
+ 0.0668978f, -0.0815197f, 0.0332833f, 0.0478789f, -0.090907f,
+ 0.0332833f, 0.0253004f, -0.0942222f, 0.0332833f, 5.95152e-009f,
+ -0.024107f, 0.0250667f, 0.0866189f, -0.0456204f, 0.0250667f,
+ 0.0776744f, -0.0637422f, 0.0250667f, 0.0637422f, -0.0776744f,
+ 0.0250667f, 0.0456204f, -0.0866189f, 0.0250667f, 0.024107f,
+ -0.0897778f, 0.0250667f, 4.48227e-009f, -0.0225556f, 0.01845f,
+ 0.0810445f, -0.0426844f, 0.01845f, 0.0726756f, -0.05964f, 0.01845f,
+ 0.05964f, -0.0726755f, 0.01845f, 0.0426845f, -0.0810444f, 0.01845f,
+ 0.0225556f, -0.084f, 0.01845f, 3.29912e-009f, -0.0210041f,
+ 0.0133333f, 0.07547f, -0.0397485f, 0.0133333f, 0.0676767f,
+ -0.0555378f, 0.0133333f, 0.0555378f, -0.0676767f, 0.0133333f,
+ 0.0397485f, -0.07547f, 0.0133333f, 0.0210041f, -0.0782222f,
+ 0.0133334f, 2.38419e-009f, -0.0198107f, 0.00961668f, 0.0711819f,
+ -0.03749f, 0.00961667f, 0.0638315f, -0.0523822f, 0.00961668f,
+ 0.0523822f, -0.0638314f, 0.00961668f, 0.0374901f, -0.0711819f,
+ 0.00961668f, 0.0198107f, -0.0737778f, 0.00961668f, 1.7196e-009f,
+ -0.0193333f, 0.00719999f, 0.0694667f, -0.0365867f, 0.00719999f,
+ 0.0622933f, -0.05112f, 0.00719999f, 0.05112f, -0.0622933f,
+ 0.00719999f, 0.0365867f, -0.0694667f, 0.0072f, 0.0193334f, -0.072f,
+ 0.0072f, 1.28746e-009f, -0.090907f, 0.0332833f, -0.0253004f,
+ -0.0815197f, 0.0332833f, -0.0478788f, -0.0668978f, 0.0332833f,
+ -0.0668978f, -0.0478789f, 0.0332833f, -0.0815197f, -0.0253004f,
+ 0.0332833f, -0.090907f, 0f, 0.0332833f, -0.0942222f, -0.0866189f,
+ 0.0250667f, -0.024107f, -0.0776744f, 0.0250667f, -0.0456204f,
+ -0.0637422f, 0.0250667f, -0.0637422f, -0.0456204f, 0.0250667f,
+ -0.0776744f, -0.024107f, 0.0250667f, -0.0866189f, 0f, 0.0250667f,
+ -0.0897778f, -0.0810445f, 0.01845f, -0.0225556f, -0.0726756f,
+ 0.01845f, -0.0426844f, -0.05964f, 0.01845f, -0.05964f, -0.0426845f,
+ 0.01845f, -0.0726755f, -0.0225556f, 0.01845f, -0.0810444f, 0f,
+ 0.01845f, -0.084f, -0.07547f, 0.0133334f, -0.0210041f, -0.0676767f,
+ 0.0133334f, -0.0397485f, -0.0555378f, 0.0133334f, -0.0555378f,
+ -0.0397485f, 0.0133334f, -0.0676767f, -0.0210041f, 0.0133334f,
+ -0.07547f, 0f, 0.0133334f, -0.0782222f, -0.0711819f, 0.00961669f,
+ -0.0198107f, -0.0638315f, 0.00961669f, -0.03749f, -0.0523822f,
+ 0.00961669f, -0.0523822f, -0.0374901f, 0.00961669f, -0.0638314f,
+ -0.0198107f, 0.00961669f, -0.0711819f, 0f, 0.00961669f,
+ -0.0737778f, -0.0694667f, 0.0072f, -0.0193333f, -0.0622933f,
+ 0.00720001f, -0.0365867f, -0.05112f, 0.00720001f, -0.05112f,
+ -0.0365867f, 0.00720001f, -0.0622933f, -0.0193334f, 0.00720001f,
+ -0.0694667f, 0f, 0.00720001f, -0.072f, 0.0253004f, 0.0332833f,
+ -0.090907f, 0.0478788f, 0.0332833f, -0.0815197f, 0.0668978f,
+ 0.0332833f, -0.0668978f, 0.0815197f, 0.0332833f, -0.0478789f,
+ 0.090907f, 0.0332833f, -0.0253004f, 0.024107f, 0.0250667f,
+ -0.0866189f, 0.0456204f, 0.0250667f, -0.0776744f, 0.0637422f,
+ 0.0250667f, -0.0637422f, 0.0776744f, 0.0250667f, -0.0456204f,
+ 0.0866189f, 0.0250667f, -0.024107f, 0.0225556f, 0.01845f,
+ -0.0810445f, 0.0426844f, 0.01845f, -0.0726756f, 0.05964f, 0.01845f,
+ -0.05964f, 0.0726755f, 0.01845f, -0.0426845f, 0.0810444f, 0.01845f,
+ -0.0225556f, 0.0210041f, 0.0133334f, -0.07547f, 0.0397485f,
+ 0.0133334f, -0.0676767f, 0.0555378f, 0.0133334f, -0.0555378f,
+ 0.0676767f, 0.0133334f, -0.0397485f, 0.07547f, 0.0133334f,
+ -0.0210041f, 0.0198107f, 0.00961669f, -0.0711819f, 0.03749f,
+ 0.00961669f, -0.0638315f, 0.0523822f, 0.00961669f, -0.0523822f,
+ 0.0638314f, 0.00961669f, -0.0374901f, 0.0711819f, 0.00961668f,
+ -0.0198107f, 0.0193333f, 0.00720001f, -0.0694667f, 0.0365867f,
+ 0.00720001f, -0.0622933f, 0.05112f, 0.00720001f, -0.05112f,
+ 0.0622933f, 0.00720001f, -0.0365867f, 0.0694667f, 0.0072f,
+ -0.0193334f, -0.0923778f, 0.09715f, 1.73718e-008f, -0.0768f,
+ 0.0972f, 1.73807e-008f, -0.0924979f, 0.0979463f, 0.00600001f,
+ -0.0764444f, 0.098f, 0.00600001f, -0.0927984f, 0.099937f,
+ 0.00960001f, -0.0755556f, 0.1f, 0.00960001f, -0.0931889f,
+ 0.102525f, 0.0108f, -0.0744f, 0.1026f, 0.0108f, -0.0935794f,
+ 0.105113f, 0.0096f, -0.0732444f, 0.1052f, 0.0096f, -0.0938798f,
+ 0.107104f, 0.006f, -0.0723556f, 0.1072f, 0.006f, -0.094f, 0.1079f,
+ 1.9294e-008f, -0.072f, 0.108f, 1.93119e-008f, -0.105422f, 0.0968f,
+ 1.73092e-008f, -0.105909f, 0.0975704f, 0.00600001f, -0.107128f,
+ 0.0994963f, 0.00960001f, -0.108711f, 0.102f, 0.0108f, -0.110295f,
+ 0.104504f, 0.0096f, -0.111513f, 0.10643f, 0.006f, -0.112f, 0.1072f,
+ 1.91688e-008f, -0.1158f, 0.09585f, 1.71393e-008f, -0.116556f,
+ 0.09655f, 0.00600001f, -0.118444f, 0.0983f, 0.00960001f, -0.1209f,
+ 0.100575f, 0.0108f, -0.123356f, 0.10285f, 0.0096f, -0.125244f,
+ 0.1046f, 0.006f, -0.126f, 0.1053f, 1.88291e-008f, -0.123378f,
+ 0.094f, 1.68085e-008f, -0.124313f, 0.094563f, 0.00600001f,
+ -0.12665f, 0.0959704f, 0.00960001f, -0.129689f, 0.0978f, 0.0108f,
+ -0.132728f, 0.0996296f, 0.0096f, -0.135065f, 0.101037f, 0.006f,
+ -0.136f, 0.1016f, 1.81675e-008f, -0.128022f, 0.09095f,
+ 1.62631e-008f, -0.129058f, 0.091287f, 0.00600001f, -0.131646f,
+ 0.0921296f, 0.00960001f, -0.135011f, 0.093225f, 0.0108f,
+ -0.138376f, 0.0943204f, 0.0096f, -0.140965f, 0.095163f, 0.006f,
+ -0.142f, 0.0955f, 1.70767e-008f, -0.1296f, 0.0864f, 1.54495e-008f,
+ -0.130667f, 0.0864f, 0.00600001f, -0.133333f, 0.0864f, 0.00960001f,
+ -0.1368f, 0.0864f, 0.0108f, -0.140267f, 0.0864f, 0.0096f,
+ -0.142933f, 0.0864f, 0.006f, -0.144f, 0.0864f, 1.54495e-008f,
+ -0.0938798f, 0.107104f, -0.00599999f, -0.0723556f, 0.1072f,
+ -0.00599999f, -0.0935794f, 0.105113f, -0.0096f, -0.0732444f,
+ 0.1052f, -0.0096f, -0.0931889f, 0.102525f, -0.0108f, -0.0744f,
+ 0.1026f, -0.0108f, -0.0927983f, 0.099937f, -0.00959999f,
+ -0.0755556f, 0.1f, -0.00959999f, -0.0924979f, 0.0979463f,
+ -0.00599998f, -0.0764444f, 0.098f, -0.00599998f, -0.0923778f,
+ 0.09715f, 1.73718e-008f, -0.112f, 0.1072f, 1.91688e-008f,
+ -0.111513f, 0.10643f, -0.00599999f, -0.110295f, 0.104504f,
+ -0.00959999f, -0.108711f, 0.102f, -0.0108f, -0.107128f, 0.0994963f,
+ -0.00959999f, -0.105909f, 0.0975704f, -0.00599998f, -0.105422f,
+ 0.0968f, 1.73092e-008f, -0.125244f, 0.1046f, -0.00599999f,
+ -0.123356f, 0.10285f, -0.0096f, -0.1209f, 0.100575f, -0.0108f,
+ -0.118444f, 0.0983f, -0.00959999f, -0.116556f, 0.09655f,
+ -0.00599998f, -0.136f, 0.1016f, 1.81675e-008f, -0.135065f,
+ 0.101037f, -0.00599999f, -0.132728f, 0.0996296f, -0.0096f,
+ -0.129689f, 0.0978f, -0.0108f, -0.12665f, 0.0959704f, -0.00959999f,
+ -0.124313f, 0.094563f, -0.00599998f, -0.123378f, 0.094f,
+ 1.68085e-008f, -0.142f, 0.0955f, 1.70767e-008f, -0.140965f,
+ 0.095163f, -0.00599999f, -0.138376f, 0.0943204f, -0.0096f,
+ -0.135011f, 0.093225f, -0.0108f, -0.131646f, 0.0921296f,
+ -0.00959999f, -0.129058f, 0.091287f, -0.00599998f, -0.128022f,
+ 0.09095f, 1.62631e-008f, -0.142933f, 0.0864f, -0.00599999f,
+ -0.140267f, 0.0864f, -0.0096f, -0.1368f, 0.0864f, -0.0108f,
+ -0.133333f, 0.0864f, -0.00959999f, -0.130667f, 0.0864f,
+ -0.00599998f, -0.128778f, 0.0802f, 1.43409e-008f, -0.129801f,
+ 0.079871f, 0.00600001f, -0.132358f, 0.0790484f, 0.00960001f,
+ -0.135683f, 0.0779792f, 0.0108f, -0.139008f, 0.0769099f, 0.0096f,
+ -0.141566f, 0.0760873f, 0.006f, -0.142589f, 0.0757583f,
+ 1.35466e-008f, -0.126222f, 0.0728f, 1.30176e-008f, -0.127118f,
+ 0.0722568f, 0.00600001f, -0.129356f, 0.0708988f, 0.00960001f,
+ -0.132267f, 0.0691333f, 0.0108f, -0.135177f, 0.0673679f, 0.0096f,
+ -0.137416f, 0.0660099f, 0.00599999f, -0.138311f, 0.0654667f,
+ 1.17063e-008f, -0.1218f, 0.0648f, 1.15871e-008f, -0.122489f,
+ 0.0641167f, 0.00600001f, -0.124211f, 0.0624083f, 0.00960001f,
+ -0.12645f, 0.0601875f, 0.0108f, -0.128689f, 0.0579667f, 0.0096f,
+ -0.130411f, 0.0562583f, 0.00599999f, -0.1311f, 0.055575f,
+ 9.93757e-009f, -0.115378f, 0.0568f, 1.01566e-008f, -0.115786f,
+ 0.0560099f, 0.00600001f, -0.116807f, 0.0540345f, 0.0096f,
+ -0.118133f, 0.0514667f, 0.0108f, -0.11946f, 0.0488987f, 0.0096f,
+ -0.120481f, 0.0469234f, 0.00599999f, -0.120889f, 0.0461333f,
+ 8.24927e-009f, -0.106822f, 0.0494f, 8.8334e-009f, -0.106881f,
+ 0.0484957f, 0.00600001f, -0.107027f, 0.0462349f, 0.00960001f,
+ -0.107217f, 0.0432958f, 0.0108f, -0.107407f, 0.0403568f, 0.0096f,
+ -0.107553f, 0.038096f, 0.00599999f, -0.107611f, 0.0371916f,
+ 6.65038e-009f, -0.0956444f, 0.0421333f, 0.00600001f, -0.0947556f,
+ 0.0394667f, 0.0096f, -0.0936f, 0.036f, 0.0108f, -0.0924444f,
+ 0.0325333f, 0.0096f, -0.0915556f, 0.0298667f, 0.00599999f,
+ -0.0912f, 0.0288f, 5.14984e-009f, -0.141566f, 0.0760873f,
+ -0.00599999f, -0.139008f, 0.0769099f, -0.0096f, -0.135683f,
+ 0.0779792f, -0.0108f, -0.132358f, 0.0790484f, -0.00959999f,
+ -0.129801f, 0.079871f, -0.00599998f, -0.137416f, 0.0660099f,
+ -0.006f, -0.135177f, 0.0673679f, -0.0096f, -0.132267f, 0.0691333f,
+ -0.0108f, -0.129356f, 0.0708988f, -0.00959999f, -0.127118f,
+ 0.0722568f, -0.00599998f, -0.130411f, 0.0562583f, -0.006f,
+ -0.128689f, 0.0579667f, -0.0096f, -0.12645f, 0.0601875f, -0.0108f,
+ -0.124211f, 0.0624083f, -0.00959999f, -0.122489f, 0.0641167f,
+ -0.00599998f, -0.120481f, 0.0469234f, -0.006f, -0.11946f,
+ 0.0488988f, -0.0096f, -0.118133f, 0.0514667f, -0.0108f, -0.116807f,
+ 0.0540346f, -0.00959999f, -0.115786f, 0.0560099f, -0.00599998f,
+ -0.107553f, 0.038096f, -0.006f, -0.107407f, 0.0403568f, -0.0096f,
+ -0.107217f, 0.0432958f, -0.0108f, -0.107027f, 0.0462349f,
+ -0.00959999f, -0.106881f, 0.0484957f, -0.00599998f, -0.0915556f,
+ 0.0298667f, -0.006f, -0.0924444f, 0.0325333f, -0.0096f, -0.0936f,
+ 0.036f, -0.0108f, -0.0947556f, 0.0394667f, -0.00959999f,
+ -0.0956445f, 0.0421333f, -0.00599998f, 0.0988222f, 0.0708667f,
+ 1.2672e-008f, 0.0816f, 0.0684f, 1.22309e-008f, 0.0994741f,
+ 0.0684099f, 0.0125926f, 0.0816f, 0.0654667f, 0.0132f, 0.101104f,
+ 0.0622679f, 0.0201482f, 0.0816f, 0.0581333f, 0.02112f, 0.103222f,
+ 0.0542833f, 0.0226667f, 0.0816f, 0.0486f, 0.02376f, 0.105341f,
+ 0.0462987f, 0.0201481f, 0.0816f, 0.0390666f, 0.02112f, 0.10697f,
+ 0.0401568f, 0.0125926f, 0.0816f, 0.0317333f, 0.0132f, 0.107622f,
+ 0.0377f, 6.74128e-009f, 0.0816f, 0.0288f, 5.14984e-009f, 0.108978f,
+ 0.0773333f, 1.38283e-008f, 0.109926f, 0.0754568f, 0.0110741f,
+ 0.112296f, 0.0707654f, 0.0177185f, 0.115378f, 0.0646667f,
+ 0.0199333f, 0.118459f, 0.0585679f, 0.0177185f, 0.12083f,
+ 0.0538765f, 0.0110741f, 0.121778f, 0.052f, 9.29832e-009f, 0.1146f,
+ 0.0864f, 1.54495e-008f, 0.115667f, 0.0851333f, 0.00910001f,
+ 0.118333f, 0.0819667f, 0.01456f, 0.1218f, 0.07785f, 0.01638f,
+ 0.125267f, 0.0737333f, 0.01456f, 0.127933f, 0.0705667f,
+ 0.00909999f, 0.129f, 0.0693f, 1.23918e-008f, 0.118222f, 0.0966667f,
+ 1.72853e-008f, 0.119407f, 0.0959654f, 0.00712594f, 0.12237f,
+ 0.0942123f, 0.0114015f, 0.126222f, 0.0919333f, 0.0128267f,
+ 0.130074f, 0.0896543f, 0.0114015f, 0.133037f, 0.0879012f,
+ 0.00712592f, 0.134222f, 0.0872f, 1.55926e-008f, 0.122378f,
+ 0.106733f, 1.90854e-008f, 0.123859f, 0.106479f, 0.00560742f,
+ 0.127563f, 0.105843f, 0.00897186f, 0.132378f, 0.105017f,
+ 0.0100933f, 0.137193f, 0.10419f, 0.00897185f, 0.140896f, 0.103554f,
+ 0.00560741f, 0.142378f, 0.1033f, 1.84715e-008f, 0.1296f, 0.1152f,
+ 2.05994e-008f, 0.131733f, 0.1152f, 0.00500001f, 0.137067f, 0.1152f,
+ 0.00800001f, 0.144f, 0.1152f, 0.00900001f, 0.150933f, 0.1152f,
+ 0.008f, 0.156267f, 0.1152f, 0.005f, 0.1584f, 0.1152f,
+ 2.05994e-008f, 0.107622f, 0.0377f, 6.74128e-009f, 0.10697f,
+ 0.0401568f, -0.0125926f, 0.0816f, 0.0317333f, -0.0132f, 0.105341f,
+ 0.0462988f, -0.0201482f, 0.0816f, 0.0390667f, -0.02112f, 0.103222f,
+ 0.0542833f, -0.0226667f, 0.0816f, 0.0486f, -0.02376f, 0.101104f,
+ 0.0622679f, -0.0201481f, 0.0816f, 0.0581334f, -0.02112f,
+ 0.0994741f, 0.0684099f, -0.0125926f, 0.0816f, 0.0654667f, -0.0132f,
+ 0.0988222f, 0.0708667f, 1.2672e-008f, 0.121778f, 0.052f,
+ 9.29832e-009f, 0.12083f, 0.0538765f, -0.0110741f, 0.118459f,
+ 0.0585679f, -0.0177185f, 0.115378f, 0.0646667f, -0.0199333f,
+ 0.112296f, 0.0707654f, -0.0177185f, 0.109926f, 0.0754568f,
+ -0.011074f, 0.127933f, 0.0705667f, -0.0091f, 0.125267f, 0.0737333f,
+ -0.01456f, 0.1218f, 0.07785f, -0.01638f, 0.118333f, 0.0819667f,
+ -0.01456f, 0.115667f, 0.0851333f, -0.00909997f, 0.134222f, 0.0872f,
+ 1.55926e-008f, 0.133037f, 0.0879012f, -0.00712592f, 0.130074f,
+ 0.0896543f, -0.0114015f, 0.126222f, 0.0919333f, -0.0128267f,
+ 0.12237f, 0.0942123f, -0.0114015f, 0.119407f, 0.0959654f,
+ -0.0071259f, 0.118222f, 0.0966667f, 1.72853e-008f, 0.142378f,
+ 0.1033f, 1.84715e-008f, 0.140896f, 0.103554f, -0.0056074f,
+ 0.137193f, 0.10419f, -0.00897185f, 0.132378f, 0.105017f,
+ -0.0100933f, 0.127563f, 0.105843f, -0.00897184f, 0.123859f,
+ 0.106479f, -0.00560739f, 0.122378f, 0.106733f, 1.90854e-008f,
+ 0.156267f, 0.1152f, -0.00499999f, 0.150933f, 0.1152f, -0.00799999f,
+ 0.144f, 0.1152f, -0.00899999f, 0.137067f, 0.1152f, -0.00799999f,
+ 0.131733f, 0.1152f, -0.00499998f, 0.131956f, 0.1167f,
+ 2.08676e-008f, 0.134228f, 0.116732f, 0.00485187f, 0.139908f,
+ 0.116813f, 0.00776297f, 0.147292f, 0.116919f, 0.00873334f,
+ 0.154676f, 0.117024f, 0.00776297f, 0.160356f, 0.117105f,
+ 0.00485185f, 0.162628f, 0.117137f, 2.09458e-008f, 0.134044f,
+ 0.1176f, 2.10285e-008f, 0.136309f, 0.117659f, 0.0044815f,
+ 0.141972f, 0.117807f, 0.00717038f, 0.149333f, 0.118f, 0.00806668f,
+ 0.156695f, 0.118193f, 0.00717038f, 0.162357f, 0.118341f,
+ 0.00448149f, 0.164622f, 0.1184f, 2.11716e-008f, 0.1356f, 0.1179f,
+ 2.10822e-008f, 0.137744f, 0.117975f, 0.00400002f, 0.143106f,
+ 0.118162f, 0.00640002f, 0.150075f, 0.118406f, 0.00720001f,
+ 0.157044f, 0.11865f, 0.00640001f, 0.162406f, 0.118838f,
+ 0.00400001f, 0.16455f, 0.118912f, 2.12632e-008f, 0.136356f,
+ 0.1176f, 2.10285e-008f, 0.138298f, 0.117674f, 0.00351854f,
+ 0.143154f, 0.117859f, 0.00562965f, 0.149467f, 0.1181f, 0.00633335f,
+ 0.155779f, 0.118341f, 0.00562964f, 0.160635f, 0.118526f,
+ 0.00351853f, 0.162578f, 0.1186f, 2.12074e-008f, 0.136044f, 0.1167f,
+ 2.08676e-008f, 0.137735f, 0.116751f, 0.00314817f, 0.141963f,
+ 0.116878f, 0.00503706f, 0.147458f, 0.117044f, 0.00566668f,
+ 0.152954f, 0.117209f, 0.00503705f, 0.157181f, 0.117337f,
+ 0.00314816f, 0.158872f, 0.117387f, 2.09906e-008f, 0.1344f, 0.1152f,
+ 2.05994e-008f, 0.135822f, 0.1152f, 0.00300002f, 0.139378f, 0.1152f,
+ 0.00480002f, 0.144f, 0.1152f, 0.00540002f, 0.148622f, 0.1152f,
+ 0.00480002f, 0.152178f, 0.1152f, 0.00300001f, 0.1536f, 0.1152f,
+ 2.05994e-008f, 0.160356f, 0.117105f, -0.00485184f, 0.154676f,
+ 0.117024f, -0.00776296f, 0.147292f, 0.116919f, -0.00873333f,
+ 0.139908f, 0.116813f, -0.00776295f, 0.134228f, 0.116732f,
+ -0.00485183f, 0.162357f, 0.118341f, -0.00448147f, 0.156695f,
+ 0.118193f, -0.00717036f, 0.149333f, 0.118f, -0.00806666f,
+ 0.141972f, 0.117807f, -0.00717036f, 0.136309f, 0.117659f,
+ -0.00448146f, 0.162406f, 0.118837f, -0.00399998f, 0.157044f,
+ 0.11865f, -0.00639999f, 0.150075f, 0.118406f, -0.00719999f,
+ 0.143106f, 0.118162f, -0.00639998f, 0.137744f, 0.117975f,
+ -0.00399998f, 0.160635f, 0.118526f, -0.0035185f, 0.155779f,
+ 0.118341f, -0.00562961f, 0.149467f, 0.1181f, -0.00633332f,
+ 0.143154f, 0.117859f, -0.00562961f, 0.138298f, 0.117674f,
+ -0.00351849f, 0.157181f, 0.117337f, -0.00314813f, 0.152954f,
+ 0.117209f, -0.00503702f, 0.147458f, 0.117044f, -0.00566665f,
+ 0.141963f, 0.116878f, -0.00503701f, 0.137735f, 0.116751f,
+ -0.00314812f, 0.152178f, 0.1152f, -0.00299998f, 0.148622f, 0.1152f,
+ -0.00479998f, 0.144f, 0.1152f, -0.00539998f, 0.139378f, 0.1152f,
+ -0.00479998f, 0.135822f, 0.1152f, -0.00299997f, 0.0133778f,
+ 0.1501f, 2.684e-008f, 0f, 0.1512f, 2.70367e-008f, 0.0129094f,
+ 0.1501f, 0.00360378f, 0f, 0.1512f, 2.70367e-008f, 0.0115817f,
+ 0.1501f, 0.00681272f, 0f, 0.1512f, 2.70367e-008f, 0.00951072f,
+ 0.1501f, 0.00951074f, 0.00681272f, 0.1501f, 0.0115817f,
+ 0.00360377f, 0.1501f, 0.0129094f, 0f, 0.1501f, 0.0133778f,
+ 0.0174222f, 0.1472f, 2.63214e-008f, 0.0168122f, 0.1472f,
+ 0.00469302f, 0.0150829f, 0.1472f, 0.00887204f, 0.0123858f, 0.1472f,
+ 0.0123858f, 0.00887205f, 0.1472f, 0.0150829f, 0.00469303f, 0.1472f,
+ 0.0168122f, 0f, 0.1472f, 0.0174222f, 0.0156f, 0.1431f,
+ 2.55883e-008f, 0.0150536f, 0.1431f, 0.00420141f, 0.0135049f,
+ 0.1431f, 0.00794312f, 0.0110895f, 0.1431f, 0.0110895f, 0.00794312f,
+ 0.1431f, 0.0135049f, 0.00420141f, 0.1431f, 0.0150536f, 0f, 0.1431f,
+ 0.0156f, 0.0113778f, 0.1384f, 2.47478e-008f, 0.0109789f, 0.1384f,
+ 0.00306257f, 0.00984863f, 0.1384f, 0.00579109f, 0.00808622f,
+ 0.1384f, 0.00808624f, 0.00579109f, 0.1384f, 0.00984864f,
+ 0.00306257f, 0.1384f, 0.0109789f, 0f, 0.1384f, 0.0113778f,
+ 0.00822222f, 0.1337f, 2.39074e-008f, 0.00793338f, 0.1337f,
+ 0.00221015f, 0.00711523f, 0.1337f, 0.00418109f, 0.00584028f,
+ 0.1337f, 0.0058403f, 0.00418108f, 0.1337f, 0.00711524f,
+ 0.00221014f, 0.1337f, 0.0079334f, 0f, 0.1337f, 0.00822224f,
+ 0.0096f, 0.1296f, 2.31743e-008f, 0.00926222f, 0.1296f, 0.0025778f,
+ 0.00830578f, 0.1296f, 0.00487824f, 0.006816f, 0.1296f, 0.00681602f,
+ 0.00487823f, 0.1296f, 0.00830579f, 0.00257779f, 0.1296f,
+ 0.00926224f, 0f, 0.1296f, 0.00960002f, 0f, 0.1501f, 0.0133778f,
+ -0.00360375f, 0.1501f, 0.0129094f, -0.0068127f, 0.1501f,
+ 0.0115817f, -0.00951072f, 0.1501f, 0.00951074f, -0.0115817f,
+ 0.1501f, 0.00681274f, -0.0129094f, 0.1501f, 0.00360379f,
+ -0.0133778f, 0.1501f, 2.684e-008f, 0f, 0.1472f, 0.0174222f,
+ -0.004693f, 0.1472f, 0.0168122f, -0.00887203f, 0.1472f, 0.0150829f,
+ -0.0123858f, 0.1472f, 0.0123858f, -0.0150829f, 0.1472f,
+ 0.00887207f, -0.0168122f, 0.1472f, 0.00469305f, -0.0174222f,
+ 0.1472f, 2.63214e-008f, -0.00420139f, 0.1431f, 0.0150536f,
+ -0.0079431f, 0.1431f, 0.0135049f, -0.0110895f, 0.1431f, 0.0110895f,
+ -0.0135049f, 0.1431f, 0.00794314f, -0.0150536f, 0.1431f,
+ 0.00420143f, -0.0156f, 0.1431f, 2.55883e-008f, 0f, 0.1384f,
+ 0.0113778f, -0.00306255f, 0.1384f, 0.010979f, -0.00579108f,
+ 0.1384f, 0.00984865f, -0.00808623f, 0.1384f, 0.00808624f,
+ -0.00984862f, 0.1384f, 0.00579111f, -0.0109789f, 0.1384f,
+ 0.00306259f, -0.0113778f, 0.1384f, 2.47478e-008f, 0f, 0.1337f,
+ 0.00822224f, -0.00221013f, 0.1337f, 0.00793341f, -0.00418107f,
+ 0.1337f, 0.00711525f, -0.00584028f, 0.1337f, 0.0058403f,
+ -0.00711522f, 0.1337f, 0.0041811f, -0.00793338f, 0.1337f,
+ 0.00221017f, -0.00822222f, 0.1337f, 2.39074e-008f, -0.00257778f,
+ 0.1296f, 0.00926224f, -0.00487822f, 0.1296f, 0.0083058f,
+ -0.006816f, 0.1296f, 0.00681602f, -0.00830577f, 0.1296f,
+ 0.00487825f, -0.00926222f, 0.1296f, 0.00257781f, -0.0096f, 0.1296f,
+ 2.31743e-008f, -0.0133778f, 0.1501f, 2.684e-008f, -0.0129094f,
+ 0.1501f, -0.00360373f, -0.0115817f, 0.1501f, -0.00681268f,
+ -0.00951073f, 0.1501f, -0.00951071f, -0.00681272f, 0.1501f,
+ -0.0115816f, -0.00360377f, 0.1501f, -0.0129094f, 0f, 0.1501f,
+ -0.0133778f, -0.0174222f, 0.1472f, 2.63214e-008f, -0.0168122f,
+ 0.1472f, -0.00469298f, -0.0150829f, 0.1472f, -0.00887201f,
+ -0.0123858f, 0.1472f, -0.0123858f, -0.00887205f, 0.1472f,
+ -0.0150829f, -0.00469303f, 0.1472f, -0.0168122f, 0f, 0.1472f,
+ -0.0174222f, -0.0150536f, 0.1431f, -0.00420136f, -0.0135049f,
+ 0.1431f, -0.00794309f, -0.0110895f, 0.1431f, -0.0110895f,
+ -0.00794312f, 0.1431f, -0.0135049f, -0.00420141f, 0.1431f,
+ -0.0150536f, 0f, 0.1431f, -0.0156f, -0.0113778f, 0.1384f,
+ 2.47478e-008f, -0.0109789f, 0.1384f, -0.00306252f, -0.00984862f,
+ 0.1384f, -0.00579105f, -0.00808622f, 0.1384f, -0.0080862f,
+ -0.00579108f, 0.1384f, -0.0098486f, -0.00306256f, 0.1384f,
+ -0.0109789f, 0f, 0.1384f, -0.0113778f, -0.00822222f, 0.1337f,
+ 2.39074e-008f, -0.00793338f, 0.1337f, -0.00221011f, -0.00711523f,
+ 0.1337f, -0.00418104f, -0.00584028f, 0.1337f, -0.00584025f,
+ -0.00418108f, 0.1337f, -0.0071152f, -0.00221014f, 0.1337f,
+ -0.00793336f, 0f, 0.1337f, -0.0082222f, -0.00926222f, 0.1296f,
+ -0.00257775f, -0.00830578f, 0.1296f, -0.0048782f, -0.006816f,
+ 0.1296f, -0.00681598f, -0.00487823f, 0.1296f, -0.00830575f,
+ -0.00257779f, 0.1296f, -0.0092622f, 0f, 0.1296f, -0.00959998f,
+ 0.00360375f, 0.1501f, -0.0129094f, 0.0068127f, 0.1501f,
+ -0.0115817f, 0.00951073f, 0.1501f, -0.00951071f, 0.0115817f,
+ 0.1501f, -0.0068127f, 0.0129094f, 0.1501f, -0.00360375f,
+ 0.0133778f, 0.1501f, 2.684e-008f, 0.004693f, 0.1472f, -0.0168122f,
+ 0.00887203f, 0.1472f, -0.0150829f, 0.0123858f, 0.1472f,
+ -0.0123858f, 0.0150829f, 0.1472f, -0.00887203f, 0.0168122f,
+ 0.1472f, -0.004693f, 0.0174222f, 0.1472f, 2.63214e-008f,
+ 0.00420139f, 0.1431f, -0.0150536f, 0.0079431f, 0.1431f,
+ -0.0135049f, 0.0110895f, 0.1431f, -0.0110895f, 0.0135049f, 0.1431f,
+ -0.00794311f, 0.0150536f, 0.1431f, -0.00420139f, 0.00306255f,
+ 0.1384f, -0.0109789f, 0.00579107f, 0.1384f, -0.0098486f,
+ 0.00808622f, 0.1384f, -0.0080862f, 0.00984861f, 0.1384f,
+ -0.00579106f, 0.0109789f, 0.1384f, -0.00306254f, 0.0113778f,
+ 0.1384f, 2.47478e-008f, 0.00221013f, 0.1337f, -0.00793336f,
+ 0.00418106f, 0.1337f, -0.00711521f, 0.00584028f, 0.1337f,
+ -0.00584025f, 0.00711522f, 0.1337f, -0.00418105f, 0.00793338f,
+ 0.1337f, -0.00221012f, 0.00822222f, 0.1337f, 2.39074e-008f,
+ 0.00257778f, 0.1296f, -0.0092622f, 0.00487822f, 0.1296f,
+ -0.00830576f, 0.006816f, 0.1296f, -0.00681598f, 0.00830577f,
+ 0.1296f, -0.00487821f, 0.00926222f, 0.1296f, -0.00257777f,
+ 0.0168444f, 0.126533f, 2.26259e-008f, 0.0162518f, 0.126533f,
+ 0.00452306f, 0.0145736f, 0.126533f, 0.00855948f, 0.0119595f,
+ 0.126533f, 0.0119596f, 0.00855948f, 0.126533f, 0.0145736f,
+ 0.00452306f, 0.126533f, 0.0162518f, 0f, 0.126533f, 0.0168444f,
+ 0.0275555f, 0.124267f, 2.22206e-008f, 0.026586f, 0.124267f,
+ 0.00739918f, 0.0238406f, 0.124267f, 0.0140023f, 0.0195644f,
+ 0.124267f, 0.0195644f, 0.0140023f, 0.124267f, 0.0238406f,
+ 0.0073992f, 0.124267f, 0.026586f, 0f, 0.124267f, 0.0275555f,
+ 0.0396f, 0.1224f, 2.18868e-008f, 0.0382067f, 0.1224f, 0.0106333f,
+ 0.0342613f, 0.1224f, 0.0201227f, 0.028116f, 0.1224f, 0.028116f,
+ 0.0201227f, 0.1224f, 0.0342613f, 0.0106334f, 0.1224f, 0.0382067f,
+ 0f, 0.1224f, 0.0396f, 0.0508444f, 0.120533f, 2.1553e-008f,
+ 0.0490554f, 0.120533f, 0.0136527f, 0.0439898f, 0.120533f,
+ 0.0258365f, 0.0360995f, 0.120533f, 0.0360995f, 0.0258365f,
+ 0.120533f, 0.0439898f, 0.0136527f, 0.120533f, 0.0490554f, 0f,
+ 0.120533f, 0.0508444f, 0.0591555f, 0.118267f, 2.11477e-008f,
+ 0.0570741f, 0.118267f, 0.0158844f, 0.0511805f, 0.118267f,
+ 0.0300598f, 0.0420004f, 0.118267f, 0.0420004f, 0.0300598f,
+ 0.118267f, 0.0511805f, 0.0158844f, 0.118267f, 0.0570741f, 0f,
+ 0.118267f, 0.0591555f, 0.0624f, 0.1152f, 2.05994e-008f, 0.0602044f,
+ 0.1152f, 0.0167556f, 0.0539876f, 0.1152f, 0.0317084f, 0.044304f,
+ 0.1152f, 0.044304f, 0.0317085f, 0.1152f, 0.0539875f, 0.0167556f,
+ 0.1152f, 0.0602044f, 0f, 0.1152f, 0.0624f, -0.00452304f, 0.126533f,
+ 0.0162518f, -0.00855946f, 0.126533f, 0.0145736f, -0.0119595f,
+ 0.126533f, 0.0119596f, -0.0145735f, 0.126533f, 0.0085595f,
+ -0.0162518f, 0.126533f, 0.00452308f, -0.0168444f, 0.126533f,
+ 2.26259e-008f, -0.00739916f, 0.124267f, 0.026586f, -0.0140023f,
+ 0.124267f, 0.0238407f, -0.0195644f, 0.124267f, 0.0195644f,
+ -0.0238406f, 0.124267f, 0.0140023f, -0.026586f, 0.124267f,
+ 0.00739922f, -0.0275555f, 0.124267f, 2.22206e-008f, -0.0106333f,
+ 0.1224f, 0.0382067f, -0.0201227f, 0.1224f, 0.0342613f, -0.028116f,
+ 0.1224f, 0.028116f, -0.0342613f, 0.1224f, 0.0201227f, -0.0382067f,
+ 0.1224f, 0.0106334f, -0.0396f, 0.1224f, 2.18868e-008f, -0.0136527f,
+ 0.120533f, 0.0490554f, -0.0258365f, 0.120533f, 0.0439898f,
+ -0.0360995f, 0.120533f, 0.0360995f, -0.0439898f, 0.120533f,
+ 0.0258365f, -0.0490554f, 0.120533f, 0.0136527f, -0.0508444f,
+ 0.120533f, 2.1553e-008f, -0.0158843f, 0.118267f, 0.0570741f,
+ -0.0300597f, 0.118267f, 0.0511805f, -0.0420004f, 0.118267f,
+ 0.0420004f, -0.0511805f, 0.118267f, 0.0300598f, -0.0570741f,
+ 0.118267f, 0.0158844f, -0.0591555f, 0.118267f, 2.11477e-008f,
+ -0.0167555f, 0.1152f, 0.0602044f, -0.0317084f, 0.1152f, 0.0539876f,
+ -0.044304f, 0.1152f, 0.044304f, -0.0539875f, 0.1152f, 0.0317085f,
+ -0.0602044f, 0.1152f, 0.0167556f, -0.0624f, 0.1152f, 2.05994e-008f,
+ -0.0162518f, 0.126533f, -0.00452302f, -0.0145736f, 0.126533f,
+ -0.00855945f, -0.0119595f, 0.126533f, -0.0119595f, -0.00855948f,
+ 0.126533f, -0.0145735f, -0.00452306f, 0.126533f, -0.0162517f, 0f,
+ 0.126533f, -0.0168444f, -0.026586f, 0.124267f, -0.00739915f,
+ -0.0238406f, 0.124267f, -0.0140023f, -0.0195644f, 0.124267f,
+ -0.0195644f, -0.0140023f, 0.124267f, -0.0238406f, -0.0073992f,
+ 0.124267f, -0.026586f, 0f, 0.124267f, -0.0275555f, -0.0382067f,
+ 0.1224f, -0.0106333f, -0.0342613f, 0.1224f, -0.0201226f,
+ -0.028116f, 0.1224f, -0.028116f, -0.0201227f, 0.1224f, -0.0342613f,
+ -0.0106334f, 0.1224f, -0.0382066f, 0f, 0.1224f, -0.0396f,
+ -0.0490554f, 0.120533f, -0.0136526f, -0.0439898f, 0.120533f,
+ -0.0258365f, -0.0360995f, 0.120533f, -0.0360995f, -0.0258365f,
+ 0.120533f, -0.0439898f, -0.0136527f, 0.120533f, -0.0490554f, 0f,
+ 0.120533f, -0.0508444f, -0.0570741f, 0.118267f, -0.0158843f,
+ -0.0511805f, 0.118267f, -0.0300597f, -0.0420004f, 0.118267f,
+ -0.0420004f, -0.0300598f, 0.118267f, -0.0511805f, -0.0158844f,
+ 0.118267f, -0.0570741f, 0f, 0.118267f, -0.0591555f, -0.0602044f,
+ 0.1152f, -0.0167555f, -0.0539876f, 0.1152f, -0.0317084f,
+ -0.044304f, 0.1152f, -0.044304f, -0.0317085f, 0.1152f, -0.0539875f,
+ -0.0167556f, 0.1152f, -0.0602044f, 0f, 0.1152f, -0.0624f,
+ 0.00452304f, 0.126533f, -0.0162517f, 0.00855946f, 0.126533f,
+ -0.0145735f, 0.0119595f, 0.126533f, -0.0119595f, 0.0145735f,
+ 0.126533f, -0.00855947f, 0.0162518f, 0.126533f, -0.00452304f,
+ 0.00739916f, 0.124267f, -0.026586f, 0.0140023f, 0.124267f,
+ -0.0238406f, 0.0195644f, 0.124267f, -0.0195644f, 0.0238406f,
+ 0.124267f, -0.0140023f, 0.026586f, 0.124267f, -0.00739919f,
+ 0.0106333f, 0.1224f, -0.0382067f, 0.0201227f, 0.1224f, -0.0342613f,
+ 0.028116f, 0.1224f, -0.028116f, 0.0342613f, 0.1224f, -0.0201227f,
+ 0.0382067f, 0.1224f, -0.0106334f, 0.0136527f, 0.120533f,
+ -0.0490554f, 0.0258365f, 0.120533f, -0.0439898f, 0.0360995f,
+ 0.120533f, -0.0360995f, 0.0439898f, 0.120533f, -0.0258365f,
+ 0.0490554f, 0.120533f, -0.0136527f, 0.0158843f, 0.118267f,
+ -0.0570741f, 0.0300597f, 0.118267f, -0.0511805f, 0.0420004f,
+ 0.118267f, -0.0420004f, 0.0511805f, 0.118267f, -0.0300598f,
+ 0.0570741f, 0.118267f, -0.0158844f, 0.0167555f, 0.1152f,
+ -0.0602044f, 0.0317084f, 0.1152f, -0.0539876f, 0.044304f, 0.1152f,
+ -0.044304f, 0.0539875f, 0.1152f, -0.0317085f, 0.0602044f, 0.1152f,
+ -0.0167556f, 0.0290833f, 0.000283333f, 5.06639e-011f, 0f, 0f, 0f,
+ 0.02806f, 0.000283335f, -0.00780941f, 0.0251625f, 0.000283336f,
+ -0.0147786f, 0.0206492f, 0.000283337f, -0.0206492f, 0.0147787f,
+ 0.000283338f, -0.0251625f, 0.00780945f, 0.000283338f, -0.02806f,
+ 0f, 0.000283338f, -0.0290833f, 0.0490667f, 0.00106667f,
+ 1.90735e-010f, 0.0473403f, 0.00106667f, -0.0131753f, 0.0424518f,
+ 0.00106667f, -0.0249331f, 0.0348373f, 0.00106667f, -0.0348373f,
+ 0.0249332f, 0.00106667f, -0.0424517f, 0.0131754f, 0.00106667f,
+ -0.0473402f, 0f, 0.00106667f, -0.0490667f, 0.06165f, 0.00225f,
+ 4.02331e-010f, 0.0594808f, 0.00225f, -0.0165542f, 0.0533387f,
+ 0.00225001f, -0.0313273f, 0.0437715f, 0.00225001f, -0.0437715f,
+ 0.0313274f, 0.00225001f, -0.0533386f, 0.0165542f, 0.00225001f,
+ -0.0594808f, 0f, 0.00225001f, -0.06165f, 0.0685333f, 0.00373333f,
+ 6.67572e-010f, 0.066122f, 0.00373334f, -0.0184025f, 0.059294f,
+ 0.00373334f, -0.0348251f, 0.0486587f, 0.00373334f, -0.0486587f,
+ 0.0348251f, 0.00373334f, -0.059294f, 0.0184026f, 0.00373334f,
+ -0.066122f, 0f, 0.00373334f, -0.0685333f, 0.0714167f, 0.00541667f,
+ 9.68575e-010f, 0.0689039f, 0.00541667f, -0.0191767f, 0.0617887f,
+ 0.00541667f, -0.0362902f, 0.0507058f, 0.00541668f, -0.0507058f,
+ 0.0362903f, 0.00541668f, -0.0617886f, 0.0191768f, 0.00541668f,
+ -0.0689038f, 0f, 0.00541668f, -0.0714167f, 0.0694667f, 0.0072f,
+ -0.0193333f, 0.0622933f, 0.00720001f, -0.0365866f, 0.0365867f,
+ 0.00720001f, -0.0622933f, 0.0193334f, 0.00720001f, -0.0694666f, 0f,
+ 0.000283338f, -0.0290833f, -0.0078094f, 0.000283338f, -0.02806f,
+ -0.0147786f, 0.000283338f, -0.0251625f, -0.0206492f, 0.000283337f,
+ -0.0206492f, -0.0251624f, 0.000283336f, -0.0147787f, -0.02806f,
+ 0.000283335f, -0.00780945f, -0.0290833f, 0.000283333f,
+ 5.06639e-011f, 0f, 0.00106667f, -0.0490667f, -0.0131753f,
+ 0.00106667f, -0.0473402f, -0.0249331f, 0.00106667f, -0.0424518f,
+ -0.0348373f, 0.00106667f, -0.0348373f, -0.0424517f, 0.00106667f,
+ -0.0249332f, -0.0473402f, 0.00106667f, -0.0131754f, -0.0490667f,
+ 0.00106667f, 1.90735e-010f, -0.0165542f, 0.00225001f, -0.0594808f,
+ -0.0313273f, 0.00225001f, -0.0533387f, -0.0437715f, 0.00225001f,
+ -0.0437715f, -0.0533386f, 0.00225001f, -0.0313274f, -0.0594808f,
+ 0.00225f, -0.0165542f, -0.06165f, 0.00225f, 4.02331e-010f, 0f,
+ 0.00373334f, -0.0685333f, -0.0184024f, 0.00373334f, -0.066122f,
+ -0.0348251f, 0.00373334f, -0.059294f, -0.0486587f, 0.00373334f,
+ -0.0486587f, -0.059294f, 0.00373334f, -0.0348251f, -0.0661219f,
+ 0.00373334f, -0.0184026f, -0.0685333f, 0.00373333f, 6.67572e-010f,
+ 0f, 0.00541667f, -0.0714167f, -0.0191767f, 0.00541668f,
+ -0.0689039f, -0.0362902f, 0.00541667f, -0.0617887f, -0.0507058f,
+ 0.00541667f, -0.0507058f, -0.0617886f, 0.00541667f, -0.0362903f,
+ -0.0689038f, 0.00541667f, -0.0191768f, -0.0714167f, 0.00541666f,
+ 9.68575e-010f, -0.0193333f, 0.00720001f, -0.0694667f, -0.0365866f,
+ 0.00720001f, -0.0622933f, -0.0622933f, 0.00720001f, -0.0365867f,
+ -0.0694666f, 0.0072f, -0.0193334f, -0.0290833f, 0.000283334f,
+ 5.0664e-011f, -0.02806f, 0.000283332f, 0.00780941f, -0.0251625f,
+ 0.000283331f, 0.0147786f, -0.0206492f, 0.00028333f, 0.0206492f,
+ -0.0147787f, 0.000283329f, 0.0251625f, -0.00780945f, 0.000283329f,
+ 0.02806f, 0f, 0.000283329f, 0.0290833f, -0.0490667f, 0.00106667f,
+ 1.90735e-010f, -0.0473403f, 0.00106667f, 0.0131753f, -0.0424518f,
+ 0.00106666f, 0.0249331f, -0.0348374f, 0.00106666f, 0.0348374f,
+ -0.0249332f, 0.00106666f, 0.0424517f, -0.0131754f, 0.00106666f,
+ 0.0473402f, 0f, 0.00106666f, 0.0490667f, -0.0594808f, 0.00225f,
+ 0.0165542f, -0.0533387f, 0.00224999f, 0.0313273f, -0.0437715f,
+ 0.00224999f, 0.0437715f, -0.0313274f, 0.00224999f, 0.0533386f,
+ -0.0165542f, 0.00224999f, 0.0594808f, 0f, 0.00224999f, 0.06165f,
+ -0.0685333f, 0.00373334f, 6.67572e-010f, -0.066122f, 0.00373333f,
+ 0.0184025f, -0.059294f, 0.00373333f, 0.0348251f, -0.0486587f,
+ 0.00373333f, 0.0486587f, -0.0348251f, 0.00373333f, 0.059294f,
+ -0.0184026f, 0.00373333f, 0.066122f, 0f, 0.00373333f, 0.0685333f,
+ -0.0714167f, 0.00541667f, 9.68576e-010f, -0.0689039f, 0.00541667f,
+ 0.0191767f, -0.0617887f, 0.00541666f, 0.0362902f, -0.0507058f,
+ 0.00541666f, 0.0507058f, -0.0362903f, 0.00541666f, 0.0617886f,
+ -0.0191768f, 0.00541666f, 0.0689038f, 0f, 0.00541666f, 0.0714167f,
+ -0.0694667f, 0.0072f, 0.0193333f, -0.0622933f, 0.00719999f,
+ 0.0365866f, -0.05112f, 0.00719999f, 0.05112f, -0.0365867f,
+ 0.00719999f, 0.0622933f, -0.0193334f, 0.00719999f, 0.0694666f,
+ 0.00780941f, 0.000283329f, 0.02806f, 0.0147786f, 0.000283329f,
+ 0.0251625f, 0.0206492f, 0.00028333f, 0.0206492f, 0.0251625f,
+ 0.000283331f, 0.0147787f, 0.02806f, 0.000283332f, 0.00780945f,
+ 0.0290833f, 0.000283334f, 5.0664e-011f, 0.0131753f, 0.00106666f,
+ 0.0473403f, 0.0249331f, 0.00106666f, 0.0424518f, 0.0348374f,
+ 0.00106666f, 0.0348374f, 0.0424517f, 0.00106666f, 0.0249332f,
+ 0.0473402f, 0.00106666f, 0.0131754f, 0.0490667f, 0.00106667f,
+ 1.90735e-010f, 0.0165542f, 0.00224999f, 0.0594808f, 0.0313273f,
+ 0.00224999f, 0.0533387f, 0.0437715f, 0.00224999f, 0.0437715f,
+ 0.0533386f, 0.00224999f, 0.0313274f, 0.0594808f, 0.00225f,
+ 0.0165542f, 0.0184025f, 0.00373333f, 0.066122f, 0.0348251f,
+ 0.00373333f, 0.059294f, 0.0486587f, 0.00373333f, 0.0486587f,
+ 0.059294f, 0.00373333f, 0.0348251f, 0.066122f, 0.00373333f,
+ 0.0184026f, 0.0685333f, 0.00373334f, 6.67572e-010f, 0.0191767f,
+ 0.00541666f, 0.0689039f, 0.0362902f, 0.00541666f, 0.0617887f,
+ 0.0507058f, 0.00541666f, 0.0507058f, 0.0617886f, 0.00541666f,
+ 0.0362903f, 0.0689038f, 0.00541667f, 0.0191768f, 0.0714167f,
+ 0.00541667f, 9.68576e-010f, 0.0193333f, 0.00719999f, 0.0694667f,
+ 0.0365866f, 0.00719999f, 0.0622933f, 0.05112f, 0.00719999f,
+ 0.05112f, 0.0622933f, 0.00719999f, 0.0365867f, 0.0694666f, 0.0072f,
+ 0.0193334f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f,
+ 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f,
+ 0f, 0f, 0f, 0f, 0f, -0.06165f, 0.00225f, 4.02331e-010f, 0f, 0f, 0f,
+ 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f,
+ 0f, 0.06165f, 0.00225f, 4.02331e-010f, 0f, 0f, 0f, 0f, 0f, 0f, 0f,
+ 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0.006816f, 0.1296f,
+ 0.00681602f, 0.00487823f, 0.1296f, 0.00830579f, 0.00257779f,
+ 0.1296f, 0.00926224f, 0f, 0.1296f, 0.00960002f, 0f, 0.1512f,
+ 2.70367e-008f, 0f, 0.1512f, 2.70367e-008f, 0f, 0.1512f,
+ 2.70367e-008f, 0f, 0.1512f, 2.70367e-008f, 0f, 0.1512f,
+ 2.70367e-008f, 0f, 0.1512f, 2.70367e-008f, 0f, 0.1512f,
+ 2.70367e-008f, 0f, 0.1512f, 2.70367e-008f, 0f, 0.1512f,
+ 2.70367e-008f, 0f, 0.1512f, 2.70367e-008f, 0f, 0.1512f,
+ 2.70367e-008f, 0f, 0.1512f, 2.70367e-008f, 0f, 0.1512f,
+ 2.70367e-008f, 0f, 0.1512f, 2.70367e-008f, 0f, 0.1512f,
+ 2.70367e-008f, 0f, 0.1512f, 2.70367e-008f, 0f, 0.1512f,
+ 2.70367e-008f, 0.00830577f, 0.1296f, -0.00487821f, 0.00487822f,
+ 0.1296f, -0.00830576f, 0.00257778f, 0.1296f, -0.0092622f, 0f,
+ 0.1296f, -0.00959998f, -0.00257779f, 0.1296f, -0.0092622f,
+ -0.00487823f, 0.1296f, -0.00830575f, -0.00830578f, 0.1296f,
+ -0.0048782f, -0.00257778f, 0.1296f, 0.00926224f, -0.00487822f,
+ 0.1296f, 0.0083058f, -0.006816f, 0.1296f, 0.00681602f, 0f, 0.1512f,
+ 2.70367e-008f, 0f, 0.1512f, 2.70367e-008f, 0f, 0.1512f,
+ 2.70367e-008f, 0f, 0.1512f, 2.70367e-008f, 0f, 0.1512f,
+ 2.70367e-008f, 0f, 0.1512f, 2.70367e-008f, 0f, 0.1512f,
+ 2.70367e-008f, 0.156267f, 0.1152f, -0.00499999f, 0.131733f,
+ 0.1152f, -0.00499998f, 0.1296f, 0.1152f, 2.05994e-008f, 0.137067f,
+ 0.1152f, 0.00800001f, -0.094f, 0.1079f, 1.9294e-008f, -0.096f,
+ 0.0432f, 7.72476e-009f, -0.0897778f, 0.0250667f, 4.48227e-009f,
+ 0.0897778f, 0.0250667f, 4.48227e-009f, -0.084f, 0.01845f,
+ 3.29912e-009f, 0.084f, 0.01845f, 3.29912e-009f, -0.0782222f,
+ 0.0133334f, 2.38419e-009f, 0.0782222f, 0.0133334f, 2.38419e-009f,
+ -0.0737778f, 0.00961668f, 1.7196e-009f, 0.0737778f, 0.00961668f,
+ 1.7196e-009f, 0.0926222f, 0.0432f, 0.0257778f, 0.072f, 0.1152f,
+ 2.05994e-008f, 0.05112f, 0.1152f, -0.05112f, 0f, 0.1152f, -0.072f,
+ -0.05112f, 0.1152f, -0.05112f, -0.072f, 0.1152f, 2.05994e-008f, 0f,
+ 0.1152f, 0.072f, -0.05112f, 0.1152f, 0.05112f, -0.0687556f,
+ 0.1194f, 2.13504e-008f, 0.05112f, 0.1152f, 0.05112f, 0f, 0.117825f,
+ 0.0663056f, -0.0396f, 0.1224f, 2.18868e-008f, 0.0396f, 0.1224f,
+ 2.18868e-008f };
+ static float teapot_normals[] = { -0.987635f, -0.156768f, 0f, -0.902861f,
+ -0.429933f, 0f, -0.953562f, -0.156989f, -0.257047f, -0.871509f,
+ -0.430441f, -0.234929f, -0.854265f, -0.157281f, -0.495474f,
+ -0.780517f, -0.431109f, -0.4527f, -0.698293f, -0.157393f,
+ -0.698294f, -0.637936f, -0.431366f, -0.637936f, -0.495474f,
+ -0.157281f, -0.854265f, -0.4527f, -0.431109f, -0.780517f,
+ -0.257047f, -0.156989f, -0.953562f, -0.234929f, -0.430441f,
+ -0.871509f, 0f, -0.156767f, -0.987636f, 0f, -0.429933f, -0.902861f,
+ -0.880022f, 0.474932f, 0f, -0.849414f, 0.475466f, -0.228973f,
+ -0.76067f, 0.476166f, -0.441189f, -0.621695f, 0.476435f,
+ -0.621695f, -0.441189f, 0.476166f, -0.76067f, -0.228972f,
+ 0.475466f, -0.849414f, 0f, 0.474932f, -0.880022f, 0f, 1f, 0f,
+ -3.12489e-007f, 1f, -4.53013e-008f, -4.74898e-007f, 1f,
+ -2.15741e-007f, 0f, 1f, 0f, -1.19502e-007f, 1f, -2.57504e-007f,
+ -5.01339e-008f, 1f, -1.37835e-007f, 0f, 1f, 0f, 0.556738f,
+ 0.830688f, 0f, 0.537013f, 0.831061f, 0.14476f, 0.480481f, 0.83155f,
+ 0.278679f, 0.392564f, 0.831738f, 0.392564f, 0.278679f, 0.83155f,
+ 0.480481f, 0.14476f, 0.831061f, 0.537012f, 0f, 0.830688f,
+ 0.556738f, 0.783289f, 0.621658f, 0f, 0.755869f, 0.622211f,
+ 0.203756f, 0.67669f, 0.622937f, 0.39248f, 0.552994f, 0.623214f,
+ 0.552994f, 0.39248f, 0.622936f, 0.676691f, 0.203756f, 0.62221f,
+ 0.755869f, 0f, 0.621658f, 0.783289f, 0.90286f, 0.429934f, 0f,
+ 0.871509f, 0.430442f, 0.234929f, 0.780517f, 0.431109f, 0.4527f,
+ 0.637935f, 0.431366f, 0.637936f, 0.4527f, 0.431109f, 0.780517f,
+ 0.234929f, 0.430441f, 0.87151f, 0f, 0.429934f, 0.90286f, 0.257047f,
+ -0.156989f, -0.953562f, 0.234929f, -0.430441f, -0.871509f,
+ 0.495474f, -0.157281f, -0.854265f, 0.4527f, -0.431109f, -0.780517f,
+ 0.698293f, -0.157393f, -0.698294f, 0.637936f, -0.431366f,
+ -0.637936f, 0.854265f, -0.157281f, -0.495474f, 0.780517f,
+ -0.431109f, -0.4527f, 0.953562f, -0.156989f, -0.257047f, 0.871509f,
+ -0.430441f, -0.234929f, 0.987636f, -0.156767f, 0f, 0.902861f,
+ -0.429933f, 0f, 0.228973f, 0.475465f, -0.849414f, 0.441188f,
+ 0.476167f, -0.760669f, 0.621695f, 0.476434f, -0.621696f, 0.76067f,
+ 0.476167f, -0.441188f, 0.849414f, 0.475466f, -0.228972f, 0.880022f,
+ 0.474932f, 0f, 4.53013e-008f, 1f, -3.12489e-007f, 2.15741e-007f,
+ 1f, -4.74898e-007f, 0f, 1f, 0f, 2.57504e-007f, 1f, -1.19502e-007f,
+ 1.37835e-007f, 1f, -5.01339e-008f, 0f, 1f, 0f, 0f, 0.830689f,
+ 0.556737f, -0.14476f, 0.831061f, 0.537012f, -0.278679f, 0.83155f,
+ 0.480481f, -0.392563f, 0.831738f, 0.392563f, -0.480482f, 0.83155f,
+ 0.27868f, -0.537012f, 0.831061f, 0.14476f, -0.556738f, 0.830688f,
+ 0f, 0f, 0.621658f, 0.783289f, -0.203756f, 0.62221f, 0.755869f,
+ -0.39248f, 0.622937f, 0.67669f, -0.552993f, 0.623215f, 0.552993f,
+ -0.67669f, 0.622937f, 0.39248f, -0.755869f, 0.62221f, 0.203756f,
+ -0.783289f, 0.621658f, 0f, -0.234929f, 0.430442f, 0.871509f,
+ -0.4527f, 0.431109f, 0.780517f, -0.637935f, 0.431366f, 0.637936f,
+ -0.780517f, 0.431109f, 0.4527f, -0.87151f, 0.430441f, 0.234929f,
+ -0.90286f, 0.429934f, 0f, 0.987636f, -0.156767f, 0f, 0.953562f,
+ -0.156989f, 0.257047f, 0.871509f, -0.430441f, 0.234929f, 0.854265f,
+ -0.15728f, 0.495474f, 0.780517f, -0.431109f, 0.4527f, 0.698294f,
+ -0.157393f, 0.698293f, 0.637936f, -0.431366f, 0.637936f, 0.495474f,
+ -0.157281f, 0.854265f, 0.4527f, -0.431109f, 0.780517f, 0.257047f,
+ -0.156989f, 0.953562f, 0.234929f, -0.430441f, 0.871509f, 0f,
+ -0.156767f, 0.987636f, 0f, -0.429933f, 0.902861f, 0.880022f,
+ 0.474934f, 0f, 0.849413f, 0.475467f, 0.228972f, 0.760669f,
+ 0.476167f, 0.441188f, 0.621695f, 0.476436f, 0.621695f, 0.441188f,
+ 0.476167f, 0.760669f, 0.228972f, 0.475466f, 0.849414f, 0f,
+ 0.474934f, 0.880022f, 3.12489e-007f, 1f, 4.53013e-008f,
+ 4.74898e-007f, 1f, 2.15741e-007f, 0f, 1f, 0f, 1.19502e-007f, 1f,
+ 2.57504e-007f, 5.01339e-008f, 1f, 1.37835e-007f, 0f, 1f, 0f,
+ -0.537013f, 0.831061f, -0.14476f, -0.480482f, 0.83155f, -0.27868f,
+ -0.392566f, 0.831735f, -0.392566f, -0.27868f, 0.83155f, -0.480482f,
+ -0.14476f, 0.831061f, -0.537012f, 0f, 0.830688f, -0.556738f,
+ -0.783289f, 0.621657f, 0f, -0.755869f, 0.62221f, -0.203756f,
+ -0.676691f, 0.622936f, -0.39248f, -0.552994f, 0.623215f,
+ -0.552993f, -0.392481f, 0.622936f, -0.676691f, -0.203756f,
+ 0.622209f, -0.75587f, 0f, 0.621657f, -0.783289f, -0.871509f,
+ 0.430442f, -0.234929f, -0.780517f, 0.431109f, -0.4527f, -0.637936f,
+ 0.431366f, -0.637935f, -0.4527f, 0.431109f, -0.780517f, -0.234929f,
+ 0.430441f, -0.87151f, 0f, 0.429934f, -0.90286f, -0.257047f,
+ -0.156989f, 0.953562f, -0.234929f, -0.430441f, 0.871509f,
+ -0.495474f, -0.15728f, 0.854265f, -0.4527f, -0.431109f, 0.780517f,
+ -0.698294f, -0.157393f, 0.698293f, -0.637936f, -0.431366f,
+ 0.637936f, -0.854265f, -0.157281f, 0.495474f, -0.780517f,
+ -0.431109f, 0.4527f, -0.953562f, -0.156989f, 0.257047f, -0.871509f,
+ -0.430442f, 0.234928f, -0.987636f, -0.156767f, 0f, -0.228972f,
+ 0.475467f, 0.849413f, -0.441188f, 0.476167f, 0.760669f, -0.621695f,
+ 0.476436f, 0.621695f, -0.76067f, 0.476167f, 0.441188f, -0.849414f,
+ 0.475466f, 0.228972f, -0.880022f, 0.474934f, 0f, -4.53013e-008f,
+ 1f, 3.12489e-007f, -2.15741e-007f, 1f, 4.74898e-007f, 0f, 1f, 0f,
+ -2.57504e-007f, 1f, 1.19502e-007f, -1.37835e-007f, 1f,
+ 5.01339e-008f, 0.14476f, 0.831061f, -0.537013f, 0.27868f, 0.83155f,
+ -0.480482f, 0.392566f, 0.831735f, -0.392566f, 0.480482f, 0.83155f,
+ -0.27868f, 0.537012f, 0.831061f, -0.14476f, 0.556738f, 0.830688f,
+ 0f, 0.203756f, 0.62221f, -0.755869f, 0.392481f, 0.622936f,
+ -0.67669f, 0.552994f, 0.623215f, -0.552993f, 0.676691f, 0.622936f,
+ -0.39248f, 0.75587f, 0.622209f, -0.203756f, 0.783289f, 0.621657f,
+ 0f, 0.234929f, 0.430442f, -0.871509f, 0.4527f, 0.431109f,
+ -0.780517f, 0.637936f, 0.431366f, -0.637935f, 0.780517f, 0.431109f,
+ -0.4527f, 0.87151f, 0.430441f, -0.234928f, 0.906828f, 0.421501f,
+ 0f, 0.875348f, 0.422003f, 0.235963f, 0.871509f, 0.430442f,
+ 0.234929f, 0.783966f, 0.422664f, 0.4547f, 0.780517f, 0.43111f,
+ 0.4527f, 0.640758f, 0.422917f, 0.640758f, 0.4547f, 0.422664f,
+ 0.783966f, 0.4527f, 0.43111f, 0.780517f, 0.235964f, 0.422003f,
+ 0.875348f, 0.234929f, 0.430442f, 0.871509f, 0f, 0.421501f,
+ 0.906828f, 0.918633f, 0.395111f, 0f, 0.886771f, 0.395595f,
+ 0.239043f, 0.794229f, 0.39623f, 0.460653f, 0.649156f, 0.396474f,
+ 0.649157f, 0.460653f, 0.39623f, 0.794229f, 0.239043f, 0.395595f,
+ 0.886771f, 0f, 0.395111f, 0.918633f, 0.937749f, 0.347314f, 0f,
+ 0.905271f, 0.347757f, 0.244029f, 0.810853f, 0.34834f, 0.470295f,
+ 0.662761f, 0.348563f, 0.662761f, 0.470295f, 0.34834f, 0.810853f,
+ 0.24403f, 0.347757f, 0.90527f, 0f, 0.347314f, 0.937749f, 0.96234f,
+ 0.271848f, 0f, 0.929073f, 0.272213f, 0.250446f, 0.832247f,
+ 0.272693f, 0.482704f, 0.680271f, 0.272877f, 0.680271f, 0.482704f,
+ 0.272693f, 0.832247f, 0.250446f, 0.272213f, 0.929073f, 0f,
+ 0.271848f, 0.96234f, 0.987204f, 0.15946f, 0f, 0.953145f, 0.159686f,
+ 0.256935f, 0.85389f, 0.159982f, 0.495256f, 0.697986f, 0.160096f,
+ 0.697986f, 0.495256f, 0.159982f, 0.853889f, 0.256935f, 0.159686f,
+ 0.953145f, 0f, 0.15946f, 0.987204f, 1f, 0f, 0f, 0.965535f,
+ -2.69333e-008f, 0.260275f, 0.865031f, -2.6582e-008f, 0.501718f,
+ 0.707107f, -1.58051e-008f, 0.707107f, 0.501718f, -5.72888e-009f,
+ 0.865031f, 0.260275f, -7.99313e-010f, 0.965535f, 0f, 0f, 1f, 0f,
+ 0.421501f, 0.906828f, -0.235963f, 0.422003f, 0.875348f, -0.234928f,
+ 0.430442f, 0.871509f, -0.4547f, 0.422664f, 0.783966f, -0.4527f,
+ 0.43111f, 0.780517f, -0.640758f, 0.422917f, 0.640758f, -0.783966f,
+ 0.422664f, 0.454701f, -0.780517f, 0.43111f, 0.4527f, -0.875348f,
+ 0.422003f, 0.235964f, -0.871509f, 0.430442f, 0.234929f, -0.906828f,
+ 0.421501f, 0f, 0f, 0.395111f, 0.918633f, -0.239043f, 0.395595f,
+ 0.886771f, -0.460653f, 0.39623f, 0.794229f, -0.649157f, 0.396474f,
+ 0.649157f, -0.794229f, 0.39623f, 0.460653f, -0.886771f, 0.395595f,
+ 0.239043f, -0.918633f, 0.395111f, 0f, -0.244029f, 0.347757f,
+ 0.905271f, -0.470295f, 0.34834f, 0.810853f, -0.662761f, 0.348563f,
+ 0.662761f, -0.810853f, 0.34834f, 0.470295f, -0.90527f, 0.347757f,
+ 0.24403f, -0.937749f, 0.347314f, 0f, 0f, 0.271848f, 0.96234f,
+ -0.250446f, 0.272213f, 0.929073f, -0.482703f, 0.272693f, 0.832248f,
+ -0.680271f, 0.272877f, 0.680271f, -0.832247f, 0.272693f, 0.482704f,
+ -0.929073f, 0.272213f, 0.250446f, -0.96234f, 0.271848f, 0f, 0f,
+ 0.159461f, 0.987204f, -0.256935f, 0.159686f, 0.953145f, -0.495256f,
+ 0.159983f, 0.853889f, -0.697986f, 0.160096f, 0.697986f, -0.853889f,
+ 0.159982f, 0.495256f, -0.953145f, 0.159686f, 0.256935f, -0.987204f,
+ 0.159461f, 0f, -0.260274f, -7.9931e-010f, 0.965535f, -0.501718f,
+ -5.72887e-009f, 0.865031f, -0.707107f, -1.58051e-008f, 0.707107f,
+ -0.865031f, -2.6582e-008f, 0.501718f, -0.965535f, -2.69333e-008f,
+ 0.260275f, 0.410365f, 0.911921f, 0f, -0.906828f, 0.421501f, 0f,
+ -0.875348f, 0.422003f, -0.235963f, -0.871509f, 0.430442f,
+ -0.234928f, -0.783966f, 0.422664f, -0.4547f, -0.780517f, 0.43111f,
+ -0.4527f, -0.640758f, 0.422917f, -0.640758f, -0.454701f, 0.422664f,
+ -0.783966f, -0.4527f, 0.43111f, -0.780517f, -0.235964f, 0.422003f,
+ -0.875348f, -0.234929f, 0.430442f, -0.871509f, 0f, 0.421501f,
+ -0.906828f, -0.918633f, 0.395111f, 0f, -0.886771f, 0.395595f,
+ -0.239043f, -0.794229f, 0.39623f, -0.460653f, -0.649157f,
+ 0.396474f, -0.649156f, -0.460653f, 0.39623f, -0.794229f,
+ -0.239043f, 0.395595f, -0.886771f, 0f, 0.395111f, -0.918633f,
+ -0.905271f, 0.347757f, -0.244029f, -0.810853f, 0.34834f,
+ -0.470295f, -0.662761f, 0.348563f, -0.662761f, -0.470295f,
+ 0.34834f, -0.810853f, -0.24403f, 0.347757f, -0.90527f, 0f,
+ 0.347314f, -0.937749f, -0.96234f, 0.271847f, 0f, -0.929073f,
+ 0.272213f, -0.250446f, -0.832248f, 0.272693f, -0.482703f,
+ -0.680271f, 0.272877f, -0.680271f, -0.482704f, 0.272693f,
+ -0.832247f, -0.250446f, 0.272213f, -0.929073f, 0f, 0.271847f,
+ -0.96234f, -0.987204f, 0.15946f, 0f, -0.953145f, 0.159685f,
+ -0.256935f, -0.85389f, 0.159982f, -0.495256f, -0.697986f,
+ 0.160096f, -0.697986f, -0.495256f, 0.159982f, -0.853889f,
+ -0.256935f, 0.159685f, -0.953145f, 0f, 0.15946f, -0.987204f,
+ -0.965535f, 2.69333e-008f, -0.260274f, -0.865031f, 2.6582e-008f,
+ -0.501718f, -0.707107f, 1.58051e-008f, -0.707107f, -0.501718f,
+ 5.72888e-009f, -0.865031f, -0.260275f, 7.99313e-010f, -0.965535f,
+ 0f, 0f, -1f, 0.235963f, 0.422003f, -0.875348f, 0.234928f,
+ 0.430442f, -0.871509f, 0.4547f, 0.422664f, -0.783966f, 0.4527f,
+ 0.43111f, -0.780517f, 0.640758f, 0.422917f, -0.640758f, 0.783966f,
+ 0.422664f, -0.4547f, 0.780517f, 0.43111f, -0.4527f, 0.875348f,
+ 0.422003f, -0.235964f, 0.871509f, 0.430442f, -0.234929f, 0.906828f,
+ 0.421501f, 0f, 0.239043f, 0.395595f, -0.886771f, 0.460653f,
+ 0.39623f, -0.794229f, 0.649157f, 0.396474f, -0.649156f, 0.794229f,
+ 0.39623f, -0.460653f, 0.886771f, 0.395595f, -0.239043f, 0.918633f,
+ 0.395111f, 0f, 0.244029f, 0.347757f, -0.905271f, 0.470295f,
+ 0.34834f, -0.810853f, 0.662761f, 0.348563f, -0.662761f, 0.810853f,
+ 0.34834f, -0.470295f, 0.90527f, 0.347757f, -0.24403f, 0.250446f,
+ 0.272213f, -0.929073f, 0.482704f, 0.272693f, -0.832247f, 0.680271f,
+ 0.272877f, -0.680271f, 0.832247f, 0.272693f, -0.482704f, 0.929073f,
+ 0.272213f, -0.250446f, 0.96234f, 0.271847f, 0f, 0.256935f,
+ 0.159685f, -0.953145f, 0.495256f, 0.159982f, -0.85389f, 0.697986f,
+ 0.160096f, -0.697986f, 0.853889f, 0.159982f, -0.495256f, 0.953145f,
+ 0.159685f, -0.256935f, 0.987204f, 0.15946f, 0f, 0.260274f,
+ 7.9931e-010f, -0.965535f, 0.501718f, 5.72887e-009f, -0.865031f,
+ 0.707107f, 1.58051e-008f, -0.707107f, 0.865031f, 2.6582e-008f,
+ -0.501718f, 0.965535f, 2.69333e-008f, -0.260275f, 0.938373f,
+ -0.345625f, -3.10672e-010f, 0.905874f, -0.346066f, 0.244192f,
+ 0.811396f, -0.346647f, 0.470609f, 0.663205f, -0.346869f, 0.663205f,
+ 0.47061f, -0.346647f, 0.811395f, 0.244192f, -0.346066f, 0.905874f,
+ 0f, -0.345625f, 0.938373f, 0.811257f, -0.584689f, -4.41262e-009f,
+ 0.782908f, -0.585247f, 0.211045f, 0.700957f, -0.58598f, 0.406555f,
+ 0.572843f, -0.586261f, 0.572843f, 0.406555f, -0.58598f, 0.700957f,
+ 0.211045f, -0.585247f, 0.782908f, 0f, -0.584689f, 0.811257f,
+ 0.6981f, -0.716f, -1.94916e-008f, 0.673539f, -0.716506f, 0.181563f,
+ 0.602839f, -0.717169f, 0.349647f, 0.492597f, -0.717423f, 0.492597f,
+ 0.349647f, -0.717169f, 0.602839f, 0.181563f, -0.716506f, 0.673539f,
+ 0f, -0.716f, 0.6981f, 0.636383f, -0.771373f, -5.3452e-008f,
+ 0.61392f, -0.771826f, 0.165491f, 0.549392f, -0.772419f, 0.318648f,
+ 0.448897f, -0.772647f, 0.448897f, 0.318648f, -0.772419f, 0.549392f,
+ 0.165492f, -0.771826f, 0.61392f, 0f, -0.771373f, 0.636383f,
+ 0.675056f, -0.737767f, -1.05865e-007f, 0.651275f, -0.738254f,
+ 0.175561f, 0.582878f, -0.738893f, 0.338069f, 0.476275f, -0.739138f,
+ 0.476275f, 0.338069f, -0.738893f, 0.582878f, 0.175561f, -0.738254f,
+ 0.651275f, 0f, -0.737767f, 0.675056f, 1f, 0f, 0f, 0.965535f,
+ -2.69332e-008f, 0.260274f, 0.865031f, -2.65819e-008f, 0.501718f,
+ 0.707107f, -1.5805e-008f, 0.707107f, 0.501718f, -5.72887e-009f,
+ 0.865031f, 0.260275f, -7.99311e-010f, 0.965535f, 0f, 0f, 1f,
+ -0.244192f, -0.346066f, 0.905874f, -0.470609f, -0.346647f,
+ 0.811396f, -0.663205f, -0.346869f, 0.663205f, -0.811395f,
+ -0.346647f, 0.47061f, -0.905874f, -0.346066f, 0.244193f,
+ -0.938373f, -0.345625f, -3.10672e-010f, -0.211045f, -0.585247f,
+ 0.782908f, -0.406555f, -0.58598f, 0.700957f, -0.572843f,
+ -0.586261f, 0.572843f, -0.700957f, -0.58598f, 0.406555f,
+ -0.782908f, -0.585247f, 0.211045f, -0.811257f, -0.584689f,
+ -4.41262e-009f, -0.181563f, -0.716506f, 0.673539f, -0.349647f,
+ -0.717169f, 0.602839f, -0.492597f, -0.717423f, 0.492597f,
+ -0.602839f, -0.717169f, 0.349647f, -0.673539f, -0.716506f,
+ 0.181563f, -0.6981f, -0.716f, -1.94916e-008f, -0.165491f,
+ -0.771826f, 0.61392f, -0.318648f, -0.772419f, 0.549393f,
+ -0.448897f, -0.772647f, 0.448897f, -0.549392f, -0.772419f,
+ 0.318648f, -0.61392f, -0.771826f, 0.165492f, -0.636383f,
+ -0.771373f, -5.3452e-008f, -0.175561f, -0.738254f, 0.651275f,
+ -0.338069f, -0.738893f, 0.582878f, -0.476275f, -0.739138f,
+ 0.476275f, -0.582878f, -0.738893f, 0.338069f, -0.651275f,
+ -0.738254f, 0.175561f, -0.675056f, -0.737767f, -1.05865e-007f,
+ -0.260274f, -7.99309e-010f, 0.965535f, -0.501718f, -5.72886e-009f,
+ 0.865031f, -0.707107f, -1.5805e-008f, 0.707107f, -0.865031f,
+ -2.65819e-008f, 0.501718f, -0.965535f, -2.69333e-008f, 0.260275f,
+ -1f, 0f, 0f, -0.905874f, -0.346066f, -0.244192f, -0.811396f,
+ -0.346647f, -0.470609f, -0.663205f, -0.346869f, -0.663205f,
+ -0.47061f, -0.346647f, -0.811395f, -0.244192f, -0.346066f,
+ -0.905874f, 0f, -0.345625f, -0.938373f, -0.782908f, -0.585247f,
+ -0.211045f, -0.700957f, -0.58598f, -0.406555f, -0.572843f,
+ -0.586261f, -0.572843f, -0.406555f, -0.58598f, -0.700957f,
+ -0.211045f, -0.585247f, -0.782908f, 0f, -0.584689f, -0.811257f,
+ -0.673539f, -0.716506f, -0.181563f, -0.602839f, -0.717169f,
+ -0.349647f, -0.492597f, -0.717423f, -0.492597f, -0.349647f,
+ -0.717169f, -0.602839f, -0.181563f, -0.716506f, -0.673539f, 0f,
+ -0.716f, -0.6981f, -0.61392f, -0.771826f, -0.165491f, -0.549392f,
+ -0.77242f, -0.318647f, -0.448897f, -0.772647f, -0.448897f,
+ -0.318648f, -0.77242f, -0.549392f, -0.165492f, -0.771826f,
+ -0.61392f, 0f, -0.771373f, -0.636383f, -0.651275f, -0.738254f,
+ -0.175561f, -0.582877f, -0.738894f, -0.338069f, -0.476274f,
+ -0.739138f, -0.476274f, -0.338069f, -0.738894f, -0.582877f,
+ -0.175561f, -0.738255f, -0.651275f, 0f, -0.737767f, -0.675055f,
+ -0.965535f, 2.69333e-008f, -0.260274f, -0.865031f, 2.6582e-008f,
+ -0.501718f, -0.707107f, 1.58051e-008f, -0.707107f, -0.501718f,
+ 5.7289e-009f, -0.865031f, -0.260275f, 7.99315e-010f, -0.965535f,
+ 0f, 0f, -1f, 0.244192f, -0.346066f, -0.905874f, 0.470609f,
+ -0.346647f, -0.811396f, 0.663205f, -0.346869f, -0.663205f,
+ 0.811395f, -0.346647f, -0.47061f, 0.905874f, -0.346066f,
+ -0.244192f, 0.211045f, -0.585247f, -0.782908f, 0.406555f,
+ -0.58598f, -0.700957f, 0.572843f, -0.586261f, -0.572843f,
+ 0.700957f, -0.58598f, -0.406555f, 0.782908f, -0.585247f,
+ -0.211045f, 0.181563f, -0.716506f, -0.673539f, 0.349647f,
+ -0.717169f, -0.602839f, 0.492597f, -0.717423f, -0.492597f,
+ 0.602839f, -0.717169f, -0.349647f, 0.673539f, -0.716506f,
+ -0.181563f, 0.165491f, -0.771826f, -0.61392f, 0.318647f, -0.77242f,
+ -0.549392f, 0.448897f, -0.772647f, -0.448897f, 0.549392f,
+ -0.77242f, -0.318648f, 0.61392f, -0.771826f, -0.165492f, 0.175561f,
+ -0.738255f, -0.651275f, 0.338069f, -0.738894f, -0.582877f,
+ 0.476274f, -0.739138f, -0.476274f, 0.582877f, -0.738894f,
+ -0.338069f, 0.651275f, -0.738254f, -0.175561f, 0.260274f,
+ 7.99314e-010f, -0.965535f, 0.501718f, 5.72889e-009f, -0.865031f,
+ 0.707107f, 1.58051e-008f, -0.707107f, 0.865031f, 2.6582e-008f,
+ -0.501718f, 0.965535f, 2.69333e-008f, -0.260275f, 0.0104645f,
+ -0.999945f, 0f, 0f, -1f, 0f, 0.0104255f, -0.954681f, 0.297447f,
+ 2.56825e-008f, -0.95448f, 0.298276f, 0.00846391f, -0.708083f,
+ 0.706078f, 1.14879e-007f, -0.707106f, 0.707108f, -2.9238e-009f,
+ -8.98486e-008f, 1f, 8.16344e-015f, -8.94074e-008f, 1f,
+ -0.00997561f, 0.707961f, 0.706181f, 5.80084e-008f, 0.707107f,
+ 0.707107f, -0.0140841f, 0.95459f, 0.297589f, 1.94189e-007f,
+ 0.95448f, 0.298275f, -0.0149982f, 0.999888f, 0f, 0f, 1f, 0f,
+ 0.0510697f, -0.998695f, 0f, 0.0510028f, -0.953615f, 0.296676f,
+ 0.0415993f, -0.706917f, 0.706072f, -2.78701e-009f, -9.11701e-008f,
+ 1f, -0.0493858f, 0.704244f, 0.708239f, -0.0701018f, 0.951466f,
+ 0.299663f, -0.07479f, 0.997199f, 0f, 0.14834f, -0.988936f, 0f,
+ 0.148104f, -0.941964f, 0.30128f, 0.119688f, -0.688399f, 0.715389f,
+ 7.13598e-009f, -8.17051e-008f, 1f, -0.141352f, 0.675015f,
+ 0.724137f, -0.204668f, 0.927128f, 0.313917f, -0.219512f, 0.97561f,
+ 0f, 0.364399f, -0.931243f, 0f, 0.359682f, -0.875088f, 0.323804f,
+ 0.275915f, -0.604128f, 0.747597f, 1.54202e-008f, -6.37972e-008f,
+ 1f, -0.313659f, 0.564289f, 0.763672f, -0.474611f, 0.807244f,
+ 0.350859f, -0.514496f, 0.857493f, 0f, 0.767382f, -0.64119f, 0f,
+ 0.727532f, -0.577566f, 0.37029f, 0.497151f, -0.35353f, 0.792374f,
+ 1.10972e-008f, -5.53164e-008f, 1f, -0.519904f, 0.300684f,
+ 0.799556f, -0.810111f, 0.441475f, 0.385771f, -0.882353f, 0.470588f,
+ 0f, 1f, 0f, 0f, 0.923077f, -3.76483e-008f, 0.384616f, 0.599999f,
+ -4.20741e-008f, 0.8f, 0f, -4.47037e-008f, 1f, -0.600001f,
+ -5.17421e-008f, 0.799999f, -0.923077f, -4.14964e-008f, 0.384614f,
+ -1f, 0f, 0f, -0.014084f, 0.95459f, -0.297589f, 5.67983e-008f,
+ 0.95448f, -0.298275f, -0.00997558f, 0.707961f, -0.706182f,
+ -4.84905e-008f, 0.707107f, -0.707107f, 5.84773e-010f,
+ 8.94956e-008f, -1f, -8.16344e-015f, 8.94074e-008f, -1f, 0.0084637f,
+ -0.708085f, -0.706076f, 3.66172e-008f, -0.707108f, -0.707106f,
+ 0.0104256f, -0.954682f, -0.297445f, 7.36826e-009f, -0.95448f,
+ -0.298274f, 0.0104646f, -0.999945f, 0f, -0.07479f, 0.997199f, 0f,
+ -0.0701018f, 0.951466f, -0.299663f, -0.0493858f, 0.704243f,
+ -0.708239f, -8.36107e-009f, 8.41192e-008f, -1f, 0.0415994f,
+ -0.706919f, -0.70607f, 0.0510028f, -0.953616f, -0.296674f,
+ 0.0510696f, -0.998695f, 0f, -0.204668f, 0.927128f, -0.313917f,
+ -0.141352f, 0.675015f, -0.724137f, -7.13598e-009f, 8.17051e-008f,
+ -1f, 0.119688f, -0.688401f, -0.715387f, 0.148104f, -0.941964f,
+ -0.301278f, -0.514495f, 0.857493f, 0f, -0.47461f, 0.807244f,
+ -0.350859f, -0.313658f, 0.564289f, -0.763673f, -9.25216e-009f,
+ 7.40412e-008f, -1f, 0.275916f, -0.60413f, -0.747595f, 0.359681f,
+ -0.875089f, -0.323802f, 0.364399f, -0.931243f, 0f, -0.882353f,
+ 0.470589f, 0f, -0.810111f, 0.441477f, -0.385771f, -0.519903f,
+ 0.300684f, -0.799556f, -1.01322e-008f, 5.82809e-008f, -1f,
+ 0.497153f, -0.353532f, -0.792373f, 0.727532f, -0.577567f,
+ -0.370288f, 0.767381f, -0.641191f, 0f, -0.923077f, 4.14963e-008f,
+ -0.384615f, -0.6f, 5.17421e-008f, -0.8f, 0f, 4.47037e-008f, -1f,
+ 0.600002f, 4.2074e-008f, -0.799999f, 0.923078f, 3.76482e-008f,
+ -0.384614f, 0.972045f, 0.234794f, 0f, 0.895972f, 0.219226f,
+ 0.38623f, 0.57987f, 0.145888f, 0.801541f, -1.56774e-008f,
+ -4.06593e-008f, 1f, -0.577708f, -0.153129f, 0.801751f, -0.890548f,
+ -0.23959f, 0.386678f, -0.965311f, -0.261102f, 0f, 0.913811f,
+ 0.406139f, 0f, 0.842942f, 0.38439f, 0.376421f, 0.548194f,
+ 0.264706f, 0.793356f, -1.8594e-008f, -5.87553e-008f, 1f,
+ -0.534196f, -0.289235f, 0.794341f, -0.807437f, -0.452559f,
+ 0.378465f, -0.869653f, -0.493664f, 0f, 0.83205f, 0.5547f, 0f,
+ 0.772293f, 0.530527f, 0.349435f, 0.515845f, 0.379263f, 0.768156f,
+ -2.48164e-008f, -6.43889e-008f, 1f, -0.486434f, -0.411777f,
+ 0.770598f, -0.700515f, -0.619694f, 0.353919f, -0.743581f,
+ -0.668646f, 0f, 0.722373f, 0.691503f, 0f, 0.676612f, 0.666255f,
+ 0.31353f, 0.471519f, 0.495195f, 0.729693f, -2.71577e-008f,
+ -7.53755e-008f, 1f, -0.433172f, -0.52092f, 0.73553f, -0.589822f,
+ -0.740319f, 0.322549f, -0.617031f, -0.786939f, 0f, 0.580972f,
+ 0.813923f, 0f, 0.548733f, 0.784249f, 0.289562f, 0.396971f,
+ 0.593617f, 0.700024f, -2.572e-008f, -8.77449e-008f, 1f, -0.367048f,
+ -0.602921f, 0.708352f, -0.485318f, -0.820874f, 0.301051f,
+ -0.504835f, -0.863216f, 0f, 0.390503f, 0.867784f, 0.307341f,
+ 0.285351f, 0.634113f, 0.718663f, -2.36665e-008f, -9.72958e-008f,
+ 1f, -0.285351f, -0.634114f, 0.718661f, -0.390503f, -0.867784f,
+ 0.30734f, -0.410365f, -0.911921f, 0f, -0.890548f, -0.23959f,
+ -0.386679f, -0.577707f, -0.153129f, -0.801752f, 1.08654e-008f,
+ 5.5622e-008f, -1f, 0.579872f, 0.145888f, -0.801539f, 0.895973f,
+ 0.219227f, -0.386228f, -0.807437f, -0.452558f, -0.378466f,
+ -0.534196f, -0.289235f, -0.794341f, 2.27516e-008f, 5.19016e-008f,
+ -1f, 0.548196f, 0.264707f, -0.793355f, 0.842943f, 0.384391f,
+ -0.376419f, -0.700515f, -0.619694f, -0.353919f, -0.486433f,
+ -0.411777f, -0.770599f, 2.48164e-008f, 6.43889e-008f, -1f,
+ 0.515847f, 0.379264f, -0.768154f, 0.772293f, 0.530528f, -0.349433f,
+ -0.589822f, -0.740319f, -0.322549f, -0.433171f, -0.520919f,
+ -0.735531f, 2.71577e-008f, 7.53755e-008f, -1f, 0.47152f, 0.495196f,
+ -0.729691f, 0.676612f, 0.666255f, -0.313529f, -0.485318f,
+ -0.820874f, -0.301052f, -0.367047f, -0.60292f, -0.708353f,
+ 2.88747e-008f, 8.75411e-008f, -1f, 0.396972f, 0.593619f,
+ -0.700022f, 0.548733f, 0.784249f, -0.289561f, -0.390503f,
+ -0.867784f, -0.30734f, -0.285351f, -0.634113f, -0.718662f,
+ 2.36665e-008f, 9.72958e-008f, -1f, 0.285351f, 0.634114f,
+ -0.718661f, 0.390503f, 0.867785f, -0.307339f, -0.333935f,
+ 0.942596f, 0f, 0f, 1f, 0f, -0.291732f, 0.855995f, 0.426808f,
+ -0.0157731f, 0.886804f, 0.461877f, -0.135103f, 0.53438f, 0.834377f,
+ -0.0291362f, 0.514277f, 0.857129f, 0.110195f, 0.0292375f, 0.99348f,
+ 4.3732e-009f, -8.94073e-008f, 1f, 0.348602f, -0.464039f, 0.814337f,
+ 0.0673463f, -0.513328f, 0.855546f, 0.492146f, -0.767551f,
+ 0.410679f, 0.134339f, -0.878875f, 0.457746f, 0.528678f, -0.848822f,
+ 0f, 0.158678f, -0.98733f, 0f, -0.731055f, 0.682318f, 0f, -0.64585f,
+ 0.656206f, 0.390219f, -0.31251f, 0.484842f, 0.816864f, 0.215359f,
+ 0.108813f, 0.970454f, 0.627608f, -0.260237f, 0.733747f, 0.813963f,
+ -0.465103f, 0.348055f, 0.854063f, -0.52017f, 0f, -0.920582f,
+ 0.39055f, 0f, -0.835236f, 0.412221f, 0.363943f, -0.451322f,
+ 0.38916f, 0.803034f, 0.214084f, 0.180281f, 0.960035f, 0.705425f,
+ -0.0805069f, 0.704198f, 0.913262f, -0.239978f, 0.329185f,
+ 0.957826f, -0.287348f, 0f, -0.948683f, 0.316228f, 0f, -0.842821f,
+ 0.34961f, 0.409177f, -0.452672f, 0.347535f, 0.821162f, 0.113546f,
+ 0.191909f, 0.974822f, 0.60461f, -0.0547987f, 0.794634f, 0.880145f,
+ -0.253261f, 0.401503f, 0.947589f, -0.319493f, 0f, -0.874591f,
+ 0.484861f, 0f, -0.723794f, 0.476715f, 0.498864f, -0.365377f,
+ 0.375544f, 0.851743f, 0.0260102f, 0.151516f, 0.988113f, 0.417243f,
+ -0.185123f, 0.88974f, 0.70819f, -0.506054f, 0.492318f, 0.787582f,
+ -0.61621f, 0f, -0.600001f, 0.799999f, 0f, -0.497164f, 0.711095f,
+ 0.497165f, -0.267367f, 0.443286f, 0.855577f, 0f, -4.47006e-008f,
+ 1f, 0.250514f, -0.54278f, 0.801644f, 0.366221f, -0.855433f,
+ 0.36622f, 0.384615f, -0.923077f, 0f, 0.528678f, -0.848822f, 0f,
+ 0.492146f, -0.767551f, -0.41068f, 0.134339f, -0.878875f,
+ -0.457747f, 0.348602f, -0.464038f, -0.814337f, 0.0673462f,
+ -0.513327f, -0.855546f, 0.110195f, 0.0292377f, -0.99348f,
+ -4.3732e-009f, 8.94073e-008f, -1f, -0.135104f, 0.534382f,
+ -0.834376f, -0.0291362f, 0.514278f, -0.857128f, -0.291732f,
+ 0.855996f, -0.426806f, -0.0157731f, 0.886804f, -0.461876f,
+ -0.333935f, 0.942596f, 0f, 0.854063f, -0.52017f, 0f, 0.813963f,
+ -0.465103f, -0.348056f, 0.627607f, -0.260237f, -0.733748f,
+ 0.215359f, 0.108813f, -0.970454f, -0.312512f, 0.484843f,
+ -0.816862f, -0.645851f, 0.656206f, -0.390218f, 0.913262f,
+ -0.239977f, -0.329185f, 0.705424f, -0.0805064f, -0.704199f,
+ 0.214084f, 0.180281f, -0.960035f, -0.451324f, 0.38916f, -0.803032f,
+ -0.835237f, 0.412221f, -0.363941f, 0.947589f, -0.319493f, 0f,
+ 0.880144f, -0.253261f, -0.401503f, 0.60461f, -0.0547981f,
+ -0.794635f, 0.113546f, 0.191909f, -0.974822f, -0.452675f,
+ 0.347535f, -0.821161f, -0.842822f, 0.34961f, -0.409175f,
+ -0.948683f, 0.316228f, 0f, 0.787582f, -0.61621f, 0f, 0.70819f,
+ -0.506053f, -0.492318f, 0.417243f, -0.185122f, -0.88974f,
+ 0.0260103f, 0.151516f, -0.988113f, -0.365379f, 0.375545f,
+ -0.851742f, -0.723796f, 0.476715f, -0.498861f, -0.874591f,
+ 0.484861f, 0f, 0.36622f, -0.855433f, -0.36622f, 0.250514f,
+ -0.54278f, -0.801644f, 0f, 4.47006e-008f, -1f, -0.267368f,
+ 0.443289f, -0.855575f, -0.497165f, 0.711096f, -0.497162f,
+ -0.467888f, 0.883788f, 0f, -0.387053f, 0.824948f, 0.411887f,
+ -0.215548f, 0.655025f, 0.72421f, -0.00489616f, 0.343259f,
+ 0.939228f, 0.269127f, -0.23781f, 0.933283f, 0.442187f, -0.761825f,
+ 0.473385f, 0.463425f, -0.886136f, 0f, -0.306008f, 0.952029f, 0f,
+ -0.253998f, 0.928137f, 0.272115f, -0.14959f, 0.863647f, 0.481391f,
+ -0.0195232f, 0.746219f, 0.665414f, 0.218115f, 0.441118f, 0.870541f,
+ 0.612385f, -0.337374f, 0.714957f, 0.694135f, -0.719844f, 0f, 0f,
+ 1f, 0f, -0.0182315f, 0.999613f, -0.0210205f, -0.0369304f,
+ 0.999286f, 0.00796664f, -0.0348909f, 0.997622f, 0.059444f,
+ -0.00787177f, 0.994104f, 0.108145f, 0.0539575f, 0.992309f,
+ 0.111405f, 0.106533f, 0.994309f, 0f, 0.913813f, 0.406135f, 0f,
+ 0.507716f, 0.52532f, -0.682835f, 0.148478f, 0.676273f, -0.721533f,
+ -0.0300304f, 0.787464f, -0.615629f, -0.144372f, 0.876436f,
+ -0.459366f, -0.223743f, 0.943891f, -0.242919f, -0.253109f,
+ 0.967438f, 0f, 0.789351f, -0.613942f, 0f, 0.577415f, -0.400033f,
+ -0.711734f, 0.241288f, -0.0136421f, -0.970358f, -0.0103803f,
+ 0.344669f, -0.938667f, -0.199105f, 0.663018f, -0.72164f,
+ -0.316295f, 0.875642f, -0.364979f, -0.349987f, 0.936755f, 0f, 0.6f,
+ -0.8f, 0f, 0.483629f, -0.690899f, -0.537366f, 0.247465f, -0.40568f,
+ -0.879878f, 0f, 4.47028e-008f, -1f, -0.236617f, 0.486025f,
+ -0.841304f, -0.378646f, 0.824393f, -0.420717f, -0.410365f,
+ 0.911921f, 0f, 0.442188f, -0.761824f, -0.473386f, 0.269127f,
+ -0.237807f, -0.933284f, -0.0048962f, 0.343262f, -0.939227f,
+ -0.215548f, 0.655028f, -0.724208f, -0.387053f, 0.82495f,
+ -0.411884f, 0.612385f, -0.337369f, -0.714959f, 0.218114f,
+ 0.441124f, -0.870538f, -0.0195232f, 0.746221f, -0.665412f,
+ -0.14959f, 0.863648f, -0.481389f, -0.253997f, 0.928138f,
+ -0.272112f, 0.0539562f, 0.992309f, -0.111404f, -0.00787199f,
+ 0.994104f, -0.108144f, -0.0348909f, 0.997622f, -0.0594425f,
+ -0.0369306f, 0.999286f, -0.00796709f, -0.0182318f, 0.999613f,
+ 0.0210199f, -0.223743f, 0.943891f, 0.242919f, -0.144372f,
+ 0.876437f, 0.459364f, -0.0300305f, 0.787466f, 0.615626f, 0.148478f,
+ 0.676276f, 0.721529f, 0.507717f, 0.525323f, 0.682832f, -0.316294f,
+ 0.875642f, 0.364979f, -0.199104f, 0.663019f, 0.72164f, -0.0103804f,
+ 0.344672f, 0.938666f, 0.241289f, -0.0136406f, 0.970357f, 0.577417f,
+ -0.400034f, 0.711732f, -0.378646f, 0.824393f, 0.420718f,
+ -0.236617f, 0.486023f, 0.841305f, 0f, -4.47028e-008f, 1f,
+ 0.247466f, -0.405682f, 0.879877f, 0.48363f, -0.690899f, 0.537365f,
+ 0.249998f, 0.968246f, 0f, 0.001257f, 0.999999f, 0f, 0.241077f,
+ 0.968356f, 0.0645611f, 0.00120899f, 0.999999f, 0.000335259f,
+ 0.215548f, 0.968509f, 0.124615f, 0.00108352f, 0.999999f,
+ 0.000626407f, 0.175886f, 0.96857f, 0.175886f, 0.124616f, 0.968509f,
+ 0.215548f, 0.0645611f, 0.968356f, 0.241077f, 0f, 0.968246f,
+ 0.249998f, 0.989204f, 0.146548f, 0f, 0.955495f, 0.146755f,
+ 0.255913f, 0.856312f, 0.147029f, 0.495088f, 0.699411f, 0.147135f,
+ 0.699411f, 0.495089f, 0.147029f, 0.856312f, 0.255914f, 0.146754f,
+ 0.955495f, 0f, 0.146548f, 0.989204f, 0.780869f, -0.624695f, 0f,
+ 0.753687f, -0.625441f, 0.201937f, 0.674735f, -0.626493f, 0.390178f,
+ 0.550895f, -0.62692f, 0.550896f, 0.390179f, -0.626493f, 0.674734f,
+ 0.201938f, -0.625441f, 0.753688f, 0f, -0.624695f, 0.780869f,
+ 0.747409f, -0.664364f, 0f, 0.721243f, -0.665116f, 0.193465f,
+ 0.645526f, -0.66618f, 0.373497f, 0.527081f, -0.666611f, 0.527081f,
+ 0.373498f, -0.66618f, 0.645526f, 0.193466f, -0.665116f, 0.721243f,
+ 0f, -0.664364f, 0.747409f, 0.950775f, -0.309882f, 0f, 0.917897f,
+ -0.310647f, 0.246906f, 0.822132f, -0.311772f, 0.476337f, 0.671753f,
+ -0.312241f, 0.671754f, 0.476338f, -0.311771f, 0.822132f, 0.246907f,
+ -0.310647f, 0.917897f, 0f, -0.309882f, 0.950775f, 0.6f, 0.8f, 0f,
+ 0.578783f, 0.800417f, 0.15602f, 0.517905f, 0.800964f, 0.300385f,
+ 0.423156f, 0.801173f, 0.423156f, 0.300386f, 0.800964f, 0.517904f,
+ 0.156021f, 0.800416f, 0.578784f, 0f, 0.799999f, 0.600001f, 0f,
+ 0.968246f, 0.249998f, -0.064561f, 0.968356f, 0.241077f, -0.124615f,
+ 0.968509f, 0.215548f, -0.175885f, 0.968571f, 0.175885f, -0.215548f,
+ 0.968509f, 0.124616f, -0.241076f, 0.968356f, 0.064561f, -0.249998f,
+ 0.968246f, 0f, 0f, 0.146549f, 0.989203f, -0.255913f, 0.146755f,
+ 0.955495f, -0.495088f, 0.14703f, 0.856312f, -0.699411f, 0.147136f,
+ 0.699411f, -0.856311f, 0.14703f, 0.495089f, -0.955495f, 0.146755f,
+ 0.255914f, -0.989203f, 0.146549f, 0f, -0.201937f, -0.625441f,
+ 0.753688f, -0.390178f, -0.626493f, 0.674735f, -0.550895f,
+ -0.62692f, 0.550896f, -0.674734f, -0.626493f, 0.390179f,
+ -0.753687f, -0.625441f, 0.201939f, -0.780869f, -0.624695f, 0f, 0f,
+ -0.664364f, 0.747409f, -0.193465f, -0.665116f, 0.721244f,
+ -0.373497f, -0.66618f, 0.645527f, -0.527081f, -0.666611f,
+ 0.527081f, -0.645526f, -0.66618f, 0.373498f, -0.721243f,
+ -0.665116f, 0.193466f, -0.747409f, -0.664364f, 0f, 0f, -0.309883f,
+ 0.950775f, -0.246906f, -0.310648f, 0.917897f, -0.476336f,
+ -0.311773f, 0.822132f, -0.671753f, -0.312242f, 0.671753f,
+ -0.822131f, -0.311773f, 0.476338f, -0.917897f, -0.310648f,
+ 0.246907f, -0.950775f, -0.309883f, 0f, -0.15602f, 0.800417f,
+ 0.578784f, -0.300385f, 0.800964f, 0.517905f, -0.423156f, 0.801173f,
+ 0.423156f, -0.517904f, 0.800964f, 0.300386f, -0.578783f, 0.800417f,
+ 0.15602f, -0.6f, 0.8f, 0f, -0.249998f, 0.968246f, 0f, -0.241077f,
+ 0.968356f, -0.064561f, -0.215548f, 0.968509f, -0.124615f,
+ -0.175885f, 0.968571f, -0.175885f, -0.124616f, 0.968509f,
+ -0.215548f, -0.064561f, 0.968356f, -0.241077f, 0f, 0.968246f,
+ -0.249998f, -0.989204f, 0.146547f, 0f, -0.955496f, 0.146753f,
+ -0.255912f, -0.856312f, 0.147028f, -0.495088f, -0.699411f,
+ 0.147134f, -0.699411f, -0.495089f, 0.147028f, -0.856312f,
+ -0.255914f, 0.146753f, -0.955495f, 0f, 0.146547f, -0.989204f,
+ -0.753688f, -0.625441f, -0.201937f, -0.674735f, -0.626494f,
+ -0.390178f, -0.550896f, -0.62692f, -0.550895f, -0.390179f,
+ -0.626494f, -0.674734f, -0.201938f, -0.625441f, -0.753687f, 0f,
+ -0.624695f, -0.780869f, -0.747409f, -0.664364f, 0f, -0.721244f,
+ -0.665116f, -0.193465f, -0.645526f, -0.66618f, -0.373497f,
+ -0.527081f, -0.666612f, -0.527081f, -0.373498f, -0.66618f,
+ -0.645526f, -0.193466f, -0.665116f, -0.721243f, 0f, -0.664364f,
+ -0.747409f, -0.950776f, -0.30988f, 0f, -0.917898f, -0.310645f,
+ -0.246906f, -0.822133f, -0.31177f, -0.476337f, -0.671754f,
+ -0.312239f, -0.671754f, -0.476338f, -0.31177f, -0.822132f,
+ -0.246907f, -0.310646f, -0.917898f, 0f, -0.309881f, -0.950775f,
+ -0.578783f, 0.800417f, -0.15602f, -0.517905f, 0.800964f,
+ -0.300384f, -0.423155f, 0.801174f, -0.423155f, -0.300386f,
+ 0.800964f, -0.517904f, -0.15602f, 0.800417f, -0.578783f, 0f, 0.8f,
+ -0.6f, 0.064561f, 0.968356f, -0.241077f, 0.124615f, 0.968509f,
+ -0.215548f, 0.175885f, 0.968571f, -0.175885f, 0.215549f, 0.968509f,
+ -0.124616f, 0.241077f, 0.968356f, -0.064561f, 0.249998f, 0.968246f,
+ 0f, 0.255913f, 0.146754f, -0.955496f, 0.495088f, 0.147028f,
+ -0.856312f, 0.699411f, 0.147134f, -0.699411f, 0.856312f, 0.147028f,
+ -0.495089f, 0.955495f, 0.146753f, -0.255914f, 0.989204f, 0.146547f,
+ 0f, 0.201937f, -0.625441f, -0.753687f, 0.390178f, -0.626494f,
+ -0.674735f, 0.550896f, -0.62692f, -0.550895f, 0.674734f,
+ -0.626494f, -0.390179f, 0.753687f, -0.625441f, -0.201938f,
+ 0.193465f, -0.665116f, -0.721243f, 0.373497f, -0.66618f,
+ -0.645526f, 0.527081f, -0.666612f, -0.527081f, 0.645526f,
+ -0.66618f, -0.373498f, 0.721244f, -0.665116f, -0.193466f,
+ 0.747409f, -0.664364f, 0f, 0.246906f, -0.310646f, -0.917898f,
+ 0.476337f, -0.31177f, -0.822133f, 0.671754f, -0.312239f,
+ -0.671754f, 0.822133f, -0.31177f, -0.476338f, 0.917898f,
+ -0.310646f, -0.246907f, 0.950776f, -0.30988f, 0f, 0.15602f,
+ 0.800417f, -0.578783f, 0.300384f, 0.800964f, -0.517905f, 0.423155f,
+ 0.801174f, -0.423155f, 0.517904f, 0.800964f, -0.300386f, 0.578783f,
+ 0.800417f, -0.15602f, 0.268354f, 0.96332f, 0f, 0.258757f,
+ 0.963421f, 0.0697519f, 0.231413f, 0.963552f, 0.134219f, 0.189037f,
+ 0.963603f, 0.189037f, 0.13422f, 0.963552f, 0.231413f, 0.0697519f,
+ 0.963421f, 0.258756f, 0f, 0.96332f, 0.268354f, 0.168031f,
+ 0.985782f, 0f, 0.162012f, 0.985822f, 0.0436728f, 0.144879f,
+ 0.985875f, 0.0840299f, 0.118345f, 0.985895f, 0.118345f, 0.0840302f,
+ 0.985875f, 0.144879f, 0.0436728f, 0.985822f, 0.162011f, 0f,
+ 0.985782f, 0.168031f, 0.14834f, 0.988936f, 0f, 0.143025f,
+ 0.988968f, 0.0385546f, 0.127899f, 0.989009f, 0.0741814f, 0.104474f,
+ 0.989025f, 0.104474f, 0.0741816f, 0.989009f, 0.127899f, 0.0385547f,
+ 0.988968f, 0.143025f, 0f, 0.988936f, 0.148341f, 0.193633f,
+ 0.981074f, 0f, 0.186698f, 0.981127f, 0.0503274f, 0.166959f,
+ 0.981197f, 0.0968359f, 0.136382f, 0.981224f, 0.136382f, 0.0968361f,
+ 0.981197f, 0.166958f, 0.0503276f, 0.981127f, 0.186699f, 0f,
+ 0.981074f, 0.193633f, 0.390291f, 0.920691f, 0f, 0.376377f,
+ 0.920895f, 0.101458f, 0.336655f, 0.921161f, 0.19526f, 0.275023f,
+ 0.921262f, 0.275023f, 0.19526f, 0.921161f, 0.336655f, 0.101459f,
+ 0.920894f, 0.376377f, 0f, 0.920691f, 0.390291f, 1f, 0f, 0f,
+ 0.965535f, -2.6932e-008f, 0.260274f, 0.865031f, -2.65808e-008f,
+ 0.501718f, 0.707107f, -1.58043e-008f, 0.707107f, 0.501719f,
+ -5.72865e-009f, 0.865031f, 0.260276f, -7.99283e-010f, 0.965534f,
+ 0f, 0f, 1f, -0.0697519f, 0.963421f, 0.258757f, -0.134219f,
+ 0.963552f, 0.231413f, -0.189037f, 0.963603f, 0.189037f, -0.231413f,
+ 0.963552f, 0.13422f, -0.258756f, 0.963421f, 0.0697519f, -0.268354f,
+ 0.96332f, 0f, -0.0436727f, 0.985822f, 0.162012f, -0.0840298f,
+ 0.985875f, 0.144879f, -0.118345f, 0.985895f, 0.118345f, -0.144879f,
+ 0.985875f, 0.0840302f, -0.162011f, 0.985822f, 0.0436728f,
+ -0.168031f, 0.985782f, 0f, -0.0385546f, 0.988968f, 0.143025f,
+ -0.0741813f, 0.989009f, 0.127899f, -0.104474f, 0.989025f,
+ 0.104474f, -0.127899f, 0.989009f, 0.0741816f, -0.143025f,
+ 0.988968f, 0.0385547f, -0.14834f, 0.988936f, 0f, -0.0503274f,
+ 0.981127f, 0.186698f, -0.0968359f, 0.981197f, 0.166959f,
+ -0.136382f, 0.981224f, 0.136382f, -0.166958f, 0.981197f,
+ 0.0968361f, -0.186699f, 0.981127f, 0.0503276f, -0.193633f,
+ 0.981074f, 0f, -0.101458f, 0.920895f, 0.376377f, -0.19526f,
+ 0.921161f, 0.336655f, -0.275023f, 0.921262f, 0.275023f, -0.336655f,
+ 0.921161f, 0.19526f, -0.376377f, 0.920894f, 0.101459f, -0.390291f,
+ 0.920691f, 0f, -0.260274f, -7.99271e-010f, 0.965535f, -0.501718f,
+ -5.72859e-009f, 0.865031f, -0.707107f, -1.58043e-008f, 0.707107f,
+ -0.865031f, -2.65808e-008f, 0.501719f, -0.965534f, -2.69321e-008f,
+ 0.260276f, -1f, 0f, 0f, -0.258757f, 0.963421f, -0.0697518f,
+ -0.231413f, 0.963552f, -0.134219f, -0.189037f, 0.963603f,
+ -0.189037f, -0.13422f, 0.963552f, -0.231413f, -0.0697518f,
+ 0.963421f, -0.258756f, 0f, 0.96332f, -0.268354f, -0.162012f,
+ 0.985822f, -0.0436727f, -0.144879f, 0.985875f, -0.0840298f,
+ -0.118345f, 0.985895f, -0.118345f, -0.0840302f, 0.985875f,
+ -0.144879f, -0.0436727f, 0.985822f, -0.162011f, 0f, 0.985782f,
+ -0.168031f, -0.143025f, 0.988968f, -0.0385546f, -0.127899f,
+ 0.989009f, -0.0741813f, -0.104474f, 0.989025f, -0.104474f,
+ -0.0741816f, 0.989009f, -0.127899f, -0.0385547f, 0.988968f,
+ -0.143025f, 0f, 0.988936f, -0.14834f, -0.186698f, 0.981127f,
+ -0.0503273f, -0.166959f, 0.981197f, -0.0968358f, -0.136382f,
+ 0.981224f, -0.136382f, -0.0968361f, 0.981197f, -0.166958f,
+ -0.0503276f, 0.981127f, -0.186699f, 0f, 0.981074f, -0.193633f,
+ -0.376377f, 0.920895f, -0.101458f, -0.336655f, 0.921161f,
+ -0.19526f, -0.275023f, 0.921262f, -0.275023f, -0.19526f, 0.921161f,
+ -0.336655f, -0.101459f, 0.920894f, -0.376377f, 0f, 0.920691f,
+ -0.390291f, -0.965535f, 2.6932e-008f, -0.260274f, -0.865031f,
+ 2.65807e-008f, -0.501718f, -0.707107f, 1.58043e-008f, -0.707107f,
+ -0.501719f, 5.72864e-009f, -0.865031f, -0.260276f, 7.99283e-010f,
+ -0.965534f, 0f, 0f, -1f, 0.0697518f, 0.963421f, -0.258757f,
+ 0.134219f, 0.963552f, -0.231413f, 0.189037f, 0.963603f, -0.189037f,
+ 0.231413f, 0.963552f, -0.13422f, 0.258756f, 0.963421f, -0.0697518f,
+ 0.0436727f, 0.985822f, -0.162012f, 0.0840298f, 0.985875f,
+ -0.144879f, 0.118345f, 0.985895f, -0.118345f, 0.144879f, 0.985875f,
+ -0.0840302f, 0.162011f, 0.985822f, -0.0436727f, 0.0385546f,
+ 0.988968f, -0.143025f, 0.0741813f, 0.989009f, -0.127899f,
+ 0.104474f, 0.989025f, -0.104474f, 0.127899f, 0.989009f,
+ -0.0741816f, 0.143025f, 0.988968f, -0.0385547f, 0.0503274f,
+ 0.981127f, -0.186698f, 0.0968359f, 0.981197f, -0.166959f,
+ 0.136382f, 0.981224f, -0.136382f, 0.166958f, 0.981197f,
+ -0.0968361f, 0.186699f, 0.981127f, -0.0503276f, 0.101458f,
+ 0.920895f, -0.376377f, 0.19526f, 0.921161f, -0.336655f, 0.275023f,
+ 0.921262f, -0.275023f, 0.336655f, 0.921161f, -0.19526f, 0.376377f,
+ 0.920894f, -0.101459f, 0.260274f, 7.99271e-010f, -0.965535f,
+ 0.501718f, 5.72859e-009f, -0.865031f, 0.707107f, 1.58043e-008f,
+ -0.707107f, 0.865031f, 2.65807e-008f, -0.501719f, 0.965534f,
+ 2.6932e-008f, -0.260276f, 0.0226746f, -0.999743f, -1.91575e-007f,
+ 0.00017586f, -1f, -1.78936e-007f, 0.0218614f, -0.999744f,
+ -0.00589325f, 0.0195486f, -0.999745f, -0.0113383f, 0.0159681f,
+ -0.999745f, -0.0159682f, 0.0113382f, -0.999745f, -0.0195487f,
+ 0.0058931f, -0.999744f, -0.0218616f, 0f, -0.999743f, -0.0226747f,
+ 0.0623783f, -0.998053f, -2.05165e-007f, 0.0601415f, -0.998058f,
+ -0.0162122f, 0.0537792f, -0.998066f, -0.0311921f, 0.0439291f,
+ -0.998068f, -0.0439292f, 0.031192f, -0.998066f, -0.0537793f,
+ 0.0162121f, -0.998058f, -0.0601416f, 0f, -0.998053f, -0.0623784f,
+ 0.141421f, -0.98995f, -2.16354e-007f, 0.136353f, -0.989978f,
+ -0.0367563f, 0.121933f, -0.990016f, -0.0707209f, 0.0996006f,
+ -0.99003f, -0.0996008f, 0.070721f, -0.990016f, -0.121933f,
+ 0.0367563f, -0.989978f, -0.136353f, 0f, -0.98995f, -0.141421f,
+ 0.328521f, -0.944497f, -2.21665e-007f, 0.316788f, -0.944644f,
+ -0.0853952f, 0.283332f, -0.944838f, -0.164332f, 0.231454f,
+ -0.944912f, -0.231454f, 0.164333f, -0.944838f, -0.283331f,
+ 0.0853954f, -0.944644f, -0.316788f, 0f, -0.944497f, -0.328521f,
+ 0.770022f, -0.638017f, -1.57624e-007f, 0.743044f, -0.638566f,
+ -0.200299f, 0.665183f, -0.639286f, -0.385806f, 0.543581f,
+ -0.639561f, -0.543581f, 0.385806f, -0.639286f, -0.665182f, 0.2003f,
+ -0.638566f, -0.743044f, 0f, -0.638017f, -0.770022f, 0.965535f,
+ 2.69333e-008f, -0.260274f, 0.865031f, 2.6582e-008f, -0.501718f,
+ 0.501719f, 5.7289e-009f, -0.865031f, 0.260276f, 7.9932e-010f,
+ -0.965534f, 0f, -0.999743f, -0.0226747f, -0.00589307f, -0.999744f,
+ -0.0218616f, -0.0113382f, -0.999745f, -0.0195487f, -0.015968f,
+ -0.999745f, -0.0159682f, -0.0195486f, -0.999745f, -0.0113384f,
+ -0.0218614f, -0.999744f, -0.00589328f, -0.0226746f, -0.999743f,
+ -1.91575e-007f, 0f, -0.998053f, -0.0623784f, -0.016212f,
+ -0.998058f, -0.0601416f, -0.0311919f, -0.998066f, -0.0537794f,
+ -0.0439291f, -0.998068f, -0.0439292f, -0.0537792f, -0.998066f,
+ -0.0311922f, -0.0601415f, -0.998058f, -0.0162123f, -0.0623783f,
+ -0.998053f, -2.05165e-007f, -0.0367561f, -0.989978f, -0.136353f,
+ -0.0707208f, -0.990016f, -0.121933f, -0.0996006f, -0.99003f,
+ -0.0996008f, -0.121932f, -0.990016f, -0.0707211f, -0.136353f,
+ -0.989978f, -0.0367565f, -0.141421f, -0.98995f, -2.16354e-007f, 0f,
+ -0.944497f, -0.32852f, -0.0853949f, -0.944644f, -0.316788f,
+ -0.164332f, -0.944838f, -0.283331f, -0.231454f, -0.944912f,
+ -0.231454f, -0.283331f, -0.944838f, -0.164333f, -0.316788f,
+ -0.944644f, -0.0853956f, -0.32852f, -0.944497f, -2.21665e-007f, 0f,
+ -0.638018f, -0.770021f, -0.200298f, -0.638567f, -0.743043f,
+ -0.385805f, -0.639287f, -0.665182f, -0.543581f, -0.639562f,
+ -0.543581f, -0.665181f, -0.639287f, -0.385806f, -0.743043f,
+ -0.638567f, -0.2003f, -0.770021f, -0.638018f, -1.57625e-007f,
+ -0.260274f, 7.99307e-010f, -0.965535f, -0.501718f, 5.72886e-009f,
+ -0.865031f, -0.865031f, 2.65819e-008f, -0.501719f, -0.965534f,
+ 2.69333e-008f, -0.260276f, -0.0226746f, -0.999743f, -1.91442e-007f,
+ -0.0218614f, -0.999744f, 0.00589289f, -0.0195486f, -0.999745f,
+ 0.011338f, -0.0159681f, -0.999745f, 0.0159679f, -0.0113382f,
+ -0.999745f, 0.0195484f, -0.0058931f, -0.999744f, 0.0218612f, 0f,
+ -0.999743f, 0.0226744f, -0.0623783f, -0.998053f, -2.04538e-007f,
+ -0.0601415f, -0.998058f, 0.0162119f, -0.0537793f, -0.998066f,
+ 0.0311918f, -0.0439291f, -0.998068f, 0.0439289f, -0.031192f,
+ -0.998066f, 0.0537791f, -0.0162121f, -0.998058f, 0.0601414f, 0f,
+ -0.998053f, 0.0623782f, -0.136353f, -0.989978f, 0.0367559f,
+ -0.121932f, -0.990016f, 0.0707206f, -0.0996006f, -0.99003f,
+ 0.0996005f, -0.0707209f, -0.990016f, 0.121932f, -0.0367563f,
+ -0.989978f, 0.136353f, 0f, -0.98995f, 0.141421f, -0.328521f,
+ -0.944497f, -2.1827e-007f, -0.316789f, -0.944644f, 0.0853949f,
+ -0.283332f, -0.944838f, 0.164332f, -0.231455f, -0.944911f,
+ 0.231454f, -0.164333f, -0.944837f, 0.283332f, -0.0853956f,
+ -0.944644f, 0.316789f, 0f, -0.944497f, 0.328521f, -0.770023f,
+ -0.638016f, -1.53325e-007f, -0.743045f, -0.638564f, 0.200299f,
+ -0.665184f, -0.639284f, 0.385806f, -0.543582f, -0.63956f,
+ 0.543582f, -0.385807f, -0.639284f, 0.665183f, -0.2003f, -0.638564f,
+ 0.743045f, 0f, -0.638016f, 0.770023f, -0.965535f, -2.69333e-008f,
+ 0.260274f, -0.865031f, -2.6582e-008f, 0.501718f, -0.707107f,
+ -1.58051e-008f, 0.707107f, -0.501719f, -5.7289e-009f, 0.865031f,
+ -0.260276f, -7.9932e-010f, 0.965534f, 0.00589307f, -0.999744f,
+ 0.0218612f, 0.0113382f, -0.999745f, 0.0195484f, 0.0159681f,
+ -0.999745f, 0.0159679f, 0.0195486f, -0.999745f, 0.011338f,
+ 0.0218614f, -0.999744f, 0.00589292f, 0.0226746f, -0.999743f,
+ -1.91442e-007f, 0.016212f, -0.998058f, 0.0601414f, 0.0311919f,
+ -0.998066f, 0.0537791f, 0.0439291f, -0.998068f, 0.0439289f,
+ 0.0537792f, -0.998066f, 0.0311918f, 0.0601415f, -0.998058f,
+ 0.016212f, 0.0623783f, -0.998053f, -2.04538e-007f, 0.0367561f,
+ -0.989978f, 0.136353f, 0.0707208f, -0.990016f, 0.121932f,
+ 0.0996006f, -0.99003f, 0.0996005f, 0.121932f, -0.990016f,
+ 0.0707208f, 0.136353f, -0.989978f, 0.0367561f, 0.0853951f,
+ -0.944644f, 0.316789f, 0.164332f, -0.944838f, 0.283332f, 0.231455f,
+ -0.944911f, 0.231454f, 0.283332f, -0.944837f, 0.164333f, 0.316789f,
+ -0.944644f, 0.0853954f, 0.328521f, -0.944497f, -2.1827e-007f,
+ 0.200299f, -0.638564f, 0.743045f, 0.385806f, -0.639284f, 0.665184f,
+ 0.543582f, -0.63956f, 0.543582f, 0.665183f, -0.639284f, 0.385807f,
+ 0.743045f, -0.638565f, 0.2003f, 0.770023f, -0.638016f,
+ -1.53325e-007f, 0.260274f, -7.99307e-010f, 0.965535f, 0.501718f,
+ -5.72886e-009f, 0.865031f, 0.707107f, -1.58051e-008f, 0.707107f,
+ 0.865031f, -2.65819e-008f, 0.501719f, 0.965534f, -2.69333e-008f,
+ 0.260276f, 0.000169553f, -1f, 4.55269e-005f, 0.000151615f, -1f,
+ 8.7758e-005f, 0.000123845f, -1f, 0.000123666f, 8.79365e-005f, -1f,
+ 0.000151436f, 4.57054e-005f, -1f, 0.000169374f, 0f, -1f,
+ 0.000175681f, -4.57057e-005f, -1f, 0.000169374f, -8.79367e-005f,
+ -1f, 0.000151436f, -0.000123845f, -1f, 0.000123666f, -0.000151615f,
+ -1f, 8.77577e-005f, -0.000169553f, -1f, 4.55266e-005f,
+ -0.00017586f, -1f, -1.78936e-007f, -0.141421f, -0.98995f,
+ -2.18023e-007f, 0f, -1f, -0.000176026f, -4.57022e-005f, -1f,
+ -0.000169719f, -8.79303e-005f, -1f, -0.000151783f, -0.000123836f,
+ -1f, -0.000124015f, -0.000151604f, -1f, -8.81092e-005f,
+ -0.00016954f, -1f, -4.58813e-005f, -0.000175847f, -1f,
+ -1.78936e-007f, 0.141421f, -0.98995f, -2.18023e-007f, 0.000175847f,
+ -1f, -1.78936e-007f, 0.000169541f, -1f, -4.58811e-005f,
+ 0.000151604f, -1f, -8.81091e-005f, 0.000123836f, -1f,
+ -0.000124015f, 8.79306e-005f, -1f, -0.000151783f, 4.57025e-005f,
+ -1f, -0.000169719f, 0.423155f, 0.801174f, 0.423155f, 0.300386f,
+ 0.800964f, 0.517905f, 0.15602f, 0.800417f, 0.578784f, 0f, 0.8f,
+ 0.6f, 0.000884181f, 0.999999f, 0.000884182f, 0.0006461f, 0.999999f,
+ 0.00107175f, 0.000305924f, 0.999999f, 0.00121748f, 0f, 0.999999f,
+ 0.001257f, 0.00125688f, 0.999999f, 0f, 0.00121716f, 0.999999f,
+ -0.000305839f, 0.00107193f, 0.999999f, -0.000646202f, 0.00088386f,
+ 0.999999f, -0.00088386f, 0.000626479f, 0.999999f, -0.00108364f,
+ 0.000335298f, 0.999999f, -0.00120914f, 0f, 0.999999f, -0.00125688f,
+ -0.000305839f, 0.999999f, -0.00121716f, -0.000646202f, 0.999999f,
+ -0.00107193f, -0.00088386f, 0.999999f, -0.00088386f, -0.00108364f,
+ 0.999999f, -0.000626479f, -0.00120914f, 0.999999f, -0.000335298f,
+ -0.00125688f, 0.999999f, 0f, 0.517904f, 0.800965f, -0.300385f,
+ 0.300384f, 0.800965f, -0.517904f, 0.15602f, 0.800418f, -0.578782f,
+ 0f, 0.800001f, -0.599999f, -0.15602f, 0.800418f, -0.578783f,
+ -0.300385f, 0.800965f, -0.517903f, -0.517904f, 0.800965f,
+ -0.300384f, -0.15602f, 0.800417f, 0.578783f, -0.300384f, 0.800964f,
+ 0.517905f, -0.423155f, 0.801174f, 0.423155f, 0f, 0.999999f,
+ 0.00125701f, -0.000335262f, 0.999999f, 0.00120901f, -0.000626413f,
+ 0.999999f, 0.00108353f, -0.00088419f, 0.999999f, 0.00088419f,
+ -0.00107176f, 0.999999f, 0.000646106f, -0.00121749f, 0.999999f,
+ 0.000305927f, -0.00125701f, 0.999999f, 0f, 0.366221f, -0.855433f,
+ -0.36622f, -0.497164f, 0.711096f, -0.497162f, -0.6f, 0.8f, 0f,
+ -0.267367f, 0.443287f, 0.855577f, -0.0149983f, 0.999888f, 0f, -1f,
+ 0f, 0f, -0.811257f, -0.584689f, -4.21204e-009f, 0.811257f,
+ -0.584689f, -4.21204e-009f, -0.6981f, -0.716f, -1.86057e-008f,
+ 0.6981f, -0.716f, -1.86057e-008f, -0.636383f, -0.771373f,
+ -5.10224e-008f, 0.636383f, -0.771373f, -5.10224e-008f, -0.675056f,
+ -0.737767f, -1.01053e-007f, 0.675056f, -0.737767f, -1.01053e-007f,
+ 0.965535f, -2.6933e-008f, 0.260274f, 0.902861f, 0.429933f, 0f,
+ 0.637936f, 0.431366f, -0.637936f, 0f, 0.429933f, -0.902861f,
+ -0.637936f, 0.431366f, -0.637936f, -0.902861f, 0.429933f, 0f, 0f,
+ 0.429933f, 0.902861f, -0.637936f, 0.431366f, 0.637936f, -0.556737f,
+ 0.830689f, 0f, 0.637936f, 0.431366f, 0.637936f, 0f, -0.156768f,
+ -0.987635f, -0.148341f, 0.988936f, 0f, 0.148341f, 0.988936f, 0 };
+
+ float lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1 };
+ float lightDiffuse[] = { 1.0f, 0.6f, 0.0f, 1 };
+ float matAmbient[] = { 0.6f, 0.6f, 0.6f, 1.0f };
+ float matDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
+ float matSpecular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
+ float lightPosition[] = { 0, 0, 1.0f, 0 };
+ float lightShininess = 100.0f;
+ float zNear = 0.1f, zFar = 1000.0f, fieldOfView = 60.0f;
+ float kTeapotScale = 3.0f;
+
+ float size;
+ float kFilteringFactor = 0.1f;
+
+ private Tester mTester;
+ private float xspeed;
+ private float yspeed;
+ private float zspeed;
+
+ public TeapotRenderer(float _xspeed, float _yspeed, float _zspeed, Tester tester) {
+ // mContext = context;
+ xspeed = _xspeed;
+ yspeed = _yspeed;
+ zspeed = _zspeed;
+ mTester = tester;
+ teapot = new Teapot();
+ teapot.setSpeedAndTester(xspeed, yspeed, zspeed, mTester);
+ Log.d("glesteapot", "TeapotRender");
+ }
+
+ public int[] getConfigSpec() {
+ // We don't need a depth buffer, and don't care about our
+ // color depth.
+ int[] configSpec = { EGL10.EGL_DEPTH_SIZE, 0, EGL10.EGL_NONE };
+ Log.d("glesteapot", "TeapotRender getConfigSpec");
+ return configSpec;
+ }
+
+ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
+ int w = 0, h =0;
+
+ gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
+ gl.glViewport(0, 0, w, h);
+
+ gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
+ gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
+ gl.glEnable(GL10.GL_DEPTH_TEST);
+ gl.glEnable(GL10.GL_CULL_FACE);
+ gl.glShadeModel(GL10.GL_SMOOTH);
+
+ gl.glEnable(GL10.GL_LIGHTING);
+ gl.glEnable(GL10.GL_LIGHT0);
+ gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, matAmbient, 0);
+ gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, matDiffuse, 0);
+ gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR, matSpecular,0);
+ gl.glMaterialf(GL10.GL_FRONT_AND_BACK, GL10.GL_SHININESS, lightShininess);
+ gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbient, 0);
+ gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuse, 0);
+ gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPosition, 0);
+ gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
+ gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
+ gl.glVertexPointer(3, GL10.GL_FLOAT, 0, fillFloatBuffer(teapot_vertices));
+ gl.glNormalPointer(GL10.GL_FLOAT, 0, fillFloatBuffer(teapot_normals));
+ gl.glEnable(GL10.GL_NORMALIZE);
+
+ Log.d("glesteapot", "TeapotRender surfaceCreated()");
+ }
+
+ private FloatBuffer fillFloatBuffer(float[] mat) {
+ ByteBuffer vbb = ByteBuffer.allocateDirect(mat.length * 4);
+ vbb.order(ByteOrder.nativeOrder());
+ FloatBuffer tmpBuffer = vbb.asFloatBuffer();
+ tmpBuffer.put(mat);
+ tmpBuffer.position(0);
+ return tmpBuffer;
+ }
+
+ public void onDrawFrame(GL10 gl) {
+ teapot.draw(gl);
+ }
+
+ public void onSurfaceChanged(GL10 gl, int w, int h) {
+ gl.glViewport(0, 0, w, h);
+
+ float ratio = (float) w / h;
+
+ gl.glMatrixMode(GL10.GL_PROJECTION);
+ gl.glLoadIdentity();
+ size = (float) (zNear * Math.tan((fieldOfView / 180 * 3.14) / 2.0));
+ gl.glFrustumf(-size, size, -size / ratio, size / ratio, zNear, zFar);
+ gl.glMatrixMode(GL10.GL_MODELVIEW);
+
+ gl.glClearColor(0, 0, 0, 0);
+ gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
+ gl.glLoadIdentity();
+ gl.glTranslatef(0.0f, -0.1f, -1.0f);
+ gl.glScalef(kTeapotScale, kTeapotScale, kTeapotScale);
+ Log.d("glesteapot", "sizeChanged: " + w + ", " + h);
+ }
+
+ public void onSensorChanged(float[] values) {
+ teapot.onSensorValueChanged(values);
+ }
+
+ public void setSensor(int sensorId) {
+ teapot.setSensor(sensorId);
+ }
+
+ private Teapot teapot;
+}
+
+class Teapot {
+ float kFilteringFactor = 0.1f;
+ float[] m2;
+ float sensorValues[] = new float[3];
+ float _accelerometer[] = new float[3];
+ private int sensorMode;
+
+ private float xrot = 0;
+ private float yrot = 0;
+ private float zrot = 0;
+ static short teapot_indices[] = { 1122, 1243, 1272, 1242, 1273, 1241, 1274,
+ 1240, 1275, 1239, 1276, 1238, 1277, 1205, 1278, 1204, 1279, 1203,
+ 1280, 1202, 1281, 1201, 1282, 1200, 1283, 1199, -1, 1243, 1249,
+ 1242, 1248, 1241, 1247, 1240, 1246, 1239, 1245, 1238, 1244, 1205,
+ 1212, 1204, 1211, 1203, 1210, 1202, 1209, 1201, 1208, 1200, 1207,
+ 1199, 1206, -1, 1249, 1136, 1248, 1254, 1247, 1253, 1246, 1252,
+ 1245, 1251, 1244, 1250, 1212, 1218, 1211, 1217, 1210, 1216, 1209,
+ 1215, 1208, 1214, 1207, 1213, 1206, 1180, -1, 1136, 1260, 1254,
+ 1259, 1253, 1258, 1252, 1257, 1251, 1256, 1250, 1255, 1218, 1225,
+ 1217, 1224, 1216, 1223, 1215, 1222, 1214, 1221, 1213, 1220, 1180,
+ 1219, -1, 1260, 1266, 1259, 1265, 1258, 1264, 1257, 1263, 1256,
+ 1262, 1255, 1261, 1225, 1232, 1224, 1231, 1223, 1230, 1222, 1229,
+ 1221, 1228, 1220, 1227, 1219, 1226, -1, 1266, 384, 1265, 1271,
+ 1264, 1270, 1263, 1269, 1262, 1268, 1261, 1267, 1232, 390, 1231,
+ 1237, 1230, 1236, 1229, 1235, 1228, 1234, 1227, 1233, 1226, 426,
+ -1, 462, 1188, 1195, 1189, 1196, 1190, 459, 1191, 1197, 1192, 1198,
+ 1193, 426, 1194, -1, 1188, 1181, 1189, 1182, 1190, 1183, 1191,
+ 1184, 1192, 1185, 1193, 1186, 1194, 1187, -1, 1181, 1142, 1182,
+ 1175, 1183, 1176, 1184, 1177, 1185, 1178, 1186, 1179, 1187, 1284,
+ -1, 1142, 1168, 1175, 1169, 1176, 1170, 1177, 1171, 1178, 1172,
+ 1179, 1173, 1284, 1174, -1, 1168, 1161, 1169, 1162, 1170, 1163,
+ 1171, 1164, 1172, 1165, 1173, 1166, 1174, 1167, -1, 1161, 1285,
+ 1162, 1286, 1163, 1287, 1164, 1288, 1165, 1289, 1166, 1290, 1167,
+ 1291, -1, 384, 1150, 1157, 1151, 1158, 1152, 490, 1153, 1159, 1154,
+ 1160, 1155, 462, 1156, -1, 1150, 1143, 1151, 1144, 1152, 1145,
+ 1153, 1146, 1154, 1147, 1155, 1148, 1156, 1149, -1, 1143, 1292,
+ 1144, 1137, 1145, 1138, 1146, 1139, 1147, 1140, 1148, 1141, 1149,
+ 1142, -1, 1292, 1129, 1137, 1130, 1138, 1131, 1139, 1132, 1140,
+ 1133, 1141, 1134, 1142, 1135, -1, 1129, 1121, 1130, 1123, 1131,
+ 1124, 1132, 1125, 1133, 1126, 1134, 1127, 1135, 1128, -1, 1121,
+ 1293, 1123, 1294, 1124, 1295, 1125, 1296, 1126, 1297, 1127, 1298,
+ 1128, 1285, -1, 902, 1024, 901, 1023, 900, 1022, 899, 1021, 898,
+ 1020, 897, 1019, 862, 983, 861, 982, 860, 981, 859, 980, 858, 979,
+ 857, 978, 856, 977, -1, 856, 849, 857, 850, 858, 851, 1299, 852,
+ 1300, 853, 1301, 854, 1302, 855, -1, 849, 842, 850, 843, 851, 844,
+ 852, 845, 853, 846, 854, 847, 855, 848, -1, 842, 835, 843, 836,
+ 844, 837, 845, 838, 846, 839, 847, 840, 848, 841, -1, 835, 828,
+ 836, 829, 837, 830, 838, 831, 839, 832, 840, 833, 841, 834, -1,
+ 828, 818, 829, 820, 830, 822, 831, 824, 832, 825, 833, 826, 834,
+ 827, -1, 818, 819, 820, 821, 822, 823, 824, 1303, 825, 1304, 826,
+ 1305, 827, 1306, -1, 1307, 948, 1308, 947, 1309, 946, 1310, 945,
+ 1311, 944, 1312, 943, 1313, 909, 1314, 908, 1315, 907, 1316, 906,
+ 1317, 905, 1318, 904, 1319, 903, -1, 948, 954, 947, 953, 946, 952,
+ 945, 951, 944, 950, 943, 949, 909, 916, 908, 915, 907, 914, 906,
+ 913, 905, 912, 904, 911, 903, 910, -1, 954, 835, 953, 959, 952,
+ 958, 951, 957, 950, 956, 949, 955, 916, 922, 915, 921, 914, 920,
+ 913, 919, 912, 918, 911, 917, 910, 882, -1, 835, 965, 959, 964,
+ 958, 963, 957, 962, 956, 961, 955, 960, 922, 929, 921, 928, 920,
+ 927, 919, 926, 918, 925, 917, 924, 882, 923, -1, 965, 971, 964,
+ 970, 963, 969, 962, 968, 961, 967, 960, 966, 929, 936, 928, 935,
+ 927, 934, 926, 933, 925, 932, 924, 931, 923, 930, -1, 971, 856,
+ 970, 976, 969, 975, 968, 974, 967, 973, 966, 972, 936, 942, 935,
+ 941, 934, 940, 933, 939, 932, 938, 931, 937, 930, 902, -1, 856,
+ 977, 976, 1095, 1320, 1094, 974, 1093, 1321, 1092, 1322, 1091,
+ 1323, 1060, 1324, 1059, 1325, 1058, 939, 1057, 1326, 1056, 937,
+ 1055, 902, 1024, -1, 1302, 890, 1327, 891, 1328, 892, 1329, 893,
+ 900, 894, 901, 895, 902, 896, -1, 890, 883, 891, 884, 892, 885,
+ 893, 886, 894, 887, 895, 888, 896, 889, -1, 883, 841, 884, 877,
+ 885, 878, 886, 879, 887, 880, 888, 881, 889, 882, -1, 841, 870,
+ 877, 871, 878, 872, 879, 873, 880, 874, 881, 875, 882, 876, -1,
+ 870, 863, 871, 864, 872, 865, 873, 866, 874, 867, 875, 868, 876,
+ 869, -1, 863, 1330, 864, 1331, 865, 1332, 866, 1333, 867, 1334,
+ 868, 1335, 869, 1336, -1, 787, 780, 813, 808, 814, 809, 815, 810,
+ 816, 811, 817, 812, 781, 774, 782, 775, 783, 776, 784, 777, 785,
+ 778, 786, 779, 787, 780, -1, 774, 767, 775, 768, 776, 769, 777,
+ 770, 778, 771, 779, 772, 780, 773, -1, 767, 760, 768, 761, 769,
+ 762, 770, 763, 771, 764, 772, 765, 773, 766, 803, 798, 804, 799,
+ 805, 800, 806, 801, 807, 802, 767, 760, -1, 767, 774, 807, 812,
+ 806, 811, 805, 810, 804, 809, 803, 808, 773, 780, -1, 760, 753,
+ 761, 754, 762, 755, 763, 756, 764, 757, 765, 758, 766, 759, 798,
+ 793, 799, 794, 800, 795, 801, 796, 802, 797, 760, 753, -1, 759,
+ 752, 793, 788, 794, 789, 795, 790, 796, 791, 797, 792, 753, 746,
+ -1, 752, 703, 788, 741, 789, 742, 790, 743, 791, 744, 792, 745,
+ 746, 697, 747, 698, 748, 699, 749, 700, 750, 701, 751, 702, 752,
+ 703, -1, 752, 759, 751, 758, 750, 757, 749, 756, 748, 755, 747,
+ 754, 746, 753, -1, 703, 734, 1337, 735, 742, 736, 743, 737, 744,
+ 738, 1338, 739, 1339, 740, -1, 734, 727, 735, 728, 736, 729, 737,
+ 730, 738, 731, 739, 732, 740, 733, -1, 727, 682, 728, 722, 729,
+ 723, 730, 724, 731, 725, 732, 726, 733, 676, -1, 682, 716, 722,
+ 717, 723, 718, 724, 719, 725, 720, 726, 721, 676, 669, -1, 716,
+ 704, 717, 705, 718, 707, 719, 709, 720, 711, 721, 713, 669, 715,
+ -1, 704, 668, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714,
+ 715, 656, -1, 1339, 690, 698, 691, 1340, 692, 700, 693, 701, 694,
+ 702, 695, 703, 696, -1, 690, 683, 691, 684, 692, 685, 693, 686,
+ 694, 687, 695, 688, 696, 689, -1, 683, 676, 684, 677, 685, 678,
+ 686, 679, 687, 680, 688, 681, 689, 682, -1, 676, 669, 677, 670,
+ 678, 671, 679, 672, 680, 673, 681, 674, 682, 675, -1, 669, 655,
+ 670, 657, 671, 659, 672, 661, 673, 663, 674, 665, 675, 667, -1,
+ 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667,
+ 668, -1, 624, 618, 650, 645, 651, 646, 652, 647, 653, 648, 654,
+ 649, 266, 612, -1, 266, 612, 619, 613, 620, 614, 621, 615, 622,
+ 616, 623, 617, 624, 618, -1, 612, 605, 613, 606, 614, 607, 615,
+ 608, 616, 609, 617, 610, 618, 611, 645, 640, 646, 641, 647, 642,
+ 648, 643, 649, 644, 612, 605, -1, 605, 598, 606, 599, 607, 600,
+ 608, 601, 609, 602, 610, 603, 611, 604, 640, 635, 641, 636, 642,
+ 637, 643, 638, 644, 639, 605, 598, -1, 604, 597, 635, 630, 636,
+ 631, 637, 632, 638, 633, 639, 634, 598, 591, -1, 597, 590, 630,
+ 625, 631, 626, 632, 627, 633, 628, 634, 629, 591, 584, -1, 590,
+ 541, 625, 579, 626, 580, 627, 581, 628, 582, 629, 583, 584, 535,
+ 585, 536, 586, 537, 587, 538, 588, 539, 589, 540, 590, 541, -1,
+ 590, 597, 589, 596, 588, 595, 587, 594, 586, 593, 585, 592, 584,
+ 591, -1, 597, 604, 596, 603, 595, 602, 594, 601, 593, 600, 592,
+ 599, 591, 598, -1, 541, 572, 579, 573, 580, 574, 581, 575, 582,
+ 576, 583, 577, 535, 578, -1, 572, 565, 573, 566, 574, 567, 575,
+ 568, 576, 569, 577, 570, 578, 571, -1, 565, 520, 566, 560, 567,
+ 561, 568, 562, 569, 563, 570, 564, 571, 514, -1, 520, 553, 560,
+ 554, 561, 555, 562, 556, 563, 557, 564, 558, 514, 559, -1, 553,
+ 505, 554, 542, 555, 544, 556, 546, 557, 548, 558, 550, 559, 552,
+ -1, 505, 506, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551,
+ 552, 494, -1, 535, 528, 536, 529, 537, 530, 538, 531, 539, 532,
+ 540, 533, 541, 534, -1, 528, 521, 529, 522, 530, 523, 531, 524,
+ 532, 525, 533, 526, 534, 527, -1, 521, 514, 522, 515, 523, 516,
+ 524, 517, 525, 518, 526, 519, 527, 520, -1, 514, 507, 515, 508,
+ 516, 509, 517, 510, 518, 511, 519, 512, 520, 513, -1, 507, 493,
+ 508, 495, 509, 497, 510, 499, 511, 501, 512, 503, 513, 1341, -1,
+ 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 1341,
+ 506, -1, 216, 349, 348, 467, 347, 466, 346, 465, 345, 464, 344,
+ 463, 310, 432, 309, 431, 308, 430, 307, 429, 306, 428, 305, 427,
+ 1342, 396, -1, 349, 356, 467, 472, 466, 471, 465, 470, 464, 469,
+ 463, 468, 432, 438, 431, 437, 430, 436, 429, 435, 428, 434, 427,
+ 433, 396, 402, -1, 356, 363, 472, 477, 471, 476, 470, 475, 469,
+ 474, 468, 473, 438, 444, 437, 443, 436, 442, 435, 441, 434, 440,
+ 433, 439, 402, 408, -1, 363, 370, 477, 482, 476, 481, 475, 480,
+ 474, 479, 473, 478, 444, 450, 443, 449, 442, 448, 441, 447, 440,
+ 446, 439, 445, 408, 414, -1, 370, 377, 482, 487, 481, 486, 480,
+ 485, 479, 484, 478, 483, 450, 456, 449, 455, 448, 454, 447, 453,
+ 446, 452, 445, 451, 414, 420, -1, 377, 384, 487, 492, 486, 491,
+ 485, 490, 484, 489, 483, 488, 456, 462, 455, 461, 454, 460, 453,
+ 459, 452, 458, 451, 457, 420, 426, -1, 1342, 396, 265, 395, 264,
+ 394, 263, 393, 262, 392, 261, 391, 222, 355, 221, 354, 220, 353,
+ 219, 352, 218, 351, 217, 350, 216, 349, -1, 396, 1343, 395, 401,
+ 394, 400, 393, 399, 392, 398, 391, 397, 355, 362, 354, 361, 353,
+ 360, 352, 359, 351, 358, 350, 357, 349, 1344, -1, 1343, 1345, 401,
+ 407, 400, 406, 399, 405, 398, 404, 397, 403, 362, 369, 361, 368,
+ 360, 367, 359, 366, 358, 365, 357, 364, 1344, 1346, -1, 1345, 1347,
+ 407, 413, 406, 412, 405, 411, 404, 410, 403, 409, 369, 376, 368,
+ 375, 367, 374, 366, 373, 365, 372, 364, 371, 1346, 1348, -1, 1347,
+ 1349, 413, 419, 412, 418, 411, 417, 410, 416, 409, 415, 376, 383,
+ 375, 382, 374, 381, 373, 380, 372, 379, 371, 378, 1348, 1350, -1,
+ 1349, 426, 419, 425, 418, 424, 417, 423, 416, 422, 415, 421, 383,
+ 390, 382, 389, 381, 388, 380, 387, 379, 386, 378, 385, 1350, 384,
+ -1, 42, 320, 319, 318, 317, 316, 174, 315, 314, 313, 312, 311, 137,
+ 277, 276, 275, 274, 273, 134, 272, 271, 270, 269, 268, 92, 267, -1,
+ 320, 326, 318, 325, 316, 324, 315, 323, 313, 322, 311, 321, 277,
+ 284, 275, 283, 273, 282, 272, 281, 270, 280, 268, 279, 267, 278,
+ -1, 326, 195, 325, 331, 324, 330, 323, 329, 322, 328, 321, 327,
+ 284, 290, 283, 289, 282, 288, 281, 287, 280, 286, 279, 285, 278,
+ 246, -1, 195, 337, 331, 336, 330, 335, 329, 334, 328, 333, 327,
+ 332, 290, 297, 289, 296, 288, 295, 287, 294, 286, 293, 285, 292,
+ 246, 291, -1, 337, 343, 336, 342, 335, 341, 334, 340, 333, 339,
+ 332, 338, 297, 304, 296, 303, 295, 302, 294, 301, 293, 300, 292,
+ 299, 291, 298, -1, 343, 216, 342, 348, 341, 347, 340, 346, 339,
+ 345, 338, 344, 304, 310, 303, 309, 302, 308, 301, 307, 300, 306,
+ 299, 305, 298, 1342, -1, 222, 254, 261, 255, 262, 256, 263, 257,
+ 264, 258, 265, 259, 1342, 260, -1, 254, 247, 255, 248, 256, 249,
+ 257, 250, 258, 251, 259, 252, 260, 253, -1, 247, 201, 248, 241,
+ 249, 242, 250, 243, 251, 244, 252, 245, 253, 246, -1, 201, 234,
+ 241, 235, 242, 236, 243, 237, 244, 238, 245, 239, 246, 240, -1,
+ 234, 223, 235, 224, 236, 226, 237, 228, 238, 229, 239, 231, 240,
+ 233, -1, 223, 48, 224, 225, 226, 227, 228, 89, 229, 230, 231, 232,
+ 233, 92, -1, 216, 209, 1351, 210, 218, 211, 219, 212, 220, 213,
+ 221, 214, 222, 215, -1, 209, 202, 210, 203, 211, 204, 212, 205,
+ 213, 206, 214, 207, 215, 208, -1, 202, 195, 203, 196, 204, 197,
+ 205, 198, 206, 199, 207, 200, 208, 201, -1, 195, 188, 196, 189,
+ 197, 190, 198, 191, 199, 192, 200, 193, 201, 194, -1, 188, 177,
+ 189, 178, 190, 180, 191, 182, 192, 183, 193, 185, 194, 187, -1,
+ 177, 42, 178, 179, 180, 181, 182, 45, 183, 184, 185, 186, 187, 48,
+ -1, 1, 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, 138, 105,
+ 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 60, 93, -1, 148,
+ 154, 146, 153, 144, 152, 142, 151, 140, 150, 138, 149, 104, 112,
+ 102, 111, 100, 110, 98, 109, 96, 108, 94, 107, 93, 106, -1, 154,
+ 21, 153, 159, 152, 158, 151, 157, 150, 156, 149, 155, 112, 118,
+ 111, 117, 110, 116, 109, 115, 108, 114, 107, 113, 106, 72, -1, 21,
+ 165, 159, 164, 158, 163, 157, 162, 156, 161, 155, 160, 118, 124,
+ 117, 123, 116, 122, 115, 121, 114, 120, 113, 119, 72, 79, -1, 165,
+ 171, 164, 170, 163, 169, 162, 168, 161, 167, 160, 166, 124, 131,
+ 123, 130, 122, 129, 121, 128, 120, 127, 119, 126, 79, 125, -1, 171,
+ 1352, 170, 176, 169, 175, 168, 1353, 167, 173, 166, 172, 131, 1354,
+ 130, 136, 129, 135, 128, 1355, 127, 133, 126, 132, 125, 1356, -1,
+ 1357, 80, 87, 81, 88, 82, 1358, 83, 90, 84, 91, 85, 1356, 86, -1,
+ 80, 73, 81, 74, 82, 75, 83, 76, 84, 77, 85, 78, 86, 1359, -1, 73,
+ 27, 74, 67, 75, 68, 76, 69, 77, 70, 78, 71, 1359, 72, -1, 27, 20,
+ 67, 61, 68, 62, 69, 63, 70, 64, 71, 65, 72, 66, -1, 20, 12, 61, 49,
+ 62, 51, 63, 53, 64, 55, 65, 57, 66, 59, -1, 12, 13, 49, 50, 51, 52,
+ 53, 54, 55, 56, 57, 58, 59, 60, -1, 1352, 35, 43, 36, 44, 37, 1360,
+ 38, 46, 39, 47, 40, 1357, 41, -1, 35, 28, 36, 29, 37, 30, 38, 31,
+ 39, 32, 40, 33, 41, 34, -1, 28, 21, 29, 22, 30, 23, 31, 24, 32, 25,
+ 33, 26, 34, 27, -1, 21, 14, 22, 15, 23, 16, 24, 17, 25, 18, 26, 19,
+ 27, 20, -1, 14, 0, 15, 2, 16, 4, 17, 6, 18, 8, 19, 10, 20, 1361,
+ -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1361, 13, -1, 1024, 1055,
+ 1061, 1062, 1068, 1069, 1075, 1076, 1082, 1083, 1089, 1090, -1,
+ 1089, 1088, 1082, 1081, 1075, 1074, 1068, 1067, 1061, 1030, 1024,
+ 1023, -1, 1030, 1067, 1036, 1073, 1042, 1079, 1048, 1085, 1054, -1,
+ 1085, 1079, 1086, 1080, 1087, 1081, 1088, -1, 1081, 1080, 1074,
+ 1073, 1067, -1, 1080, 1079, 1073, -1, 1055, 1056, 1062, 1063, 1069,
+ 1070, 1076, 1077, 1083, 1084, 1090, 1116, -1, 1056, 1057, 1063,
+ 1064, 1070, 1071, 1077, 1078, 1084, 1111, 1116, 1117, -1, 1057,
+ 1058, 1064, 1065, 1071, 1072, 1078, 1106, 1111, 1112, 1117, 1118,
+ -1, 1058, 1059, 1065, 1066, 1072, 1101, 1106, 1107, 1112, 1113,
+ 1118, 1119, -1, 1059, 1060, 1066, 1096, 1101, 1102, 1107, 1108,
+ 1113, 1114, 1119, 1120, -1, 1060, 1091, 1096, 1097, 1102, 1103,
+ 1108, 1109, 1114, 1115, 1120, 1012, -1, 1091, 1092, 1097, 1098,
+ 1103, 1104, 1109, 1110, 1115, 1005, 1012, 1013, -1, 1092, 1093,
+ 1098, 1099, 1104, 1105, 1110, 998, 1005, 1006, 1013, 1014, -1, 998,
+ 1105, 991, 1100, 984, 1095, 977, -1, 1095, 1100, 1094, 1099, 1093,
+ -1, 1100, 1105, 1099, -1, 984, 977, 985, 978, 986, 979, 987, 980,
+ 988, 981, 989, 982, 990, 983, 1025, 1019, 1026, 1020, 1027, 1021,
+ 1028, 1022, 1029, 1023, 1030, -1, 1030, 1362, 1029, 1035, 1028,
+ 1034, 1027, 1033, 1026, 1032, 1025, 1031, 990, 997, 989, 996, 988,
+ 995, 987, 994, 986, 993, 985, 992, 984, 1363, -1, 1362, 1042, 1035,
+ 1041, 1034, 1040, 1033, 1039, 1032, 1038, 1031, 1037, 997, 1004,
+ 996, 1003, 995, 1002, 994, 1001, 993, 1000, 992, 999, 1363, 998,
+ -1, 998, 999, 1006, 1007, 1014, 1015, -1, 999, 1000, 1007, 1008,
+ 1015, 1016, -1, 1000, 1001, 1008, 1009, 1016, 1017, -1, 1001, 1002,
+ 1009, 1010, 1017, 1018, -1, 1002, 1003, 1010, 1011, 1018, 1049, -1,
+ 1003, 1004, 1011, 1043, 1049, 1050, -1, 1004, 1037, 1043, 1044,
+ 1050, 1051, -1, 1037, 1038, 1044, 1045, 1051, 1052, -1, 1038, 1039,
+ 1045, 1046, 1052, 1053, -1, 1039, 1040, 1046, 1047, 1053, 1054, -1,
+ 1054, 1047, 1048, 1041, 1042, -1, 1041, 1047, 1040, -1, };
+
+ private Tester mTester;
+ private float xspeed;
+ private float yspeed;
+ private float zspeed;
+
+ public void setSpeedAndTester(float _xspeed, float _yspeed, float _zspeed, Tester tester) {
+ xspeed = _xspeed;
+ yspeed = _yspeed;
+ zspeed = _zspeed;
+ mTester = tester;
+ }
+
+ public Teapot() {
+ ByteBuffer vbb = ByteBuffer.allocateDirect(teapot_indices.length * 4);
+ vbb.order(ByteOrder.nativeOrder());
+ mVertexBuffer = vbb.asShortBuffer();
+ mVertexBuffer.put(teapot_indices);
+ mVertexBuffer.position(0);
+ sensorMode = TeapotES.ACCEL_ID;
+ Log.d("glesteapot", "Teapot()");
+ }
+
+ public void setSensor(int sensor) {
+ sensorMode = sensor;
+ }
+
+ public void onSensorValueChanged(float[] values) {
+ sensorValues = values;
+ }
+
+ public void draw(GL10 gl) {
+ int num_teapot_indices = 2781;
+ int i = 0, start = 0;
+ float kTeapotScale = 3.0f;
+
+ gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
+ gl.glRotatef(xrot, 1, 0, 0);
+ gl.glRotatef(yrot, 0, 1, 0);
+ gl.glRotatef(zrot, 0, 0, 1);
+ gl.glRotatef(90.0f, 0, 0, -1);
+
+
+ while (i < num_teapot_indices) {
+ if (teapot_indices[i] == -1) {
+ gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, i - start,
+ GL10.GL_UNSIGNED_SHORT, mVertexBuffer.position(start));
+ start = i + 1;
+ }
+ i++;
+ }
+ if (start < num_teapot_indices)
+ gl.glDrawElements(GL10.GL_TRIANGLE_STRIP, i - start - 1,
+ GL10.GL_UNSIGNED_SHORT, mVertexBuffer.position(start));
+ // Log.d("glesteapot", "draw");
+ gl.glLoadIdentity();
+ gl.glTranslatef(0.0f, -0.1f, -1.0f);
+ gl.glScalef(kTeapotScale, kTeapotScale, kTeapotScale);
+
+ xrot += xspeed;
+ yrot += yspeed;
+ zrot += zspeed;
+ gl.glFinish();
+ mTester.decreaseCounter();
+ }
+
+ private ShortBuffer mVertexBuffer;
+}
diff --git a/src/org/opensolaris/hub/libmicro/NativeCaseMicro.java b/src/org/opensolaris/hub/libmicro/NativeCaseMicro.java
new file mode 100644
index 0000000..108e490
--- /dev/null
+++ b/src/org/opensolaris/hub/libmicro/NativeCaseMicro.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ * Authored by: Joseph Chang (bizkit) <bizkit@0xlab.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.opensolaris.hub.libmicro;
+
+import org.zeroxlab.benchmark.*;
+
+import android.util.Log;
+
+import android.os.SystemClock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+
+import java.util.ArrayList;
+
+import org.opensolaris.hub.libmicro.NativeTesterMicro;
+
+public class NativeCaseMicro extends Case {
+
+ public static String LIN_RESULT = "LIN_RESULT";
+ protected Bundle mInfo[];
+
+ public static int Repeat = 1;
+ public static int Round = 1;
+
+ public NativeCaseMicro() {
+ super("NativeCaseMicro", "org.opensolaris.hub.libmicro.NativeTesterMicro", Repeat, Round);
+
+ mType = "syscall-nsec";
+ String [] _tmp = {
+ "syscall",
+ };
+ mTags = _tmp;
+
+ generateInfo();
+ }
+
+ public String getTitle() {
+ return "LibMicro";
+ }
+
+ public String getDescription() {
+ return "(Requires root and pre-deployed binaries) LibMicro is a portable set of microbenchmarks that many Solaris engineers used during Solaris 10 development to measure the performance of various system and library calls.";
+ }
+
+ private void generateInfo() {
+ mInfo = new Bundle[Repeat];
+ for (int i = 0; i < mInfo.length; i++) {
+ mInfo[i] = new Bundle();
+ }
+ }
+
+ @Override
+ public void clear() {
+ super.clear();
+ generateInfo();
+ }
+
+ @Override
+ public void reset() {
+ super.reset();
+ generateInfo();
+ }
+
+ @Override
+ public String getBenchmark() {
+ if (!couldFetchReport()) {
+ return "No benchmark report";
+ }
+
+ return "";
+// return mInfo[0].getString(NativeTesterMicro.REPORT);
+ }
+
+ @Override
+ public ArrayList<Scenario> getScenarios () {
+ ArrayList<Scenario> scenarios = new ArrayList<Scenario>();
+
+ Bundle bundle = mInfo[0]; // only 1 run
+ for(String command: NativeTesterMicro.COMMANDS) {
+ String name = bundle.getString(command+"S");
+ String results = bundle.getString(command+"FA");
+ if(name == null || results == null)
+ continue;
+ ArrayList<String> _mTags = new ArrayList<String>();
+ _mTags.add((String)("exe:" + command.substring(command.indexOf("_")+1, command.indexOf(" "))));
+// String [] _tmp = command.split(" +-");
+// for(int i=1; i<_tmp.length; i++){
+// if(_tmp[i].matches("[NECLSW].*"))
+// continue;
+// _mTags.add((String)(_tmp[i].trim().replace(' ', ':')));
+// Log.i(TAG, _tmp[i].trim().replace(' ', ':'));
+// }
+ String [] __mTags = (String[])(_mTags.toArray(new String[_mTags.size()]));
+ Scenario s = new Scenario(name, mType, __mTags, true);
+ s.mStringResults = results;
+ scenarios.add(s);
+
+ }
+
+ return scenarios;
+ }
+
+ @Override
+ protected boolean saveResult(Intent intent, int index) {
+ Bundle info = intent.getBundleExtra(NativeTesterMicro.RESULT);
+ if (info == null) {
+ Log.i(TAG, "Cannot find LibMicroInfo");
+ return false;
+ } else {
+ mInfo[index] = info;
+ }
+
+ return true;
+ }
+}
diff --git a/src/org/opensolaris/hub/libmicro/NativeTesterMicro.java b/src/org/opensolaris/hub/libmicro/NativeTesterMicro.java
new file mode 100644
index 0000000..ccebe3e
--- /dev/null
+++ b/src/org/opensolaris/hub/libmicro/NativeTesterMicro.java
@@ -0,0 +1,429 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ * Authored by: Joseph Chang (bizkit) <bizkit@0xlab.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.opensolaris.hub.libmicro;
+
+import org.zeroxlab.benchmark.*;
+
+import android.os.Bundle;
+import android.content.Intent;
+import android.util.Log;
+
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.List;
+
+public class NativeTesterMicro extends NativeTester {
+
+ public static final String REPORT = "REPORT";
+ public static final String RESULT = "RESULT";
+ private static final String Opts = "-E -C 70 -L -S -W";
+ private static final String Path = "/system/bin/bench_";
+ public static final List<String> COMMANDS = Arrays.asList(
+
+ Path + "getpid " + Opts + " -N getpid -I 5",
+
+ Path + "getenv " + Opts + " -N getenv -s 100 -I 100",
+ Path + "getenv " + Opts + " -N getenvT2 -s 100 -I 100 -T 2",
+
+ Path + "gettimeofday " + Opts + " -N gettimeofday",
+
+ Path + "log " + Opts + " -N log -I 20",
+
+ Path + "exp " + Opts + " -N exp -I 20",
+
+ Path + "lrand48 " + Opts + " -N lrand48",
+
+ Path + "memset " + Opts + " -N memset_10 -s 10 -I 10 ",
+ Path + "memset " + Opts + " -N memset_256 -s 256 -I 20",
+ Path + "memset " + Opts + " -N memset_256_u -s 256 -a 1 -I 20 ",
+ Path + "memset " + Opts + " -N memset_1k -s 1k -I 100",
+ Path + "memset " + Opts + " -N memset_4k -s 4k -I 250",
+ Path + "memset " + Opts + " -N memset_4k_uc -s 4k -u -I 400",
+ Path + "memset " + Opts + " -N memset_10k -s 10k -I 600 ",
+ Path + "memset " + Opts + " -N memset_1m -s 1m -I 200000",
+// Path + "memset " + Opts + " -N memset_10m -s 10m -I 2000000 ",
+// Path + "memset " + Opts + " -N memsetP2_10m -s 10m -P 2 -I 2000000 ",
+
+// Path + "memrand " + Opts + " -N memrand -s 128m -B 10000",
+
+ Path + "isatty " + Opts + " -N isatty_yes ",
+// Path + "isatty " + Opts + " -N isatty_no -f $IFILE",
+
+ Path + "malloc " + Opts + " -N malloc_10 -s 10 -g 10 -I 50",
+ Path + "malloc " + Opts + " -N malloc_100 -s 100 -g 10 -I 50",
+ Path + "malloc " + Opts + " -N malloc_1k -s 1k -g 10 -I 50",
+ Path + "malloc " + Opts + " -N malloc_10k -s 10k -g 10 -I 50",
+ Path + "malloc " + Opts + " -N malloc_100k -s 100k -g 10 -I 2000",
+
+ Path + "malloc " + Opts + " -N mallocT2_10 -s 10 -g 10 -T 2 -I 200",
+ Path + "malloc " + Opts + " -N mallocT2_100 -s 100 -g 10 -T 2 -I 200",
+ Path + "malloc " + Opts + " -N mallocT2_1k -s 1k -g 10 -T 2 -I 200",
+ Path + "malloc " + Opts + " -N mallocT2_10k -s 10k -g 10 -T 2 -I 200",
+ Path + "malloc " + Opts + " -N mallocT2_100k -s 100k -g 10 -T 2 -I 10000",
+
+ Path + "close " + Opts + " -N close_bad -B 32 -b",
+// Path + "close " + Opts + " -N close_tmp -B 32 -f $TFILE",
+// Path + "close " + Opts + " -N close_usr -B 32 -f $VFILE",
+ Path + "close " + Opts + " -N close_zero -B 32 -f /dev/zero",
+
+ Path + "memcpy " + Opts + " -N memcpy_10 -s 10 -I 10 ",
+ Path + "memcpy " + Opts + " -N memcpy_1k -s 1k -I 50",
+ Path + "memcpy " + Opts + " -N memcpy_10k -s 10k -I 800",
+// Path + "memcpy " + Opts + " -N memcpy_1m -s 1m -I 500000",
+// Path + "memcpy " + Opts + " -N memcpy_10m -s 10m -I 5000000",
+
+ Path + "strcpy " + Opts + " -N strcpy_10 -s 10 -I 5 ",
+ Path + "strcpy " + Opts + " -N strcpy_1k -s 1k -I 100",
+
+ Path + "strlen " + Opts + " -N strlen_10 -s 10 -I 5",
+ Path + "strlen " + Opts + " -N strlen_1k -s 1k -I 100",
+
+ Path + "strchr " + Opts + " -N strchr_10 -s 10 -I 5",
+ Path + "strchr " + Opts + " -N strchr_1k -s 1k -I 200",
+ Path + "strcmp " + Opts + " -N strcmp_10 -s 10 -I 10",
+ Path + "strcmp " + Opts + " -N strcmp_1k -s 1k -I 200",
+
+ Path + "strcasecmp " + Opts + " -N scasecmp_10 -s 10 -I 50",
+ Path + "strcasecmp " + Opts + " -N scasecmp_1k -s 1k -I 20000",
+
+ Path + "strtol " + Opts + " -N strtol -I 20 ",
+
+ Path + "mutex " + Opts + " -N mutex_st -I 10",
+ Path + "mutex " + Opts + " -N mutex_mt -t -I 10 ",
+ Path + "mutex " + Opts + " -N mutex_T2 -T 2 -I 100",
+
+// Path + "longjmp " + Opts + " -N longjmp -I 10",
+// Path + "siglongjmp " + Opts + " -N siglongjmp -I 20",
+
+ Path + "getrusage " + Opts + " -N getrusage -I 200",
+
+ Path + "times " + Opts + " -N times -I 200",
+ Path + "time " + Opts + " -N time -I 50",
+ Path + "localtime_r " + Opts + " -N localtime_r -I 200 ",
+ Path + "strftime " + Opts + " -N strftime -I 10000 ",
+
+ Path + "mktime " + Opts + " -N mktime -I 500 ",
+ Path + "mktime " + Opts + " -N mktimeT2 -T 2 -I 1000 ",
+
+// Path + "cascade_mutex " + Opts + " -N c_mutex_1 -I 50",
+// Path + "cascade_mutex " + Opts + " -N c_mutex_10 -T 10 -I 5000",
+// Path + "cascade_mutex " + Opts + " -N c_mutex_200 -T 200 -I 2000000",
+
+// Path + "cascade_cond " + Opts + " -N c_cond_1 -I 100",
+// Path + "cascade_cond " + Opts + " -N c_cond_10 -T 10 -I 3000",
+// Path + "cascade_cond " + Opts + " -N c_cond_200 -T 200 -I 2000000",
+
+ Path + "cascade_flock " + Opts + " -N c_flock -I 1000 ",
+ Path + "cascade_flock " + Opts + " -N c_flock_10 -P 10 -I 50000",
+ Path + "cascade_flock " + Opts + " -N c_flock_200 -P 200 -I 5000000",
+
+ Path + "cascade_fcntl " + Opts + " -N c_fcntl_1 -I 2000 ",
+ Path + "cascade_fcntl " + Opts + " -N c_fcntl_10 -P 10 -I 20000",
+ Path + "cascade_fcntl " + Opts + " -N c_fcntl_200 -P 200 -I 5000000",
+
+ Path + "file_lock " + Opts + " -N file_lock -I 1000 ",
+
+ Path + "getsockname " + Opts + " -N getsockname -I 100",
+ Path + "getpeername " + Opts + " -N getpeername -I 100",
+
+// Path + "chdir " + Opts + " -N chdir_tmp -I 2000 $TDIR1 $TDIR2",
+// Path + "chdir " + Opts + " -N chdir_usr -I 2000 $VDIR1 $VDIR2",
+//
+// Path + "chdir " + Opts + " -N chgetwd_tmp -I 3000 -g $TDIR1 $TDIR2",
+// Path + "chdir " + Opts + " -N chgetwd_usr -I 3000 -g $VDIR1 $VDIR2",
+//
+// Path + "realpath " + Opts + " -N realpath_tmp -I 3000 -f $TDIR1",
+// Path + "realpath " + Opts + " -N realpath_usr -I 3000 -f $VDIR1",
+//
+// Path + "stat " + Opts + " -N stat_tmp -I 1000 -f $TFILE",
+// Path + "stat " + Opts + " -N stat_usr -I 1000 -f $VFILE",
+
+// Path + "fcntl " + Opts + " -N fcntl_tmp -I 100 -f $TFILE",
+// Path + "fcntl " + Opts + " -N fcntl_usr -I 100 -f $VFILE",
+ Path + "fcntl_ndelay " + Opts + " -N fcntl_ndelay -I 100 ",
+
+// Path + "lseek " + Opts + " -N lseek_t8k -s 8k -I 50 -f $TFILE",
+// Path + "lseek " + Opts + " -N lseek_u8k -s 8k -I 50 -f $VFILE",
+
+// Path + "open " + Opts + " -N open_tmp -B 256 -f $TFILE",
+// Path + "open " + Opts + " -N open_usr -B 256 -f $VFILE",
+ Path + "open " + Opts + " -N open_zero -B 256 -f /dev/zero",
+
+ Path + "dup " + Opts + " -N dup -B 512 ",
+
+ Path + "socket " + Opts + " -N socket_u -B 256",
+ Path + "socket " + Opts + " -N socket_i -B 256 -f PF_INET",
+
+ Path + "socketpair " + Opts + " -N socketpair -B 256",
+
+ Path + "setsockopt " + Opts + " -N setsockopt -I 200",
+
+ Path + "bind " + Opts + " -N bind -B 100",
+
+ Path + "listen " + Opts + " -N listen -B 100",
+
+// Path + "connection " + Opts + " -N connection -B 256 ",
+
+ Path + "poll " + Opts + " -N poll_10 -n 10 -I 500",
+ Path + "poll " + Opts + " -N poll_100 -n 100 -I 1000",
+ Path + "poll " + Opts + " -N poll_1000 -n 1000 -I 5000",
+
+ Path + "poll " + Opts + " -N poll_w10 -n 10 -I 500 -w 1",
+ Path + "poll " + Opts + " -N poll_w100 -n 100 -I 2000 -w 10",
+ Path + "poll " + Opts + " -N poll_w1000 -n 1000 -I 40000 -w 100",
+
+ Path + "select " + Opts + " -N select_10 -n 10 -I 500",
+ Path + "select " + Opts + " -N select_100 -n 100 -I 1000",
+ Path + "select " + Opts + " -N select_1000 -n 1000 -I 5000",
+
+ Path + "select " + Opts + " -N select_w10 -n 10 -I 500 -w 1",
+ Path + "select " + Opts + " -N select_w100 -n 100 -I 2000 -w 10",
+ Path + "select " + Opts + " -N select_w1000 -n 1000 -I 40000 -w 100",
+
+ Path + "sigaction " + Opts + " -N sigaction -I 100",
+ Path + "signal " + Opts + " -N signal -I 1000",
+ Path + "sigprocmask " + Opts + " -N sigprocmask -I 200",
+
+ Path + "pthread_create " + Opts + " -N pthread_8 -B 8",
+ Path + "pthread_create " + Opts + " -N pthread_32 -B 32",
+ Path + "pthread_create " + Opts + " -N pthread_128 -B 128",
+// Path + "pthread_create " + Opts + " -N pthread_512 -B 512",
+
+ Path + "fork " + Opts + " -N fork_10 -B 10",
+ Path + "fork " + Opts + " -N fork_100 -B 100 -C 100",
+// Path + "fork " + Opts + " -N fork_1000 -B 1000 -C 50",
+
+ Path + "exit " + Opts + " -N exit_10 -B 10",
+ Path + "exit " + Opts + " -N exit_100 -B 100",
+// Path + "exit " + Opts + " -N exit_1000 -B 1000 -C 50",
+
+ Path + "exit " + Opts + " -N exit_10_nolibc -e -B 10",
+
+ Path + "exec " + Opts + " -N exec -B 10",
+
+ Path + "system " + Opts + " -N system -I 1000000",
+
+ Path + "recurse " + Opts + " -N recurse -B 512",
+
+// Path + "read " + Opts + " -N read_t1k -s 1k -f $TFILE",
+// Path + "read " + Opts + " -N read_t10k -s 10k -f $TFILE",
+// Path + "read " + Opts + " -N read_t100k -s 100k -f $TFILE",
+
+// Path + "read " + Opts + " -N read_u1k -s 1k -f $VFILE",
+// Path + "read " + Opts + " -N read_u10k -s 10k -f $VFILE",
+// Path + "read " + Opts + " -N read_u100k -s 100k -f $VFILE",
+
+ Path + "read " + Opts + " -N read_z1k -s 1k -f /dev/zero ",
+ Path + "read " + Opts + " -N read_z10k -s 10k -f /dev/zero ",
+ Path + "read " + Opts + " -N read_z100k -s 100k -f /dev/zero ",
+ Path + "read " + Opts + " -N read_zw100k -s 100k -w -f /dev/zero ",
+
+// Path + "write " + Opts + " -N write_t1k -s 1k -f $TFILE",
+// Path + "write " + Opts + " -N write_t10k -s 10k -f $TFILE",
+// Path + "write " + Opts + " -N write_t100k -s 100k -f $TFILE",
+
+// Path + "write " + Opts + " -N write_u1k -s 1k -f $VFILE",
+// Path + "write " + Opts + " -N write_u10k -s 10k -f $VFILE",
+// Path + "write " + Opts + " -N write_u100k -s 100k -f $VFILE",
+
+ Path + "write " + Opts + " -N write_n1k -s 1k -I 100 -B 0 -f /dev/null ",
+ Path + "write " + Opts + " -N write_n10k -s 10k -I 100 -B 0 -f /dev/null ",
+ Path + "write " + Opts + " -N write_n100k -s 100k -I 100 -B 0 -f /dev/null ",
+
+// Path + "writev " + Opts + " -N writev_t1k -s 1k -f $TFILE",
+// Path + "writev " + Opts + " -N writev_t10k -s 10k -f $TFILE",
+// Path + "writev " + Opts + " -N writev_t100k -s 100k -f $TFILE",
+
+// Path + "writev " + Opts + " -N writev_u1k -s 1k -f $VFILE",
+// Path + "writev " + Opts + " -N writev_u10k -s 10k -f $VFILE",
+// Path + "writev " + Opts + " -N writev_u100k -s 100k -f $VFILE",
+
+ Path + "writev " + Opts + " -N writev_n1k -s 1k -I 100 -B 0 -f /dev/null ",
+ Path + "writev " + Opts + " -N writev_n10k -s 10k -I 100 -B 0 -f /dev/null ",
+ Path + "writev " + Opts + " -N writev_n100k -s 100k -I 100 -B 0 -f /dev/null ",
+
+// Path + "pread " + Opts + " -N pread_t1k -s 1k -I 300 -f $TFILE",
+// Path + "pread " + Opts + " -N pread_t10k -s 10k -I 1000 -f $TFILE",
+// Path + "pread " + Opts + " -N pread_t100k -s 100k -I 10000 -f $TFILE",
+
+// Path + "pread " + Opts + " -N pread_u1k -s 1k -I 300 -f $VFILE",
+// Path + "pread " + Opts + " -N pread_u10k -s 10k -I 1000 -f $VFILE",
+// Path + "pread " + Opts + " -N pread_u100k -s 100k -I 10000 -f $VFILE",
+
+ Path + "pread " + Opts + " -N pread_z1k -s 1k -I 300 -f /dev/zero ",
+ Path + "pread " + Opts + " -N pread_z10k -s 10k -I 1000 -f /dev/zero ",
+ Path + "pread " + Opts + " -N pread_z100k -s 100k -I 2000 -f /dev/zero ",
+ Path + "pread " + Opts + " -N pread_zw100k -s 100k -w -I 10000 -f /dev/zero ",
+
+// Path + "pwrite " + Opts + " -N pwrite_t1k -s 1k -I 500 -f $TFILE",
+// Path + "pwrite " + Opts + " -N pwrite_t10k -s 10k -I 1000 -f $TFILE",
+// Path + "pwrite " + Opts + " -N pwrite_t100k -s 100k -I 10000 -f $TFILE",
+
+// Path + "pwrite " + Opts + " -N pwrite_u1k -s 1k -I 500 -f $VFILE",
+// Path + "pwrite " + Opts + " -N pwrite_u10k -s 10k -I 1000 -f $VFILE",
+// Path + "pwrite " + Opts + " -N pwrite_u100k -s 100k -I 20000 -f $VFILE",
+
+ Path + "pwrite " + Opts + " -N pwrite_n1k -s 1k -I 100 -f /dev/null ",
+ Path + "pwrite " + Opts + " -N pwrite_n10k -s 10k -I 100 -f /dev/null ",
+ Path + "pwrite " + Opts + " -N pwrite_n100k -s 100k -I 100 -f /dev/null ",
+
+ Path + "mmap " + Opts + " -N mmap_z8k -l 8k -I 1000 -f /dev/zero",
+ Path + "mmap " + Opts + " -N mmap_z128k -l 128k -I 2000 -f /dev/zero",
+// Path + "mmap " + Opts + " -N mmap_t8k -l 8k -I 1000 -f $TFILE",
+// Path + "mmap " + Opts + " -N mmap_t128k -l 128k -I 1000 -f $TFILE",
+// Path + "mmap " + Opts + " -N mmap_u8k -l 8k -I 1000 -f $VFILE",
+// Path + "mmap " + Opts + " -N mmap_u128k -l 128k -I 1000 -f $VFILE",
+ Path + "mmap " + Opts + " -N mmap_a8k -l 8k -I 200 -f MAP_ANON",
+ Path + "mmap " + Opts + " -N mmap_a128k -l 128k -I 200 -f MAP_ANON",
+
+
+ Path + "mmap " + Opts + " -N mmap_rz8k -l 8k -I 2000 -r -f /dev/zero",
+ Path + "mmap " + Opts + " -N mmap_rz128k -l 128k -I 2000 -r -f /dev/zero",
+// Path + "mmap " + Opts + " -N mmap_rt8k -l 8k -I 2000 -r -f $TFILE",
+// Path + "mmap " + Opts + " -N mmap_rt128k -l 128k -I 20000 -r -f $TFILE",
+// Path + "mmap " + Opts + " -N mmap_ru8k -l 8k -I 2000 -r -f $VFILE",
+ Path + "mmap " + Opts + " -N mmap_ru128k -l 128k -I 20000 -r -f $VFILE",
+ Path + "mmap " + Opts + " -N mmap_ra8k -l 8k -I 2000 -r -f MAP_ANON",
+ Path + "mmap " + Opts + " -N mmap_ra128k -l 128k -I 20000 -r -f MAP_ANON",
+
+ Path + "mmap " + Opts + " -N mmap_wz8k -l 8k -I 5000 -w -f /dev/zero",
+ Path + "mmap " + Opts + " -N mmap_wz128k -l 128k -I 50000 -w -f /dev/zero",
+// Path + "mmap " + Opts + " -N mmap_wt8k -l 8k -I 5000 -w -f $TFILE",
+// Path + "mmap " + Opts + " -N mmap_wt128k -l 128k -I 50000 -w -f $TFILE",
+// Path + "mmap " + Opts + " -N mmap_wu8k -l 8k -I 5000 -w -f $VFILE",
+// Path + "mmap " + Opts + " -N mmap_wu128k -l 128k -I 500000 -w -f $VFILE",
+ Path + "mmap " + Opts + " -N mmap_wa8k -l 8k -I 3000 -w -f MAP_ANON",
+ Path + "mmap " + Opts + " -N mmap_wa128k -l 128k -I 50000 -w -f MAP_ANON",
+
+ Path + "munmap " + Opts + " -N unmap_z8k -l 8k -I 500 -f /dev/zero",
+ Path + "munmap " + Opts + " -N unmap_z128k -l 128k -I 500 -f /dev/zero",
+// Path + "munmap " + Opts + " -N unmap_t8k -l 8k -I 500 -f $TFILE",
+// Path + "munmap " + Opts + " -N unmap_t128k -l 128k -I 500 -f $TFILE",
+// Path + "munmap " + Opts + " -N unmap_u8k -l 8k -I 500 -f $VFILE",
+// Path + "munmap " + Opts + " -N unmap_u128k -l 128k -I 500 -f $VFILE",
+ Path + "munmap " + Opts + " -N unmap_a8k -l 8k -I 500 -f MAP_ANON",
+ Path + "munmap " + Opts + " -N unmap_a128k -l 128k -I 500 -f MAP_ANON",
+
+ Path + "munmap " + Opts + " -N unmap_rz8k -l 8k -I 1000 -r -f /dev/zero",
+ Path + "munmap " + Opts + " -N unmap_rz128k -l 128k -I 2000 -r -f /dev/zero",
+// Path + "munmap " + Opts + " -N unmap_rt8k -l 8k -I 1000 -r -f $TFILE",
+// Path + "munmap " + Opts + " -N unmap_rt128k -l 128k -I 3000 -r -f $TFILE",
+// Path + "munmap " + Opts + " -N unmap_ru8k -l 8k -I 1000 -r -f $VFILE",
+// Path + "munmap " + Opts + " -N unmap_ru128k -l 128k -I 3000 -r -f $VFILE",
+ Path + "munmap " + Opts + " -N unmap_ra8k -l 8k -I 1000 -r -f MAP_ANON",
+ Path + "munmap " + Opts + " -N unmap_ra128k -l 128k -I 2000 -r -f MAP_ANON",
+
+// Path + "connection " + Opts + " -N conn_connect -B 256 -c",
+
+ Path + "munmap " + Opts + " -N unmap_wz8k -l 8k -I 1000 -w -f /dev/zero",
+ Path + "munmap " + Opts + " -N unmap_wz128k -l 128k -I 8000 -w -f /dev/zero",
+// Path + "munmap " + Opts + " -N unmap_wt8k -l 8k -I 1000 -w -f $TFILE",
+// Path + "munmap " + Opts + " -N unmap_wt128k -l 128k -I 10000 -w -f $TFILE",
+// Path + "munmap " + Opts + " -N unmap_wu8k -l 8k -I 1000 -w -f $VFILE",
+// Path + "munmap " + Opts + " -N unmap_wu128k -l 128k -I 50000 -w -f $VFILE",
+ Path + "munmap " + Opts + " -N unmap_wa8k -l 8k -I 1000 -w -f MAP_ANON",
+ Path + "munmap " + Opts + " -N unmap_wa128k -l 128k -I 10000 -w -f MAP_ANON",
+
+
+ Path + "mprotect " + Opts + " -N mprot_z8k -l 8k -I 300 -f /dev/zero",
+ Path + "mprotect " + Opts + " -N mprot_z128k -l 128k -I 500 -f /dev/zero",
+ Path + "mprotect " + Opts + " -N mprot_wz8k -l 8k -I 500 -w -f /dev/zero",
+ Path + "mprotect " + Opts + " -N mprot_wz128k -l 128k -I 1000 -w -f /dev/zero",
+ Path + "mprotect " + Opts + " -N mprot_twz8k -l 8k -I 1000 -w -t -f /dev/zero",
+ Path + "mprotect " + Opts + " -N mprot_tw128k -l 128k -I 2000 -w -t -f /dev/zero",
+ Path + "mprotect " + Opts + " -N mprot_tw4m -l 4m -w -t -B 1 -f /dev/zero",
+
+ Path + "pipe " + Opts + " -N pipe_pst1 -s 1 -I 1000 -x pipe -m st",
+ Path + "pipe " + Opts + " -N pipe_pmt1 -s 1 -I 8000 -x pipe -m mt",
+ Path + "pipe " + Opts + " -N pipe_pmp1 -s 1 -I 8000 -x pipe -m mp",
+ Path + "pipe " + Opts + " -N pipe_pst4k -s 4k -I 1000 -x pipe -m st",
+ Path + "pipe " + Opts + " -N pipe_pmt4k -s 4k -I 8000 -x pipe -m mt",
+ Path + "pipe " + Opts + " -N pipe_pmp4k -s 4k -I 8000 -x pipe -m mp",
+
+ Path + "pipe " + Opts + " -N pipe_sst1 -s 1 -I 1000 -x sock -m st",
+ Path + "pipe " + Opts + " -N pipe_smt1 -s 1 -I 8000 -x sock -m mt",
+ Path + "pipe " + Opts + " -N pipe_smp1 -s 1 -I 8000 -x sock -m mp",
+ Path + "pipe " + Opts + " -N pipe_sst4k -s 4k -I 1000 -x sock -m st",
+ Path + "pipe " + Opts + " -N pipe_smt4k -s 4k -I 8000 -x sock -m mt",
+ Path + "pipe " + Opts + " -N pipe_smp4k -s 4k -I 8000 -x sock -m mp",
+
+ Path + "pipe " + Opts + " -N pipe_tst1 -s 1 -I 1000 -x tcp -m st",
+ Path + "pipe " + Opts + " -N pipe_tmt1 -s 1 -I 8000 -x tcp -m mt",
+ Path + "pipe " + Opts + " -N pipe_tmp1 -s 1 -I 8000 -x tcp -m mp",
+ Path + "pipe " + Opts + " -N pipe_tst4k -s 4k -I 1000 -x tcp -m st",
+ Path + "pipe " + Opts + " -N pipe_tmt4k -s 4k -I 8000 -x tcp -m mt",
+ Path + "pipe " + Opts + " -N pipe_tmp4k -s 4k -I 8000 -x tcp -m mp",
+
+// Path + "connection " + Opts + " -N conn_accept -B 256 -a",
+
+ Path + "close_tcp " + Opts + " -N close_tcp -B 32 "
+
+ );
+
+
+ @Override
+ protected String getTag() {
+ return "Native Micro";
+ };
+ protected final List<String> getCommands() {
+ return COMMANDS;
+ }
+
+ @Override
+ protected boolean saveResult(Intent intent) {
+ Bundle bundle = new Bundle();
+// StringBuilder report = new StringBuilder();
+ for (String command: getCommands()) {
+// report.append(mStdErrs.get(command));
+// report.append("---------------------------\n");
+// report.append(mStdOuts.get(command));
+// report.append("---------------------------\n");
+ if(!mSockets.containsKey(command))
+ continue;
+ String [] lines = mSockets.get(command).trim().split("\n");
+ String name = lines[0].trim().split("\t")[0];
+ StringBuilder list = new StringBuilder();;
+ for(String line: lines) {
+ String [] sp = line.trim().split("\t");
+ if (sp.length != 2) {
+ Log.w(TAG, "error line: " + line.trim());
+ continue;
+ }
+ if(!name.equals(sp[0]))
+ Log.i(TAG, "Incompatible bench name in socket out: " + name + " v.s. " + sp[0]);
+
+ //TODO changing from string to float will use up too much memory
+ // causing outOfMemory exception.
+ // should save in string format to bundle. easier to generate xml, too.
+ try {
+ int toInt = (int)Float.parseFloat(sp[1]);
+ list.append(toInt + " ");
+ } catch (Exception e) { // error format
+ Log.e(TAG, "cannot parse '" + sp[1] + "' in line: " + line);
+ continue;
+ }
+ }
+ bundle.putString(command+"S", name);
+ bundle.putString(command+"FA", list.toString().trim());
+
+ }
+// bundle.putString(REPORT, report.toString());
+ intent.putExtra(RESULT, bundle);
+ return true;
+ }
+}
diff --git a/src/org/zeroxlab/arithmetic/LinpackLoop.java b/src/org/zeroxlab/arithmetic/LinpackLoop.java
new file mode 100644
index 0000000..fc036ce
--- /dev/null
+++ b/src/org/zeroxlab/arithmetic/LinpackLoop.java
@@ -0,0 +1,577 @@
+package org.zeroxlab.arithmetic;
+
+import org.zeroxlab.benchmark.TesterArithmetic;
+import android.os.Bundle;
+import android.util.Log;
+
+/*
+
+Reformatted by Jonathan Hardwick (jch@cs.cmu.edu), 3/28/96
+Run benchmark 10 times to decrease effects of timer granularity, 10/20/96
+Compare to LinpackLoopOpt.java.
+See http://www.cs.cmu.edu/~jch/java/linpack.html for details
+
+
+Ported to Java by Reed Wade (wade@cs.utk.edu) 2/96
+built using JDK 1.0 on solaris
+using "javac -O Linpack.java"
+
+
+Translated to C by Bonnie Toy 5/88
+ (modified on 2/25/94 to fix a problem with daxpy for
+ unequal increments or equal increments not equal to 1.
+ Jack Dongarra)
+
+*/
+
+import android.util.*;
+
+public class LinpackLoop {
+
+ static Bundle mInfo;
+
+ public static String main(Bundle info) {
+ LinpackLoop l = new LinpackLoop();
+ mInfo = info;
+ return l.run_benchmark();
+ }
+
+ double second_orig = -1;
+ double second() {
+ if (second_orig==-1) {
+ second_orig = System.currentTimeMillis();
+ }
+ return (System.currentTimeMillis() - second_orig)/1000;
+ }
+
+ public String run_benchmark () {
+ double a[][] = new double[200][201];
+ double b[] = new double[200];
+ double x[] = new double[200];
+ double cray,ops,total,norma,normx;
+ double resid,time;
+ double kf;
+ int n,i,ntimes,info,lda,ldaa,kflops;
+ int ipvt[] = new int[200];
+
+ double mflops_result;
+ double residn_result;
+ double time_result;
+ double eps_result;
+
+ lda = 201;
+ ldaa = 200;
+ cray = .056;
+ n = 100;
+
+ ops = (2.0e0*(n*n*n))/3.0 + 2.0*(n*n);
+
+ norma = matgen(a,lda,n,b);
+ time = second();
+ for (i = 0; i < 10; i++) {
+ info = dgefa(a,lda,n,ipvt);
+ dgesl(a,lda,n,ipvt,b,0);
+ }
+ total = (second() - time) / 10.0D;
+
+ for (i = 0; i < n; i++) {
+ x[i] = b[i];
+ }
+ norma = matgen(a,lda,n,b);
+ for (i = 0; i < n; i++) {
+ b[i] = -b[i];
+ }
+ dmxpy(n,b,n,lda,x,a);
+ resid = 0.0;
+ normx = 0.0;
+ for (i = 0; i < n; i++) {
+ resid = (resid > Math.abs((double)b[i]))
+ ? resid : Math.abs((double)b[i]);
+ normx = (normx > Math.abs((double)x[i]))
+ ? normx : Math.abs((double)x[i]);
+ }
+
+ eps_result = epslon((double)1.0);
+ residn_result = resid/( n*norma*normx*eps_result );
+ time_result = total;
+ mflops_result = ops/(1.0e6*total);
+
+ mInfo.putDouble(TesterArithmetic.MFLOPS, mflops_result);
+ mInfo.putDouble(TesterArithmetic.RESIDN, residn_result);
+ mInfo.putDouble(TesterArithmetic.TIME, time_result);
+ mInfo.putDouble(TesterArithmetic.EPS, eps_result);
+
+ Log.e("Benchmark", "Mflops/s: " + mflops_result +
+ " Time: " + time_result + " secs" +
+ " Norm Res: " + residn_result +
+ " Precision: " + eps_result);
+
+ return ("Mflops/s: " + mflops_result +
+ " Time: " + time_result + " secs" +
+ " Norm Res: " + residn_result +
+ " Precision: " + eps_result);
+ }
+
+ double matgen (double a[][], int lda, int n, double b[]) {
+ double norma;
+ int init, i, j;
+
+ init = 1325;
+ norma = 0.0;
+ /* Next two for() statements switched. Solver wants
+ matrix in column order. --dmd 3/3/97 --added to this source jch 3/7/97
+ */
+ for (i = 0; i < n; i++) {
+ for (j = 0; j < n; j++) {
+ init = 3125*init % 65536;
+ a[j][i] = (init - 32768.0)/16384.0;
+ norma = (a[j][i] > norma) ? a[j][i] : norma;
+ }
+ }
+ for (i = 0; i < n; i++) {
+ b[i] = 0.0;
+ }
+ for (j = 0; j < n; j++) {
+ for (i = 0; i < n; i++) {
+ b[i] = b[i] + a[j][i];
+ }
+ }
+
+ return norma;
+ }
+
+ /*
+ dgefa factors a double precision matrix by gaussian elimination.
+
+ dgefa is usually called by dgeco, but it can be called
+ directly with a saving in time if rcond is not needed.
+ (time for dgeco) = (1 + 9/n)*(time for dgefa) .
+
+ on entry
+
+ a double precision[n][lda]
+ the matrix to be factored.
+
+ lda integer
+ the leading dimension of the array a .
+
+ n integer
+ the order of the matrix a .
+
+ on return
+
+ a an upper triangular matrix and the multipliers
+ which were used to obtain it.
+ the factorization can be written a = l*u where
+ l is a product of permutation and unit lower
+ triangular matrices and u is upper triangular.
+
+ ipvt integer[n]
+ an integer vector of pivot indices.
+
+ info integer
+ = 0 normal value.
+ = k if u[k][k] .eq. 0.0 . this is not an error
+ condition for this subroutine, but it does
+ indicate that dgesl or dgedi will divide by zero
+ if called. use rcond in dgeco for a reliable
+ indication of singularity.
+
+ linpack. this version dated 08/14/78.
+ cleve moler, university of new mexico, argonne national lab.
+
+ functions
+
+ blas daxpy,dscal,idamax
+ */
+
+ int dgefa( double a[][], int lda, int n, int ipvt[]) {
+ double t;
+ int j,k,kp1,l,nm1;
+ int info;
+
+ // gaussian elimination with partial pivoting
+
+ info = 0;
+ nm1 = n - 1;
+ if (nm1 >= 0) {
+ for (k = 0; k < nm1; k++) {
+ kp1 = k + 1;
+
+ // find l = pivot index
+
+ l = idamax(n-k,a[k],k,1) + k;
+ ipvt[k] = l;
+
+ // zero pivot implies this column already triangularized
+
+ if (a[k][l] != 0) {
+
+ // interchange if necessary
+
+ if (l != k) {
+ t = a[k][l];
+ a[k][l] = a[k][k];
+ a[k][k] = t;
+ }
+
+ // compute multipliers
+
+ t = -1.0/a[k][k];
+ dscal(n-(k+1),t,a[k],k+1,1);
+
+ // row elimination with column indexing
+
+ for (j = kp1; j < n; j++) {
+ t = a[j][l];
+ if (l != k) {
+ a[j][l] = a[j][k];
+ a[j][k] = t;
+ }
+ daxpy(n-(k+1),t,a[k],k+1,1,
+ a[j],k+1,1);
+ }
+ }
+ else {
+ info = k;
+ }
+ }
+ }
+ ipvt[n-1] = n-1;
+ if (a[(n-1)][(n-1)] == 0) info = n-1;
+
+ return info;
+ }
+
+ /*
+ dgesl solves the double precision system
+ a * x = b or trans(a) * x = b
+ using the factors computed by dgeco or dgefa.
+
+ on entry
+
+ a double precision[n][lda]
+ the output from dgeco or dgefa.
+
+ lda integer
+ the leading dimension of the array a .
+
+ n integer
+ the order of the matrix a .
+
+ ipvt integer[n]
+ the pivot vector from dgeco or dgefa.
+
+ b double precision[n]
+ the right hand side vector.
+
+ job integer
+ = 0 to solve a*x = b ,
+ = nonzero to solve trans(a)*x = b where
+ trans(a) is the transpose.
+
+ on return
+
+ b the solution vector x .
+
+ error condition
+
+ a division by zero will occur if the input factor contains a
+ zero on the diagonal. technically this indicates singularity
+ but it is often caused by improper arguments or improper
+ setting of lda . it will not occur if the subroutines are
+ called correctly and if dgeco has set rcond .gt. 0.0
+ or dgefa has set info .eq. 0 .
+
+ to compute inverse(a) * c where c is a matrix
+ with p columns
+ dgeco(a,lda,n,ipvt,rcond,z)
+ if (!rcond is too small){
+ for (j=0,j<p,j++)
+ dgesl(a,lda,n,ipvt,c[j][0],0);
+ }
+
+ linpack. this version dated 08/14/78 .
+ cleve moler, university of new mexico, argonne national lab.
+
+ functions
+
+ blas daxpy,ddot
+ */
+
+ void dgesl( double a[][], int lda, int n, int ipvt[], double b[], int job) {
+ double t;
+ int k,kb,l,nm1;
+
+ nm1 = n - 1;
+ if (job == 0) {
+
+ // job = 0 , solve a * x = b. first solve l*y = b
+
+ if (nm1 >= 1) {
+ for (k = 0; k < nm1; k++) {
+ l = ipvt[k];
+ t = b[l];
+ if (l != k){
+ b[l] = b[k];
+ b[k] = t;
+ }
+ daxpy(n-(k+1),t,a[k],k+1,1,b,k+1,1);
+ }
+ }
+
+ // now solve u*x = y
+
+ for (kb = 0; kb < n; kb++) {
+ k = n - (kb + 1);
+ b[k] = b[k]/a[k][k];
+ t = -b[k];
+ daxpy(k,t,a[k],0,1,b,0,1);
+ }
+ }
+ else {
+
+ // job = nonzero, solve trans(a) * x = b. first solve trans(u)*y = b
+
+ for (k = 0; k < n; k++) {
+ t = ddot(k,a[k],0,1,b,0,1);
+ b[k] = (b[k] - t)/a[k][k];
+ }
+
+ // now solve trans(l)*x = y
+
+ if (nm1 >= 1) {
+ for (kb = 1; kb < nm1; kb++) {
+ k = n - (kb+1);
+ b[k] = b[k] + ddot(n-(k+1),a[k],k+1,1,b,k+1,1);
+ l = ipvt[k];
+ if (l != k) {
+ t = b[l];
+ b[l] = b[k];
+ b[k] = t;
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ constant times a vector plus a vector.
+ jack dongarra, linpack, 3/11/78.
+ */
+ void daxpy( int n, double da, double dx[], int dx_off, int incx,
+ double dy[], int dy_off, int incy) {
+ int i,ix,iy,m,mp1;
+
+ if ((n > 0) && (da != 0)) {
+ if (incx != 1 || incy != 1) {
+
+ // code for unequal increments or equal increments not equal to 1
+
+ ix = 0;
+ iy = 0;
+ if (incx < 0) ix = (-n+1)*incx;
+ if (incy < 0) iy = (-n+1)*incy;
+ for (i = 0;i < n; i++) {
+ dy[iy +dy_off] = dy[iy +dy_off] + da*dx[ix +dx_off];
+ ix = ix + incx;
+ iy = iy + incy;
+ }
+ return;
+ } else {
+
+ // code for both increments equal to 1
+
+ int _r = n % 4;
+ int _n = n - _r;
+
+ for (i = 0;i < _n; i+=4) {
+ dy[i +dy_off] = dy[i +dy_off] + da*dx[i +dx_off];
+ dy[i+1 +dy_off] = dy[i+1 +dy_off] + da*dx[i+1 +dx_off];
+ dy[i+2 +dy_off] = dy[i+2 +dy_off] + da*dx[i+2 +dx_off];
+ dy[i+3 +dy_off] = dy[i+3 +dy_off] + da*dx[i+3 +dx_off];
+ }
+ for (i=_n ;i < n; i++)
+ dy[i +dy_off] = dy[i +dy_off] + da*dx[i +dx_off];
+ }
+ }
+ }
+
+ /*
+ forms the dot product of two vectors.
+ jack dongarra, linpack, 3/11/78.
+ */
+ double ddot( int n, double dx[], int dx_off, int incx, double dy[],
+ int dy_off, int incy) {
+ double dtemp;
+ int i,ix,iy,m,mp1;
+
+ dtemp = 0;
+
+ if (n > 0) {
+
+ if (incx != 1 || incy != 1) {
+
+ // code for unequal increments or equal increments not equal to 1
+
+ ix = 0;
+ iy = 0;
+ if (incx < 0) ix = (-n+1)*incx;
+ if (incy < 0) iy = (-n+1)*incy;
+ for (i = 0;i < n; i++) {
+ dtemp = dtemp + dx[ix +dx_off]*dy[iy +dy_off];
+ ix = ix + incx;
+ iy = iy + incy;
+ }
+ } else {
+
+ // code for both increments equal to 1
+
+ for (i=0;i < n; i++)
+ dtemp = dtemp + dx[i +dx_off]*dy[i +dy_off];
+ }
+ }
+ return(dtemp);
+ }
+
+ /*
+ scales a vector by a constant.
+ jack dongarra, linpack, 3/11/78.
+ */
+ void dscal( int n, double da, double dx[], int dx_off, int incx) {
+ int i,m,mp1,nincx;
+
+ if (n > 0) {
+ if (incx != 1) {
+
+ // code for increment not equal to 1
+
+ nincx = n*incx;
+ for (i = 0; i < nincx; i = i + incx)
+ dx[i +dx_off] = da*dx[i +dx_off];
+ } else {
+
+ // code for increment equal to 1
+
+ for (i = 0; i < n; i++)
+ dx[i +dx_off] = da*dx[i +dx_off];
+ }
+ }
+ }
+
+ /*
+ finds the index of element having max. absolute value.
+ jack dongarra, linpack, 3/11/78.
+ */
+ int idamax( int n, double dx[], int dx_off, int incx) {
+ double dmax;
+ int i, ix, itemp=0;
+
+ if (n < 1) {
+ itemp = -1;
+ } else if (n ==1) {
+ itemp = 0;
+ } else if (incx != 1) {
+
+ // code for increment not equal to 1
+
+ ix = 1;
+ dmax = Math.abs((double)dx[0 +dx_off]);
+ ix = ix + incx;
+ for (i = 1; i < n; i++) {
+ if (Math.abs((double)dx[ix +dx_off]) > dmax) {
+ itemp = i;
+ dmax = Math.abs((double)dx[ix +dx_off]);
+ }
+ ix = ix + incx;
+ }
+ } else {
+
+ // code for increment equal to 1
+
+ itemp = 0;
+ dmax = Math.abs((double)dx[0 +dx_off]);
+ for (i = 1; i < n; i++) {
+ if (Math.abs((double)dx[i +dx_off]) > dmax) {
+ itemp = i;
+ dmax = Math.abs((double)dx[i +dx_off]);
+ }
+ }
+ }
+ return (itemp);
+ }
+
+ /*
+ estimate unit roundoff in quantities of size x.
+
+ this program should function properly on all systems
+ satisfying the following two assumptions,
+ 1. the base used in representing dfloating point
+ numbers is not a power of three.
+ 2. the quantity a in statement 10 is represented to
+ the accuracy used in dfloating point variables
+ that are stored in memory.
+ the statement number 10 and the go to 10 are intended to
+ force optimizing compilers to generate code satisfying
+ assumption 2.
+ under these assumptions, it should be true that,
+ a is not exactly equal to four-thirds,
+ b has a zero for its last bit or digit,
+ c is not exactly equal to one,
+ eps measures the separation of 1.0 from
+ the next larger dfloating point number.
+ the developers of eispack would appreciate being informed
+ about any systems where these assumptions do not hold.
+
+ *****************************************************************
+ this routine is one of the auxiliary routines used by eispack iii
+ to avoid machine dependencies.
+ *****************************************************************
+
+ this version dated 4/6/83.
+ */
+ double epslon (double x) {
+ double a,b,c,eps;
+
+ a = 4.0e0/3.0e0;
+ eps = 0;
+ while (eps == 0) {
+ b = a - 1.0;
+ c = b + b + b;
+ eps = Math.abs((double)(c-1.0));
+ }
+ return(eps*Math.abs((double)x));
+ }
+
+ /*
+ purpose:
+ multiply matrix m times vector x and add the result to vector y.
+
+ parameters:
+
+ n1 integer, number of elements in vector y, and number of rows in
+ matrix m
+
+ y double [n1], vector of length n1 to which is added
+ the product m*x
+
+ n2 integer, number of elements in vector x, and number of columns
+ in matrix m
+
+ ldm integer, leading dimension of array m
+
+ x double [n2], vector of length n2
+
+ m double [ldm][n2], matrix of n1 rows and n2 columns
+ */
+ void dmxpy ( int n1, double y[], int n2, int ldm, double x[], double m[][]) {
+ int j,i,jmin;
+
+ // cleanup odd vector
+ for (j = 0; j < n2; j++) {
+ for (i = 0; i < n1; i++) {
+ y[i] = (y[i]) + x[j]*m[j][i];
+ }
+ }
+ }
+}
diff --git a/src/org/zeroxlab/benchmark/Benchmark.java b/src/org/zeroxlab/benchmark/Benchmark.java
new file mode 100644
index 0000000..4e40007
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/Benchmark.java
@@ -0,0 +1,434 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import android.util.Log;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.os.Bundle;
+import android.os.*;
+import android.widget.*;
+import android.view.*;
+import android.content.*;
+import java.nio.*;
+import java.io.*;
+
+import java.util.LinkedList;
+import java.util.Arrays;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+import java.lang.StringBuffer;
+
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
+
+import android.os.SystemClock;
+import android.app.ProgressDialog;
+
+import org.opensolaris.hub.libmicro.*;
+
+import android.os.PowerManager;
+import android.os.PowerManager.WakeLock;
+
+import android.os.Environment;
+
+/* Construct a basic UI */
+public class Benchmark extends Activity implements View.OnClickListener {
+
+ public final static String TAG = "Benchmark";
+ public final static String PACKAGE = "org.zeroxlab.benchmark";
+
+ private final static File SDCARD = Environment.getExternalStorageDirectory();
+ private final static String mOutputFile = "0xBenchmark";
+
+ private static String mXMLResult;
+ private final static String mOutputXMLFile = "0xBenchmark.xml";
+
+ private Button mRun;
+ private Button mShow;
+ private CheckBox mCheckList[];
+ private TextView mDesc[];
+ private TextView mBannerInfo;
+
+ private ScrollView mScrollView;
+ private LinearLayout mLinearLayout;
+
+ LinkedList<Case> mCases;
+ boolean mTouchable = true;
+
+ private WakeLock mWakeLock;
+
+ @Override
+ protected void onDestroy() {
+ super.onPause();
+ mWakeLock.release();
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
+ mWakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, TAG);
+ mWakeLock.acquire();
+
+ setContentView(R.layout.main);
+ mCases = new LinkedList<Case>();
+ Case arith = new CaseArithmetic();
+ Case scimark2 = new CaseScimark2();
+ Case canvas = new CaseCanvas();
+ Case glcube = new CaseGLCube();
+ Case circle = new CaseDrawCircle();
+ Case nehe08 = new CaseNeheLesson08();
+ Case nehe16 = new CaseNeheLesson16();
+ Case teapot = new CaseTeapot();
+ Case gc = new CaseGC();
+ Case libMicro = new NativeCaseMicro();
+
+ // mflops
+ mCases.add(arith);
+ mCases.add(scimark2);
+ // 2d
+ mCases.add(canvas);
+ mCases.add(circle);
+ // 3d
+ mCases.add(glcube);
+ mCases.add(nehe08);
+ mCases.add(nehe16);
+ mCases.add(teapot);
+ // vm
+ mCases.add(gc);
+ // native
+ mCases.add(libMicro);
+
+ initViews();
+
+ Intent intent = getIntent();
+ if (intent.getBooleanExtra("AUTO", false)) {
+ ImageView head = (ImageView)findViewById(R.id.banner_img);
+ head.setImageResource(R.drawable.icon_auto);
+ mTouchable = false;
+ initAuto();
+ }
+
+ }
+
+ @Override
+ public boolean dispatchTouchEvent(MotionEvent event) {
+ if (mTouchable) super.dispatchTouchEvent(event);
+ return true;
+ }
+
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ if (mTouchable) super.dispatchKeyEvent(event);
+ return true;
+ }
+
+ @Override
+ public boolean dispatchTrackballEvent(MotionEvent event) {
+ if (mTouchable) super.dispatchTrackballEvent(event);
+ return true;
+ }
+
+ private void _checkTagCase(String [] Tags) {
+ Arrays.sort(Tags);
+ for (int i=0; i<mCheckList.length; i++) {
+ String [] caseTags = mCases.get(i).mTags;
+ for (String t: caseTags) {
+ int search = Arrays.binarySearch(Tags, t);
+ if ( search >= 0)
+ mCheckList[i].setChecked(true);
+ }
+ }
+ }
+
+ private void _checkCatCase(String [] Cats) {
+ Arrays.sort(Cats);
+ for (int i=0; i<mCheckList.length; i++) {
+ int search = Arrays.binarySearch(Cats, mCases.get(i).mType);
+ if ( search >= 0)
+ mCheckList[i].setChecked(true);
+ }
+ }
+
+ private void _checkAllCase(boolean check) {
+ for (int i=0; i<mCheckList.length; i++)
+ mCheckList[i].setChecked(check);
+ }
+
+ private void initAuto() {
+ Intent intent = getIntent();
+ String TAG = intent.getStringExtra("TAG");
+ String CAT = intent.getStringExtra("CAT");
+
+
+ _checkAllCase(false);
+ if (TAG != null)
+ _checkTagCase( TAG.split(",") );
+ if (CAT != null)
+ _checkCatCase( CAT.split(",") );
+ if (TAG == null && CAT == null)
+ _checkAllCase(true);
+ final Handler h = new Handler() {
+ public void handleMessage(Message msg) {
+ if (msg.what == 0x1234)
+ onClick(mRun);
+ }
+ };
+
+ final ProgressDialog dialog = new ProgressDialog(this).show(this, "Starting Benchmark", "Please wait...", true, false);
+ new Thread() {
+ public void run() {
+ SystemClock.sleep(1000);
+ dialog.dismiss();
+ Message m = new Message();
+ m.what = 0x1234;
+ h.sendMessage(m);
+ }
+ }.start();
+ mTouchable = true;
+ }
+
+ private void initViews() {
+ mRun = (Button)findViewById(R.id.btn_run);
+ mRun.setOnClickListener(this);
+
+ mShow = (Button)findViewById(R.id.btn_show);
+ mShow.setOnClickListener(this);
+ mShow.setClickable(false);
+
+ mLinearLayout = (LinearLayout)findViewById(R.id.list_container);
+
+ mBannerInfo = (TextView)findViewById(R.id.banner_info);
+ mBannerInfo.setText("Hello!\nSelect cases to Run.\nUploaded results:\nhttp://0xbenchmark.appspot.com");
+
+ int length = mCases.size();
+ mCheckList = new CheckBox[length];
+ mDesc = new TextView[length];
+ boolean gray = true;
+ for (int i = 0; i < length; i++) {
+ mCheckList[i] = new CheckBox(this);
+ mCheckList[i].setText(mCases.get(i).getTitle());
+ mLinearLayout.addView(mCheckList[i]);
+ mDesc[i] = new TextView(this);
+ mDesc[i].setText(mCases.get(i).getDescription());
+ mDesc[i].setTextSize(mDesc[i].getTextSize() - 2);
+ mDesc[i].setPadding(42, 0, 10, 10);
+ mLinearLayout.addView(mDesc[i]);
+
+ if (gray) {
+ int color = 0xFF333333; //ARGB
+ mCheckList[i].setBackgroundColor(color);
+ mDesc[i].setBackgroundColor(color);
+ }
+
+ gray = !gray;
+ }
+ }
+
+ public void onClick(View v) {
+ if (v == mRun) {
+ int numberOfCaseChecked = 0;
+ for (int i = 0; i < mCheckList.length; i++) {
+ if (mCheckList[i].isChecked()) {
+ mCases.get(i).reset();
+ numberOfCaseChecked++;
+ } else {
+ mCases.get(i).clear();
+ }
+ }
+ if(numberOfCaseChecked>0)
+ runCase(mCases);
+ } else if (v == mShow) {
+ String result = getResult();
+ Log.i(TAG,"\n\n"+result+"\n\n");
+ writeToSDCard(mOutputFile, result);
+ Intent intent = new Intent();
+ intent.putExtra(Report.REPORT, result);
+ intent.putExtra(Report.XML, mXMLResult);
+ intent.setClassName(Report.packageName(), Report.fullClassName());
+ startActivity(intent);
+ }
+ }
+
+ public void runCase(LinkedList<Case> list) {
+ Case pointer = null;
+ boolean finish = true;
+ for (int i = 0; i < list.size(); i++) {
+ pointer = list.get(i);
+ if (!pointer.isFinish()) {
+ finish = false;
+ break;
+ }
+ }
+
+ if (finish) {
+ mBannerInfo.setText("Benchmarking complete.\nClick Show to upload.\nUploaded results:\nhttp://0xbenchmark.appspot.com");
+ String result = getResult();
+ writeToSDCard(mOutputFile, result);
+
+ final ProgressDialog dialogGetXml = new ProgressDialog(this).show(this, "Generating XML Report", "Please wait...", true, false);
+ new Thread() {
+ public void run() {
+ mXMLResult = getXMLResult();
+ Log.e(TAG, "XML: " + mXMLResult);
+ writeToSDCard(mOutputXMLFile, mXMLResult);
+ mShow.setClickable(true);
+ onClick(mShow);
+ mTouchable = true;
+ dialogGetXml.dismiss();
+ }
+ }.start();
+ } else {
+ Intent intent = pointer.generateIntent();
+ if (intent != null) {
+ startActivityForResult(intent, 0);
+ }
+ }
+ }
+
+ public String getXMLResult() {
+ if (mCases.size() == 0)
+ return "";
+
+ Date date = new Date();
+ //2010-05-28T17:40:25CST
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
+
+ String xml = "";
+ xml += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
+ xml += "<result";
+ xml += " executedTimestamp=\"" + sdf.format(date) + "\"";
+ xml += " manufacturer=\"" + Build.MANUFACTURER.replace(' ', '_') + "\"";
+ xml += " model=\"" + Build.MODEL.replace(' ', '_') + ":" + Build.DISPLAY + "\"";
+ xml += " buildTimestamp=\"" + sdf.format(new Date(Build.TIME)) + "\"";
+
+ try { // read kernel version
+ BufferedReader procVersion = new BufferedReader( new FileReader("/proc/version") );
+ StringBuffer sbuff = new StringBuffer();
+ String tmp;
+ while ( (tmp = procVersion.readLine()) != null)
+ sbuff.append(tmp);
+ procVersion.close();
+ tmp = sbuff.toString().replace("[\n\r]+", " ").replace(" +", ".");
+ xml += " version=\"" + tmp + "\"";
+ } catch (IOException e){
+ Log.e(TAG, "opening /proc/version failed: " + e.toString());
+ }
+
+ try { // read and parse cpu info
+ BufferedReader procVersion = new BufferedReader( new FileReader("/proc/cpuinfo") );
+ StringBuffer sbuff = new StringBuffer();
+ String tmp;
+ while ( (tmp = procVersion.readLine()) != null)
+ sbuff.append(tmp + "\n");
+ procVersion.close();
+
+ tmp = sbuff.toString();
+
+ sbuff = new StringBuffer();
+
+ Pattern p1 = Pattern.compile("(Processor\\s*:\\s*(.*)\\s*[\n\r]+)");
+ Matcher m1 = p1.matcher(tmp);
+ if (m1.find()) sbuff.append(m1.group(2));
+
+ Pattern p2 = Pattern.compile("(Hardware\\s*:\\s*(.*)\\s*[\n\r]+)");
+ Matcher m2 = p2.matcher(tmp);
+ if (m2.find()) sbuff.append(":"+m2.group(2));
+
+ Pattern p3 = Pattern.compile("(Revision\\s*:\\s*(.*)\\s*[\n\r]+)");
+ Matcher m3 = p3.matcher(tmp);
+ if (m3.find()) sbuff.append(":"+m3.group(2));
+
+ Log.e(TAG, sbuff.toString());
+ xml += " cpu=\"" + sbuff.toString() + "\"";
+ } catch (IOException e){
+ Log.e(TAG, "opening /proc/version failed: " + e.toString());
+ }
+
+ xml += ">";
+
+ Case mycase;
+ for (int i = 0; i < mCases.size(); i++) {
+ mycase = mCases.get(i);
+ xml += mycase.getXMLBenchmark();
+ }
+
+ xml += "</result>";
+ return xml;
+ }
+
+ public String getResult() {
+ String result = "";
+ Case mycase;
+ for (int i = 0; i < mCases.size(); i++) {
+ mycase = mCases.get(i);
+ if ( !mycase.couldFetchReport() ) continue;
+ result += "============================================================\n";
+ result += mycase.getTitle() + "\n";
+ result += "------------------------------------------------------------\n";
+ result += mycase.getBenchmark().trim() + "\n";
+ }
+ result += "============================================================\n";
+
+ return result;
+ }
+
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (data == null) {
+ Log.i(TAG,"oooops....Intent is null");
+ return;
+ }
+
+ Case mycase;
+ for (int i = 0; i < mCases.size(); i++) {
+ mycase = mCases.get(i);
+ if (mycase.realize(data)) {
+ mycase.parseIntent(data);
+ break;
+ }
+ }
+ runCase(mCases);
+ }
+
+ private boolean writeToSDCard(String filename, String output) {
+ if ( !SDCARD.canWrite() ) {
+ Log.i(TAG, "Permission denied, maybe SDCARD mounted to PC?");
+ return false;
+ }
+
+ File file = new File(SDCARD, filename);
+
+ if (file.exists()) {
+ Log.i(TAG, "File exists, delete SDCARD/" + filename);
+ file.delete();
+ }
+
+ try {
+ file.createNewFile();
+ FileOutputStream fos = new FileOutputStream(file);
+ fos.write(output.getBytes());
+ fos.flush();
+ } catch (Exception e) {
+ Log.i(TAG, "Write Failed.");
+ e.printStackTrace();
+ return false;
+ }
+ return true;
+ }
+}
diff --git a/src/org/zeroxlab/benchmark/Case.java b/src/org/zeroxlab/benchmark/Case.java
new file mode 100644
index 0000000..ef78f17
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/Case.java
@@ -0,0 +1,305 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import android.util.Log;
+
+import android.os.SystemClock;
+
+import org.zeroxlab.benchmark.Scenario;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.*;
+import android.view.*;
+import java.nio.*;
+
+import java.util.ArrayList;
+
+public abstract class Case{
+ protected String TAG = "Case";
+
+ protected String PACKAGE = Benchmark.PACKAGE;
+ protected String TESTER;
+
+ /* If mRepeatMax = 3, mRepeatNow will count from 0 to 2*/
+ private int mRepeatMax = 1;
+ private int mRepeatNow;
+ protected boolean mInvolved;
+ protected long[] mResult;
+
+ private final static String SOURCE = "SOURCE";
+ private final static String INDEX = "INDEX";
+ private final static String RESULT = "RESULT";
+ private final static String ROUND = "ROUND";
+ protected int mCaseRound = 30;
+
+ public String mType = "";
+ public String[] mTags = {};
+
+ /**
+ * Constructor to generate instance.
+ *
+ * It defines the Case as "Please run Tester for N round, repeat N times"
+ * @param tag The tag name of the subclass Case. It is generally the Subclass Name
+ * @param tester The taget tester be used by subclass Case. It should be full class name.
+ * @param repeat The tester will run *repeat* times.
+ * @param round To tell tester to run itself as *round* round.
+ */
+ protected Case(String tag, String tester, int repeat, int round) {
+ TAG = tag;
+ TESTER = tester;
+ mRepeatMax = repeat;
+ mCaseRound = round;
+ reset();
+ }
+
+ abstract public String getDescription();
+ abstract public String getTitle();
+
+ abstract public ArrayList<Scenario> getScenarios ();
+
+
+ public final static void putRound(Intent intent, int round) {
+ intent.putExtra(ROUND, round);
+ }
+
+ public final static void putIndex(Intent intent, int index) {
+ intent.putExtra(INDEX, index);
+ }
+
+ public final static void putSource(Intent intent, String source) {
+ intent.putExtra(SOURCE, source);
+ }
+
+ public final static void putResult(Intent intent, long result) {
+ intent.putExtra(RESULT, result);
+ }
+
+ public final static int getRound(Intent intent) {
+ return intent.getIntExtra(ROUND, 100);
+ }
+
+ public final static int getIndex(Intent intent) {
+ return intent.getIntExtra(INDEX, -1);
+ }
+
+ public final static String getSource(Intent intent) {
+ String source = intent.getStringExtra(SOURCE);
+ if (source == null) {
+ return "unknown";
+ }
+
+ if (source.equals("")) {
+ return "unknown";
+ }
+
+ return source;
+ }
+
+ public final static long getResult(Intent intent) {
+ long defaultResult = -1;
+ return intent.getLongExtra(RESULT, defaultResult);
+ }
+
+ public String getTag() {
+ return TAG;
+ }
+
+ protected Intent generateIntent() {
+ /* if run out of the repeat times, go back directly */
+ if (mRepeatNow >= mRepeatMax) {
+ return null;
+ }
+
+ Intent intent = new Intent();
+ intent.setClassName(PACKAGE, TESTER);
+ Case.putRound(intent, mCaseRound);
+ Case.putSource(intent, TAG);
+ Case.putIndex(intent, mRepeatNow);
+
+ mRepeatNow = mRepeatNow + 1;
+
+ return intent;
+ }
+
+ public void clear() {
+ mResult = new long[mRepeatMax];
+ mRepeatNow = mRepeatMax; // no more repeating times
+ mInvolved = false;
+ }
+
+ /* Reset the repeat time to default value. clear result */
+ public void reset() {
+ mResult = new long[mRepeatMax];
+ mRepeatNow = 0;
+ mInvolved = true;
+ }
+
+ public boolean isFinish() {
+ /* If mRepeatMax = 3, mRepeatNow will count from 0 to 2*/
+ return (mRepeatNow >= mRepeatMax);
+ }
+
+ /** To read the SOURCE of this intent to see if this intent belong to this case
+ *
+ * @return return True if this intent belong to this case, otherwise return false
+ */
+ public boolean realize(Intent intent) {
+ if (intent == null) {
+ Log.i(TAG, "Intent is null");
+ return false;
+ }
+
+ String source = Case.getSource(intent);
+ if (source == null || source.equals("")) {
+ return false;
+ }
+
+ if (source.equals(TAG)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public boolean parseIntent(Intent intent) {
+ if (intent == null) {
+ Log.i(TAG, "Intent is null");
+ return false;
+ }
+
+ String tag = Case.getSource(intent);
+
+ if (tag == null || !tag.equals(TAG)) {
+ Log.i(TAG,"Unknown intent, cannot parse it");
+ return false;
+ }
+
+ int index = Case.getIndex(intent);
+ if (index >= mRepeatMax) {
+ Log.i(TAG,"Ooooops index >= mRepeatMax("+mRepeatMax+"), how come?");
+ return false;
+ }
+
+ return saveResult(intent, index);
+ }
+
+ /**
+ * To Save the result from Tester into this Case
+ * If subclass has its own way to analysis result, override this method
+ *
+ * @param intent The intent will be analysis
+ * @param index The repeating time of this intent. (Tester might repeat N times)
+ * @return return True if analysis sucessfully
+ */
+ protected boolean saveResult(Intent intent, int index) {
+ long result = Case.getResult(intent);
+
+ if (result == -1) {
+ Log.i(TAG,"Oooops! result is " + result);
+ return false;
+ }
+
+ mResult[index] = result;
+ return true;
+ }
+
+ public boolean couldFetchReport() {
+ if (!isFinish()) {
+ return false;
+ }
+
+ if (mInvolved == false) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public String getBenchmark() {
+
+ if (!couldFetchReport()) {
+ return "No benchmark report";
+ }
+
+ String result = "";
+ long total = 0;
+ int length = mResult.length;
+ for (int i = 0; i < length; i++) {
+ total += mResult[i];
+ result += "round " + i + ":" + mResult[i] + "\n";
+ }
+
+ result += "Average:" + (total/length) + "\n";
+ return result;
+ }
+
+ public String getXMLBenchmark() {
+ if (!couldFetchReport()) {
+ Log.e(TAG, "cannot fetch report: " + getTitle() + " : " + isFinish() + " : " + mInvolved);
+ return "";
+ }
+
+ String result = "";
+
+ ArrayList<Scenario> scenarios = getScenarios();
+ Log.e(TAG, "length of scenarios: " + scenarios.size());
+
+ for (Scenario s: scenarios) {
+ if (s == null){
+ Log.e(TAG, "Scenario is null");
+ continue;
+ }
+ String _result = "";
+ _result += "<scenario";
+ _result += " benchmark=\"" + s.mName.replace(" ", "") + "\"";
+ _result += " unit=\"" + s.mType + "\"";
+ _result += " tags=\"";
+ for (String tag: s.mTags)
+ _result += tag + ",";
+ _result += "\"";
+ _result += ">";
+ if(!s.useStringResults) {
+ Double total = 0.0;
+ for (Double value: s.mResults) {
+ _result += value + " ";
+ total += value;
+ }
+ _result += "</scenario>";
+ if (total == 0){
+ Log.e(TAG, "_result total is 0: ");
+ Log.e(TAG, _result);
+ continue;
+ }
+ } else {
+ if(s.mStringResults == null || s.mStringResults.length() == 0) {
+ Log.e(TAG, "string results is empty: " + s.mStringResults);
+ continue;
+ }
+ _result += s.mStringResults;
+ _result += "</scenario>";
+ }
+ result += _result;
+ }
+ return result;
+ }
+}
+
diff --git a/src/org/zeroxlab/benchmark/CaseArithmetic.java b/src/org/zeroxlab/benchmark/CaseArithmetic.java
new file mode 100644
index 0000000..4fb800b
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/CaseArithmetic.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import java.util.ArrayList;
+
+import android.util.Log;
+
+import android.os.SystemClock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+
+import org.zeroxlab.benchmark.TesterArithmetic;
+
+public class CaseArithmetic extends Case{
+
+ public static String LIN_RESULT = "LIN_RESULT";
+ protected Bundle mInfo[];
+
+ public static int Repeat = 1;
+ public static int Round = 3;
+
+ CaseArithmetic() {
+ super("CaseArithmetic", "org.zeroxlab.benchmark.TesterArithmetic", Repeat, Round);
+
+ mType = "mflops";
+ String [] _tmp = {
+ "numeric",
+ "mflops",
+ "scientific",
+ };
+ mTags = _tmp;
+
+ generateInfo();
+ }
+
+ public String getTitle() {
+ return "Linpack";
+ }
+
+ public String getDescription() {
+ return "The Linpack Benchmark is a numerically intensive test that has been used for years to measure the floating point performance of computers.";
+ }
+
+ private void generateInfo() {
+ mInfo = new Bundle[Repeat];
+ for (int i = 0; i < mInfo.length; i++) {
+ mInfo[i] = new Bundle();
+ }
+ }
+
+ @Override
+ public void clear() {
+ super.clear();
+ generateInfo();
+ }
+
+ @Override
+ public void reset() {
+ super.reset();
+ generateInfo();
+ }
+
+ @Override
+ public String getBenchmark() {
+ String result = "\n";
+ for (int i = 0; i < mInfo.length; i++) {
+ result += TesterArithmetic.bundleToString(mInfo[i]);
+ result += "\n";
+ }
+ return result;
+ }
+
+ @Override
+ public ArrayList<Scenario> getScenarios () {
+ ArrayList<Scenario> scenarios = new ArrayList<Scenario>();
+
+ Scenario s = new Scenario(getTitle(), mType, mTags);
+ s.mLog = getBenchmark();
+ for (int i=0; i<mInfo.length; i++)
+ s.mResults.add(mInfo[i].getDouble(TesterArithmetic.MFLOPS));
+
+ scenarios.add(s);
+
+ return scenarios;
+ }
+
+ @Override
+ protected boolean saveResult(Intent intent, int index) {
+ Bundle info = intent.getBundleExtra(LIN_RESULT);
+ if (info == null) {
+ Log.i(TAG, "Weird! cannot find LinpackInfo");
+ return false;
+ } else {
+ mInfo[index] = info;
+ }
+
+ return true;
+ }
+}
diff --git a/src/org/zeroxlab/benchmark/CaseCanvas.java b/src/org/zeroxlab/benchmark/CaseCanvas.java
new file mode 100644
index 0000000..1e5a8b8
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/CaseCanvas.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import android.util.Log;
+
+import android.os.SystemClock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.*;
+import android.view.*;
+import java.nio.*;
+import java.util.ArrayList;
+
+public class CaseCanvas extends Case{
+
+ public static int CanvasRound = 300;
+
+ CaseCanvas() {
+ super("CaseCanvas", TesterCanvas.getFullClassName(), 3, CanvasRound);
+
+ mType = "2d-fps";
+ String [] _tmp = {
+ "2d",
+ "render",
+ "view",
+ };
+ mTags = _tmp;
+
+ }
+
+ public String getTitle() {
+ return "Draw Canvas";
+ }
+
+ public String getDescription() {
+ return "call canvas.drawRGB to fill the canvas repeatedly. It redraw for " + CanvasRound + " times";
+ }
+
+ @Override
+ public String getBenchmark() {
+ if (!couldFetchReport()) {
+ return "Cavas has no report";
+ }
+
+ String result = "";
+ long total = 0;
+ int length = mResult.length;
+
+ for (int i = 0; i < length; i++) {
+ float second = (mResult[i] / 1000f);
+ float fps = (float)mCaseRound / second; // milliseconds to seconds
+ result += "Round " + i +" fps = " + fps + "\n";
+ total += fps;
+ }
+
+ result += "Average: fps = " + ((float)total/length) + "\n";
+ return result;
+ }
+
+ @Override
+ public ArrayList<Scenario> getScenarios () {
+ ArrayList<Scenario> scenarios = new ArrayList<Scenario>();
+
+ Scenario s = new Scenario(getTitle(), mType, mTags);
+ s.mLog = getBenchmark();
+ for (int i = 0; i < mResult.length; i++) {
+ float second = (mResult[i] / 1000f);
+ float fps = (float)mCaseRound / second;
+ s.mResults.add(((Float)fps).doubleValue());
+ }
+
+ scenarios.add(s);
+ return scenarios;
+ }
+
+}
diff --git a/src/org/zeroxlab/benchmark/CaseDrawCircle.java b/src/org/zeroxlab/benchmark/CaseDrawCircle.java
new file mode 100644
index 0000000..9b2097a
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/CaseDrawCircle.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import android.util.Log;
+
+import android.os.SystemClock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.*;
+import android.view.*;
+import java.nio.*;
+import java.util.ArrayList;
+
+public class CaseDrawCircle extends Case{
+
+ public static int CircleRound = 300;
+
+ CaseDrawCircle() {
+ super("CaseDrawCircle", "org.zeroxlab.graphics.DrawCircle", 3, CircleRound);
+ mType = "2d-fps";
+ String [] _tmp = {
+ "2d",
+ "render",
+ "skia",
+ "view",
+ };
+ mTags = _tmp;
+ }
+
+ public String getTitle() {
+ return "Draw Circle";
+ }
+
+ public String getDescription() {
+ return "call canvas.drawCircle to draw circle for " + CircleRound + " times";
+ }
+
+ @Override
+ public String getBenchmark() {
+ if (!couldFetchReport()) {
+ return "DrawCircle has no report";
+ }
+
+ String result = "";
+ long total = 0;
+ int length = mResult.length;
+
+ for (int i = 0; i < length; i++) {
+ float second = (mResult[i] / 1000f);
+ float fps = (float)mCaseRound / second; // milliseconds to seconds
+ result += "Round " + i +": fps = " + fps + "\n";
+ total += fps;
+ }
+
+ result += "Average: fps = " + ((float)total/length) + "\n";
+ return result;
+ }
+
+ @Override
+ public ArrayList<Scenario> getScenarios () {
+ ArrayList<Scenario> scenarios = new ArrayList<Scenario>();
+
+ Scenario s = new Scenario(getTitle(), mType, mTags);
+ s.mLog = getBenchmark();
+ for (int i = 0; i < mResult.length; i++) {
+ float second = (mResult[i] / 1000f);
+ float fps = (float)mCaseRound / second;
+ s.mResults.add(((Float)fps).doubleValue());
+ }
+
+ scenarios.add(s);
+ return scenarios;
+ }
+
+}
diff --git a/src/org/zeroxlab/benchmark/CaseGC.java b/src/org/zeroxlab/benchmark/CaseGC.java
new file mode 100644
index 0000000..809d695
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/CaseGC.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import android.util.Log;
+
+import android.os.SystemClock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.*;
+import android.view.*;
+import java.nio.*;
+import java.util.ArrayList;
+
+public class CaseGC extends Case{
+
+ String mStringBuf = "";
+ public static String GCRESULT = "GC_RESULT";
+ public static String TIME = "GC_RUNTIME";
+ public static double time = 0.0;
+
+ CaseGC() {
+ super("CaseGC", "org.zeroxlab.benchmark.TesterGC", 1, 1); // GC benchmark only run once
+
+ mType = "msec";
+ String [] _tmp = {
+ "dalvik",
+ "garbagecollection",
+ };
+ mTags = _tmp;
+ }
+
+ public String getTitle() {
+ return "Garbage Collection";
+ }
+
+ public String getDescription() {
+ return "It create long-live binary tree of depth and array of doubles to test GC";
+ }
+
+ @Override
+ public void clear() {
+ super.clear();
+ mStringBuf = "";
+ }
+
+ @Override
+ public void reset() {
+ super.reset();
+ mStringBuf = "";
+ }
+
+ @Override
+ public String getBenchmark() {
+
+ if (!couldFetchReport()) {
+ return "No benchmark report";
+ }
+
+ return mStringBuf;
+ }
+
+ @Override
+ public ArrayList<Scenario> getScenarios () {
+ ArrayList<Scenario> scenarios = new ArrayList<Scenario>();
+
+ Scenario s = new Scenario(getTitle(), mType, mTags);
+ s.mLog = getBenchmark();
+ s.mResults.add(time);
+ scenarios.add(s);
+
+ return scenarios;
+ }
+
+ @Override
+ protected boolean saveResult(Intent intent, int index) {
+ String result = intent.getStringExtra(GCRESULT);
+ time = intent.getDoubleExtra(TIME, 0.0);
+
+ if (result == null || result.equals("")) {
+ mStringBuf += "\nReport not found\n";
+ } else {
+ mStringBuf += "\n"+result+"\n";
+ }
+
+ return true;
+ }
+}
diff --git a/src/org/zeroxlab/benchmark/CaseGLCube.java b/src/org/zeroxlab/benchmark/CaseGLCube.java
new file mode 100644
index 0000000..0175000
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/CaseGLCube.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import android.util.Log;
+
+import org.zeroxlab.kubench.Kubench;
+
+import android.os.SystemClock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.*;
+import android.view.*;
+import java.nio.*;
+import java.util.ArrayList;
+
+public class CaseGLCube extends Case{
+
+ public static int CubeRound = 1000;
+
+ CaseGLCube() {
+ super("CaseGLCube", Kubench.getFullClassName(), 3, CubeRound);
+
+ mType = "3d-fps";
+ String [] _tmp = {
+ "3d",
+ "opengl",
+ "render",
+ "apidemo",
+ };
+ mTags = _tmp;
+ }
+
+ public String getTitle() {
+ return "OpenGL Cube";
+ }
+
+ public String getDescription() {
+ return "use OpenGL to draw a magic cube.";
+ }
+
+ @Override
+ public String getBenchmark() {
+ if (!couldFetchReport()) {
+ return "GLCube has no report";
+ }
+
+ String result = "";
+ long total = 0;
+ int length = mResult.length;
+
+ for (int i = 0; i < length; i++) {
+ float fps = mCaseRound / (mResult[i] / 1000f); // milliseconds to seconds
+ result += "Round " + i + ": fps = " + fps + "\n";
+ total += fps;
+ }
+
+ result += "Average: fps = " + ((float)total/length) + "\n";
+ return result;
+ }
+
+
+ @Override
+ public ArrayList<Scenario> getScenarios () {
+ ArrayList<Scenario> scenarios = new ArrayList<Scenario>();
+
+ Scenario s = new Scenario(getTitle(), mType, mTags);
+ s.mLog = getBenchmark();
+ for (int i = 0; i < mResult.length; i++) {
+ float fps = (float)mCaseRound / (mResult[i] / 1000f);
+ s.mResults.add(((Float)fps).doubleValue());
+ }
+
+ scenarios.add(s);
+ return scenarios;
+ }
+
+}
diff --git a/src/org/zeroxlab/benchmark/CaseNeheLesson08.java b/src/org/zeroxlab/benchmark/CaseNeheLesson08.java
new file mode 100644
index 0000000..722a299
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/CaseNeheLesson08.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import android.util.Log;
+
+import com.nea.nehe.lesson08.Run;
+import android.os.SystemClock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+
+import java.util.ArrayList;
+
+public class CaseNeheLesson08 extends Case {
+
+ public static int mNeheRepeat = 2;
+ public static int mNeheRound = 1000;
+
+ CaseNeheLesson08() {
+ super("NeheLesson08", Run.FullName, mNeheRepeat, mNeheRound);
+
+ mType = "3d-fps";
+
+ String [] _tmp = {
+ "render",
+ "opengl",
+ "nehe",
+ "gltexture",
+ "glblending",
+ "3d",
+ };
+ mTags = _tmp;
+ }
+
+ public String getTitle() {
+ return "OpenGL Blending";
+ }
+
+ public String getDescription() {
+ return "A very famous OpenGL tutorial to demo OpenGL blending";
+ }
+
+ @Override
+ public String getBenchmark() {
+ if (!couldFetchReport()) {
+ return "Nehe Lesson 8 has no report";
+ }
+
+ String result = "";
+ float total = 0;
+ int length = mResult.length;
+
+ for (int i = 0; i < length; i++) {
+ float fps = mCaseRound / (mResult[i] / 1000f); // milliseconds to seconds
+ result += "Round " + i + ": fps = " + fps + "\n";
+ total += fps;
+ }
+
+ result += "Average: fps = " + (total/length) + "\n";
+ return result;
+ }
+
+ @Override
+ public ArrayList<Scenario> getScenarios () {
+ ArrayList<Scenario> scenarios = new ArrayList<Scenario>();
+
+ Scenario s = new Scenario(getTitle(), mType, mTags);
+ s.mLog = getBenchmark();
+ for (int i = 0; i < mResult.length; i++) {
+ float fps = (float)mCaseRound / (mResult[i] / 1000f);
+ s.mResults.add(((Float)fps).doubleValue());
+ }
+
+ scenarios.add(s);
+ return scenarios;
+ }
+
+}
diff --git a/src/org/zeroxlab/benchmark/CaseNeheLesson16.java b/src/org/zeroxlab/benchmark/CaseNeheLesson16.java
new file mode 100644
index 0000000..7da6f15
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/CaseNeheLesson16.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import android.util.Log;
+
+import com.nea.nehe.lesson16.Run;
+import android.os.SystemClock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+import java.util.ArrayList;
+
+public class CaseNeheLesson16 extends Case {
+
+ public static int mNeheRepeat = 2;
+ public static int mNeheRound = 1000;
+
+ CaseNeheLesson16() {
+ super("NeheLesson16", Run.FullName, mNeheRepeat, mNeheRound);
+
+ mType = "3d-fps";
+ String [] _tmp = {
+ "3d",
+ "opengl",
+ "nehe",
+ "glfog",
+ "gltexture",
+ "render",
+ };
+ mTags = _tmp;
+ }
+
+ public String getTitle() {
+ return "OpenGL Fog";
+ }
+
+ public String getDescription() {
+ return "A very famous OpenGL tutorial to demo OpenGL fog";
+ }
+
+ @Override
+ public String getBenchmark() {
+ if (!couldFetchReport()) {
+ return "Nehe Lesson 16 has no report";
+ }
+
+ String result = "";
+ float total = 0;
+ int length = mResult.length;
+
+ for (int i = 0; i < length; i++) {
+ float fps = mCaseRound / (mResult[i] / 1000f); // milliseconds to seconds
+ result += "Round " + i + ": fps = " + fps + "\n";
+ total += fps;
+ }
+
+ result += "Average: fps = " + (total/length) + "\n";
+ return result;
+ }
+
+ @Override
+ public ArrayList<Scenario> getScenarios () {
+ ArrayList<Scenario> scenarios = new ArrayList<Scenario>();
+
+ Scenario s = new Scenario(getTitle(), mType, mTags);
+ s.mLog = getBenchmark();
+ for (int i = 0; i < mResult.length; i++) {
+ float fps = (float)mCaseRound / (mResult[i] / 1000f);
+ s.mResults.add(((Float)fps).doubleValue());
+ }
+
+ scenarios.add(s);
+ return scenarios;
+ }
+}
diff --git a/src/org/zeroxlab/benchmark/CaseScimark2.java b/src/org/zeroxlab/benchmark/CaseScimark2.java
new file mode 100644
index 0000000..8c7f4c1
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/CaseScimark2.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import android.util.Log;
+
+import android.os.SystemClock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+
+import java.util.ArrayList;
+
+import org.zeroxlab.benchmark.TesterScimark2;
+
+public class CaseScimark2 extends Case{
+
+ public static String LIN_RESULT = "LIN_RESULT";
+ protected Bundle mInfo[];
+
+ public static int Repeat = 1;
+ public static int Round = 1;
+
+ CaseScimark2() {
+ super("CaseScimark2", "org.zeroxlab.benchmark.TesterScimark2", Repeat, Round);
+
+ mType = "mflops";
+ String [] _tmp = {
+ "mflops",
+ "numeric",
+ "scientific",
+ };
+ mTags = _tmp;
+
+ generateInfo();
+ }
+
+ public String getTitle() {
+ return "Scimark2";
+ }
+
+ public String getDescription() {
+ return "SciMark 2.0 is a Java benchmark for scientific and numerical computing. It measures several computational kernels and reports a composite score in approximate Mflops.";
+ }
+
+ private void generateInfo() {
+ mInfo = new Bundle[Repeat];
+ for (int i = 0; i < mInfo.length; i++) {
+ mInfo[i] = new Bundle();
+ }
+ }
+
+ @Override
+ public void clear() {
+ super.clear();
+ generateInfo();
+ }
+
+ @Override
+ public void reset() {
+ super.reset();
+ generateInfo();
+ }
+
+ @Override
+ public String getBenchmark() {
+ if (!couldFetchReport()) {
+ return "No benchmark report";
+ }
+
+ String result = "\n";
+ for (int i = 0; i < mInfo.length; i++) {
+ result += TesterScimark2.bundleToString(mInfo[i]);
+ result += "\n";
+ }
+ return result;
+ }
+
+ @Override
+ public ArrayList<Scenario> getScenarios () {
+ ArrayList<Scenario> scenarios = new ArrayList<Scenario>();
+
+ ArrayList<String> subBenchmarks = new ArrayList<String>();
+ subBenchmarks.add(TesterScimark2.COMPOSITE );
+ subBenchmarks.add(TesterScimark2.FFT );
+ subBenchmarks.add(TesterScimark2.SOR );
+ subBenchmarks.add(TesterScimark2.MONTECARLO );
+ subBenchmarks.add(TesterScimark2.SPARSEMATMULT);
+ subBenchmarks.add(TesterScimark2.LU );
+
+ for (int i=0; i<subBenchmarks.size(); i++) {
+ String benchName = subBenchmarks.get(i);
+ Scenario s = new Scenario(getTitle()+":"+benchName, mType, mTags);
+
+ for(int j=0; j<mInfo.length; j++) {
+ double[] _tmp = mInfo[j].getDoubleArray(benchName + "array");
+ for(int k=0; k<_tmp.length; k++)
+ s.mResults.add(_tmp[k]);
+ }
+
+ scenarios.add(s);
+ }
+
+ return scenarios;
+ }
+
+ @Override
+ protected boolean saveResult(Intent intent, int index) {
+ Bundle info = intent.getBundleExtra(LIN_RESULT);
+ if (info == null) {
+ Log.i(TAG, "Weird! cannot find Scimark2Info");
+ return false;
+ } else {
+ mInfo[index] = info;
+ }
+
+ return true;
+ }
+}
diff --git a/src/org/zeroxlab/benchmark/CaseTeapot.java b/src/org/zeroxlab/benchmark/CaseTeapot.java
new file mode 100644
index 0000000..84ccc8a
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/CaseTeapot.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import android.util.Log;
+
+import org.itri.teapot.TeapotES;
+import android.os.SystemClock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+import java.util.ArrayList;
+
+public class CaseTeapot extends Case {
+
+ public static int mTeapotRepeat = 2;
+ public static int mTeapotRound = 1000;
+
+ CaseTeapot() {
+ super("Teapot", TeapotES.FullName, mTeapotRepeat, mTeapotRound);
+ mType = "3d-fps";
+ String [] _tmp = {
+ "3d",
+ "opengl",
+ "render",
+ };
+ mTags = _tmp;
+ }
+
+ public String getTitle() {
+ return "Flying Teapot";
+ }
+
+ public String getDescription() {
+ return "A flying standard Utah Teapot";
+ }
+
+ @Override
+ public String getBenchmark() {
+ if (!couldFetchReport()) {
+ return "Teapot has no report";
+ }
+
+ String result = "";
+ float total = 0;
+ int length = mResult.length;
+
+ for (int i = 0; i < length; i++) {
+ float fps = mCaseRound / (mResult[i] / 1000f); // milliseconds to seconds
+ result += "Round " + i + ": fps = " + fps + "\n";
+ total += fps;
+ }
+
+ result += "Average: fps = " + (total/length) + "\n";
+ return result;
+ }
+
+ @Override
+ public ArrayList<Scenario> getScenarios () {
+ ArrayList<Scenario> scenarios = new ArrayList<Scenario>();
+
+ Scenario s = new Scenario(getTitle(), mType, mTags);
+ s.mLog = getBenchmark();
+ for (int i = 0; i < mResult.length; i++) {
+ float fps = (float)mCaseRound / (mResult[i] / 1000f);
+ s.mResults.add(((Float)fps).doubleValue());
+ }
+
+ scenarios.add(s);
+ return scenarios;
+ }
+
+}
diff --git a/src/org/zeroxlab/benchmark/MicroBenchmark.java b/src/org/zeroxlab/benchmark/MicroBenchmark.java
new file mode 100644
index 0000000..7ae519b
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/MicroBenchmark.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import android.util.Log;
+import android.os.Handler;
+import android.os.Bundle;
+import android.os.SystemClock;
+import android.os.Message;
+
+/* code adapted from Caliper Project */
+
+class MicroBenchmark extends Thread {
+ final static int FAILED = -1;
+ final static int DONE = 0;
+ final static int RUNNING = 1;
+
+ final static String STATE = "STATE";
+ final static String MSG = "MSG";
+ final static String TAG = "MicroBenchmarkThread";
+
+ Handler mHandler;
+
+ String xml;
+ String postUrl;
+ String apiKey;
+ String benchmarkName;
+
+ MicroBenchmark(String _xml, String _postUrl, String _apiKey, String _benchmarkName, Handler h) {
+ xml = _xml;
+ postUrl = _postUrl;
+ apiKey = _apiKey;
+ benchmarkName = _benchmarkName;
+ mHandler = h;
+ }
+
+ private void updateState(int state, String info) {
+ Bundle b = new Bundle();
+ b.putInt(STATE, state);
+ b.putString(MSG, info);
+ Message msg = mHandler.obtainMessage();
+ msg.setData(b);
+ mHandler.sendMessage(msg);
+
+ Log.e(TAG, "set state: " + state);
+ }
+
+ private void updateState(int state) {
+ updateState(state, "");
+ }
+
+
+ public void upload() {
+ updateState(RUNNING);
+ try {
+ URL url = new URL(postUrl + apiKey + "/" + benchmarkName);
+ HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
+ urlConnection.setDoOutput(true);
+
+ OutputStream post = urlConnection.getOutputStream();
+ Log.e(TAG, xml);
+ post.write(xml.getBytes());
+
+ int responseCode = urlConnection.getResponseCode();
+ Log.e(TAG, ""+responseCode);
+
+ if (responseCode != 200) {
+ updateState(FAILED, "Connection failed with response code " + responseCode);
+ return;
+ }
+ } catch (IOException e) {
+ updateState(FAILED, e.toString());
+ return;
+ }
+ updateState(DONE);
+
+ }
+
+ public void run() {
+ upload();
+ }
+}
+
diff --git a/src/org/zeroxlab/benchmark/NativeTester.java b/src/org/zeroxlab/benchmark/NativeTester.java
new file mode 100644
index 0000000..2b9e058
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/NativeTester.java
@@ -0,0 +1,336 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import java.lang.Runtime;
+import java.lang.IllegalThreadStateException;
+
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.lang.Math;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
+
+import java.net.Socket;
+import java.net.ServerSocket;
+
+import android.app.Activity;
+import android.util.Log;
+import android.os.Bundle;
+import android.os.SystemClock;
+import android.os.Handler;
+import android.os.Message;
+import android.content.Intent;
+import android.widget.TextView;
+import android.widget.ScrollView;
+
+import android.content.pm.ActivityInfo;
+
+
+public abstract class NativeTester extends Tester {
+
+ private TextView mTextView;
+ private ScrollView mScrollView;
+
+ private Runtime mRuntime;
+ private Process mProcess;
+
+ public final String TAG = "NativeTester";
+ public final String PING_MSG = "PING";
+ public final String ENV_VAR = "ZXBENCH_PORT";
+
+ public final int CHECK_FREQ = 1000;
+ public final int IDLE_KILL = 20000; //1000 * 60 * 5;
+
+ public String mCommand;
+ public Handler mHandler;
+ public static final int GUINOTIFIER = 0x1234;
+
+ public Map<String, String> mStdOuts = new HashMap<String, String>();
+ public Map<String, String> mStdErrs = new HashMap<String, String>();
+ public Map<String, String> mSockets = new HashMap<String, String>();
+
+ private BufferedReader stdOutReader;
+ private BufferedReader stdErrReader;
+ private BufferedReader sckOutReader;
+
+ private ProcessMonitor mProcessMonitor;
+ private boolean mProcessRunning = false;
+ private double mIdleTime;
+
+ private StringBuilder stdOut = new StringBuilder();
+ private StringBuilder stdErr = new StringBuilder();
+ private StringBuilder sckOut = new StringBuilder();
+
+ private ServerSocket mServerSocket;
+ private Socket mClientSocket = null;
+ private int mBindPort = -1;
+
+ public NativeTester() {
+ mRuntime = Runtime.getRuntime();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.gc);
+ mTextView = (TextView) findViewById(R.id.myTextView1);
+ mScrollView = (ScrollView) findViewById(R.id.myScrollView);
+
+ mHandler = new Handler() {
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case GUINOTIFIER:
+ mTextView.setText("idle time: " + mIdleTime + "\nstderr -->\n" + stdErr.toString() + "\nstdout -->\n" + stdOut.toString());
+ mScrollView.post(new Runnable() {
+ public void run() {
+ mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
+ }
+ });
+ break;
+ }
+ }
+ };
+
+ startTester();
+ }
+
+ protected abstract List<String> getCommands();
+
+ protected abstract boolean saveResult(Intent intent);
+
+ @Override
+ protected int sleepBeforeStart() {
+ return 0;
+ };
+ @Override
+ protected int sleepBetweenRound(){
+ return 0;
+ };
+
+ private void reportOutputs() {
+ Log.i(TAG, stdOut.toString() );
+ Log.i(TAG, stdErr.toString() );
+ String [] sckOutLines = sckOut.toString().split("\n");
+ for(String sckOutLine: sckOutLines)
+ Log.i(TAG, sckOutLine);
+ }
+
+ public void oneRound() {
+ new ProcessRunner().start();
+ }
+
+ public int exitValue() throws IllegalThreadStateException {
+ return mProcess.exitValue();
+ }
+
+ public void killProcess() {
+ mProcess.destroy();
+ try {
+ mClientSocket.close();
+ mServerSocket.close();
+ } catch (IOException e) {
+ Log.i(TAG, "close server socket failed: " + e.toString());
+ }
+ mProcessRunning = false;
+ }
+
+ class ProcessRunner extends Thread {
+ public void run() {
+ for(String command: getCommands()) {
+ Log.i(TAG, "------------------------ process " + command + " start ------------------------ ");
+ try {
+ mServerSocket = new ServerSocket(0);
+ mServerSocket.setSoTimeout(IDLE_KILL);
+ } catch (IOException e) {
+ Log.e(TAG, "cannot create ServerSocket. " + e.toString());
+ interruptTester();
+ }
+ Log.i(TAG, "server socket created");
+
+ mBindPort = mServerSocket.getLocalPort();
+
+ String[] envp = {
+ ENV_VAR + "=" + mBindPort,
+ };
+ try {
+ mProcess = mRuntime.exec(command, envp);
+ if(mProcess == null)
+ throw new Exception();
+ mProcessRunning = true;
+ } catch (Exception e) {
+ Log.e(TAG, "Cannot execute command: `" + command + "`. " + e.toString());
+ mNow = 0;
+ continue;
+ }
+ Log.i(TAG, "command executed");
+ stdOutReader = new BufferedReader(new InputStreamReader(mProcess.getInputStream()));
+ stdErrReader = new BufferedReader(new InputStreamReader(mProcess.getErrorStream()));
+ updateBuffer stdOutThread = new updateBuffer(stdOutReader, stdOut);
+ updateBuffer stdErrThread = new updateBuffer(stdErrReader, stdErr);
+ stdOutThread.start();
+ stdErrThread.start();
+
+ try {
+ Log.i(TAG, "waiting conncetion with timeout " + mServerSocket.getSoTimeout());
+ mClientSocket = mServerSocket.accept();
+ } catch (IOException e) {
+ Log.e(TAG, "cannot acception incoming connection. " + e.toString());
+ killProcess();
+ continue;
+ }
+ Log.i(TAG, "connection accepted");
+
+ try {
+ sckOutReader = new BufferedReader(new InputStreamReader(mClientSocket.getInputStream()));
+ } catch (IOException e) {
+ Log.e(TAG, "cannot create input stream, lost connection? " + e.toString());
+ killProcess();
+ continue;
+ }
+ Log.i(TAG, "stream created");
+
+ updateBuffer socketThread = new updateBuffer(sckOutReader, sckOut);
+ socketThread.start();
+
+ mProcessMonitor = new ProcessMonitor(stdOutThread, stdErrThread, socketThread);
+ mProcessMonitor.start();
+ try {
+ mProcessMonitor.join();
+ } catch (InterruptedException e) {
+ Log.e(TAG, "inturrupted before process monitor joins: " + e.toString());
+ killProcess();
+ continue;
+ }
+ reportOutputs();
+ mStdOuts.put(command, stdOut.toString());
+ mStdErrs.put(command, stdErr.toString());
+ mSockets.put(command, sckOut.toString());
+ stdOut = new StringBuilder();
+ stdErr = new StringBuilder();
+ sckOut = new StringBuilder();
+ Log.i(TAG, "------------------------ process " + command + " finish ------------------------ ");
+ }
+ decreaseCounter();
+ Log.i(TAG, "counter decreased by 1 to " + mNow);
+ }
+ }
+
+ class ProcessMonitor extends Thread {
+ updateBuffer stdOutThread;
+ updateBuffer stdErrThread;
+ updateBuffer sckOutThread;
+ float idleTime;
+ ProcessMonitor (updateBuffer stdOutThread, updateBuffer stdErrThread, updateBuffer sckOutThread) {
+ this.stdOutThread = stdOutThread;
+ this.stdErrThread = stdErrThread;
+ this.sckOutThread = sckOutThread;
+ }
+ public void run() {
+ int value;
+ mIdleTime = 0.0;
+ while (true) {
+ try {
+ value = mProcess.exitValue();
+ } catch (IllegalThreadStateException e) {
+ mIdleTime = Math.min(Math.min(stdOutThread.idleTime(), stdErrThread.idleTime()), sckOutThread.idleTime()) ;
+ Message m = new Message();
+ m.what = GUINOTIFIER;
+ mHandler.sendMessage(m);
+ if ( mIdleTime > IDLE_KILL ) {
+ Log.e(TAG, "Native process idle for over " + IDLE_KILL/1000 + " Seconds, killing.");
+ killProcess();
+ Log.w(TAG, "Monitor: ends with no update threads joined");
+ //TODO: should find a way to end update threads gracefully
+ return;
+
+ }
+ SystemClock.sleep(CHECK_FREQ);
+ continue;
+ }
+ break;
+ }
+ Log.i(TAG, "Process exited with value = " + value);
+ try {
+ stdOutThread.join();
+ } catch (InterruptedException e) {
+ Log.w(TAG, "stdout update thread cannot join");
+ }
+ Log.i(TAG, "stdout update thread joined");
+ try {
+ stdErrThread.join();
+ } catch (InterruptedException e) {
+ Log.w(TAG, "stderr update thread cannot join");
+ }
+ Log.i(TAG, "stderr update thread joined");
+ try {
+ sckOutThread.join();
+ } catch (InterruptedException e) {
+ Log.w(TAG, "socket update thread cannot join");
+ }
+ Log.i(TAG, "socket update thread joined");
+ Log.i(TAG, "closing server socket");
+ try {
+ mClientSocket.close();
+ mServerSocket.close();
+ } catch (IOException e) {
+ Log.i(TAG, "close server socket failed: " + e.toString());
+ }
+ Log.w(TAG, "Monitor: All update threads joined");
+ }
+ }
+
+ class updateBuffer extends Thread {
+ long mLastRead;
+ BufferedReader is;
+ StringBuilder mBuffer;
+ final int UNREAD = -1;
+
+ updateBuffer(BufferedReader is, StringBuilder targetBuffer) {
+ this.is = is;
+ mBuffer = targetBuffer;
+ mLastRead = UNREAD;
+ }
+
+ public void run() {
+ char[] c = new char[1024];
+ int count;
+ try {
+ while ( (count = is.read(c,0,1024)) != -1) {
+ mLastRead = SystemClock.uptimeMillis();
+ mBuffer.append(c, 0, count);
+ Message m = new Message();
+ m.what = GUINOTIFIER;
+ mHandler.sendMessage(m);
+ if (!mProcessRunning && !is.ready()) {
+ is.close();
+ break;
+ }
+ }
+ } catch (IOException e) {
+ Log.e(TAG, "update buffer failed. " + e.toString());
+ }
+ }
+
+ public long idleTime() {
+ return SystemClock.uptimeMillis() - mLastRead;
+ }
+ }
+}
+
diff --git a/src/org/zeroxlab/benchmark/Report.java b/src/org/zeroxlab/benchmark/Report.java
new file mode 100644
index 0000000..fc45b93
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/Report.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import android.util.Log;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.TextView;
+import android.widget.Button;
+import android.content.*;
+import java.nio.*;
+
+import java.util.LinkedList;
+
+/* Construct a basic UI */
+public class Report extends Activity implements View.OnClickListener {
+
+ public final static String TAG = "Repord";
+ public final static String REPORT = "REPORT";
+ public final static String XML = "XML";
+ private TextView mTextView;
+
+ private Button mUpload;
+ private Button mBack;
+ private String mXMLResult;
+
+ @Override
+ protected void onCreate(Bundle bundle) {
+ super.onCreate(bundle);
+ setContentView(R.layout.report);
+
+ mTextView = (TextView)findViewById(R.id.report_text);
+
+ mUpload = (Button)findViewById(R.id.btn_upload);
+ mUpload.setOnClickListener(this);
+
+ mBack = (Button)findViewById(R.id.btn_back);
+ mBack.setOnClickListener(this);
+
+ Intent intent = getIntent();
+ String report = intent.getStringExtra(REPORT);
+ mXMLResult = intent.getStringExtra(XML);
+
+ if (report == null || report.equals("")) {
+ mTextView.setText("oooops...report not found");
+ } else {
+ mTextView.setText(report);
+ }
+ }
+
+ public void onClick(View v) {
+ if (v == mBack) {
+ finish();
+ } else if (v == mUpload) {
+ Intent intent = new Intent();
+ intent.putExtra(Upload.XML, mXMLResult);
+ intent.setClassName(Upload.packageName(), Upload.fullClassName());
+
+ startActivity(intent);
+ }
+ }
+
+ public static String fullClassName() {
+ return "org.zeroxlab.benchmark.Report";
+ }
+
+ public static String packageName() {
+ return "org.zeroxlab.benchmark";
+ }
+}
diff --git a/src/org/zeroxlab/benchmark/Scenario.java b/src/org/zeroxlab/benchmark/Scenario.java
new file mode 100644
index 0000000..8cb3b89
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/Scenario.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import java.util.Date;
+import java.util.ArrayList;
+
+public class Scenario {
+ String mName;
+ String mType;
+ String [] mTags;
+ Date mTime;
+
+ public ArrayList<Double> mResults;
+ public String mStringResults;
+ public boolean useStringResults;
+ String mLog;
+
+ public Scenario(String name, String type, String [] tags) {
+ useStringResults = false;
+
+ mName = name;
+ mType = type;
+ mTags = tags;
+
+ mTime = new Date();
+ mResults = new ArrayList<Double>();
+ }
+
+ public Scenario(String name, String type, String [] tags, boolean useString) {
+ if (!useString) {
+ useStringResults = false;
+ mResults = new ArrayList<Double>();
+ } else {
+ useStringResults = true;
+ }
+
+ mName = name;
+ mType = type;
+ mTags = tags;
+
+ mTime = new Date();
+ }
+}
+
diff --git a/src/org/zeroxlab/benchmark/Tester.java b/src/org/zeroxlab/benchmark/Tester.java
new file mode 100644
index 0000000..3370c89
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/Tester.java
@@ -0,0 +1,213 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import android.util.Log;
+
+import android.os.SystemClock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.*;
+import android.view.*;
+import android.graphics.Canvas;
+import android.os.*;
+
+public abstract class Tester extends Activity{
+ private String TAG;
+ public final static String PACKAGE = "org.zeroxlab.benchmark";
+ int mRound;
+ int mNow;
+ int mIndex;
+
+ protected long mTesterStart = 0;
+ protected long mTesterEnd = 0;
+
+ protected abstract String getTag();
+ protected abstract int sleepBeforeStart();
+ protected abstract int sleepBetweenRound();
+ protected abstract void oneRound();
+
+ protected String mSourceTag = "unknown";
+ private boolean mNextRound = true;
+
+ protected boolean mDropTouchEvent = true;
+ protected boolean mDropTrackballEvent = true;
+
+ protected void onCreate(Bundle bundle) {
+ super.onCreate(bundle);
+ TAG = getTag();
+
+ Intent intent = getIntent();
+ if (intent != null) {
+ mRound = Case.getRound(intent);
+ mSourceTag = Case.getSource(intent);
+ mIndex = Case.getIndex(intent);
+ } else {
+ mRound = 80;
+ mIndex = -1;
+ }
+ mNow = mRound;
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ interruptTester();
+ }
+
+ /* drop the annoying event */
+ @Override
+ public boolean dispatchTouchEvent(MotionEvent ev) {
+ if (mDropTouchEvent) {
+ return false;
+ } else {
+ return super.dispatchTouchEvent(ev);
+ }
+ }
+
+ @Override
+ public boolean dispatchTrackballEvent(MotionEvent ev) {
+ if (mDropTrackballEvent) {
+ return false;
+ } else {
+ return super.dispatchTouchEvent(ev);
+ }
+ }
+
+ protected void startTester() {
+ TesterThread thread = new TesterThread(sleepBeforeStart(), sleepBetweenRound());
+ thread.start();
+ }
+
+ public void interruptTester() {
+ mNow = 0;
+ finish();
+ }
+
+ /**
+ * Call this method if you finish your testing.
+ *
+ * @param start The starting time of testing round
+ * @param end The ending time of testing round
+ */
+ public void finishTester(long start, long end) {
+ mTesterStart = start;
+ mTesterEnd = end;
+ Intent intent = new Intent();
+ if (mSourceTag == null || mSourceTag.equals("")) {
+ Case.putSource(intent, "unknown");
+ } else {
+ Case.putSource(intent, mSourceTag);
+ }
+
+ Case.putIndex(intent, mIndex);
+ saveResult(intent);
+
+ setResult(0, intent);
+ finish();
+ }
+
+ /**
+ * Save the benchmarking result into intent
+ * If this Case and Tester has their own way to pass benchmarking result
+ * just override this method
+ *
+ * @param intent The intent will return to Case
+ */
+ protected boolean saveResult(Intent intent) {
+ long elapse = mTesterEnd - mTesterStart;
+ Case.putResult(intent, elapse);
+ return true;
+ }
+
+ public void resetCounter() {
+ mNow = mRound;
+ }
+
+ public void decreaseCounter() {
+ /*
+ if (mNow == mRound) {
+ mTesterStart = SystemClock.uptimeMillis();
+ } else if (mNow == 1) {
+ mTesterEnd = SystemClock.uptimeMillis();
+ }
+ */
+ mNow = mNow - 1;
+ mNextRound = true;
+ }
+
+ public boolean isTesterFinished() {
+ return (mNow <= 0);
+ }
+
+ class TesterThread extends Thread {
+ int mSleepingStart;
+ int mSleepingTime;
+ TesterThread(int sleepStart, int sleepPeriod) {
+ mSleepingStart = sleepStart;
+ mSleepingTime = sleepPeriod;
+ }
+
+ private void lazyLoop() throws Exception {
+ while (!isTesterFinished()) {
+ if (mNextRound) {
+ mNextRound = false;
+ oneRound();
+ } else {
+ sleep(mSleepingTime);
+ // TODO:
+ // Benchmarks that calculates frequencies (e.g. fps) should be time,
+ // for example, GL cases should run for a fixed time, and calculate
+ // # of frames rendered, instead of periodically checking if fixed
+ // # of frames had been rendered (which can hurt performance).
+ }
+ }
+ }
+
+ private void nervousLoop() throws Exception {
+ while (!isTesterFinished()) {
+ oneRound();
+ }
+ }
+
+ private void sleepLoop() throws Exception {
+ while (!isTesterFinished()) {
+ oneRound();
+ sleep(mSleepingTime);
+ }
+ }
+
+ public void run() {
+ try {
+ sleep(mSleepingStart);
+
+ long start = SystemClock.uptimeMillis();
+
+ lazyLoop();
+
+ long end = SystemClock.uptimeMillis();
+ finishTester(start, end);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/src/org/zeroxlab/benchmark/TesterArithmetic.java b/src/org/zeroxlab/benchmark/TesterArithmetic.java
new file mode 100644
index 0000000..5d29921
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/TesterArithmetic.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import org.zeroxlab.arithmetic.LinpackLoop;
+
+import android.util.Log;
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.content.Intent;
+import android.widget.TextView;
+
+public class TesterArithmetic extends Tester{
+
+ TextView mTextView;
+ Bundle mInfo[];
+ public final static String MFLOPS = "MFLOPS";
+ public final static String RESIDN = "RESIDN";
+ public final static String TIME = "TIME";
+ public final static String EPS = "EPS";
+
+ protected String getTag() {
+ return "Arithmetic";
+ }
+
+ protected int sleepBeforeStart() {
+ return 1000;
+ }
+
+ protected int sleepBetweenRound() {
+ return 200;
+ }
+
+ protected void oneRound() {
+ LinpackLoop.main(mInfo[mNow - 1]);
+ decreaseCounter();
+ }
+
+ @Override
+ protected boolean saveResult(Intent intent) {
+ Bundle result = new Bundle();
+ TesterArithmetic.average(result, mInfo);
+
+ intent.putExtra(CaseArithmetic.LIN_RESULT, result);
+ return true;
+ }
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ int length = mRound;
+ mInfo = new Bundle[length];
+ for (int i = 0; i < length; i++) {
+ mInfo[i] = new Bundle();
+ }
+
+ mTextView = new TextView(this);
+ mTextView.setText("Running benchmark....");
+ mTextView.setTextSize(mTextView.getTextSize() + 5);
+ setContentView(mTextView);
+ startTester();
+ }
+
+ public static void average(Bundle result, Bundle[] list) {
+
+ if (result == null) {
+ result = new Bundle();
+ }
+
+ if (list == null) {
+ Log.i("Arithmetic", "Array is null");
+ return;
+ }
+
+ int length = list.length;
+ double mflops_total = 0.0;
+ double residn_total = 0.0;
+ double time_total = 0.0;
+ double eps_total = 0.0;
+
+ for (int i = 0; i < length; i ++) {
+ Bundle info = list[i];
+
+ if (info == null) {
+ Log.i("Arithmetic", "one item of array is null!");
+ return;
+ }
+
+ mflops_total += info.getDouble(MFLOPS);
+ residn_total += info.getDouble(RESIDN);
+ time_total += info.getDouble(TIME);
+ eps_total += info.getDouble(EPS);
+ }
+
+ result.putDouble(MFLOPS, mflops_total / length);
+ result.putDouble(RESIDN, residn_total / length);
+ result.putDouble(TIME, time_total / length);
+ result.putDouble(EPS, eps_total / length);
+ }
+
+ public static String bundleToString(Bundle bundle) {
+ String result = "";
+ result += "\nMflops/s :" + bundle.getDouble(MFLOPS, 0.0);
+ /* the time result is too small to calculate average. (0.0 ~ 0.1), drop it*/
+ //result += "\nTime :" + bundle.getDouble(TIME, 0.0);
+ result += "\nNorm Res :" + bundle.getDouble(RESIDN, 0.0);
+ result += "\nPrecision:" + bundle.getDouble(EPS, 0.0);
+
+ return result;
+ }
+
+ public static String bundleListToXML(Bundle[] mInfo) {
+
+ double total = 0.0;
+ for (int i = 0; i < mInfo.length; i++) {
+ double mflops = mInfo[i].getDouble(MFLOPS, 0.0);
+ total += mflops;
+ }
+ if (total == 0) {
+ return "";
+ }
+ String result = "";
+ result += "<scenario benchmark=\"Linpack\" unit=\"mflops\">";
+ for (int i = 0; i < mInfo.length; i++) {
+ double mflops = mInfo[i].getDouble(MFLOPS, 0.0);
+ result += "" + mflops + " ";
+ }
+ result += "</scenario>";
+
+ return result;
+ }
+
+}
diff --git a/src/org/zeroxlab/benchmark/TesterCanvas.java b/src/org/zeroxlab/benchmark/TesterCanvas.java
new file mode 100644
index 0000000..7b763f9
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/TesterCanvas.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import android.util.Log;
+
+import android.os.SystemClock;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.*;
+import android.view.*;
+import android.graphics.Canvas;
+import android.os.*;
+
+import java.util.Random;
+import android.graphics.Color;
+
+public class TesterCanvas extends Tester {
+ public final String TAG = "TesterCanvas";
+ public final static String PACKAGE = "org.zeroxlab.benchmark";
+ MyView mView;
+
+ public String getTag() {
+ return TAG;
+ }
+
+ public static String getPackage() {
+ return PACKAGE;
+ }
+
+ public static String getFullClassName() {
+ return getPackage()+".TesterCanvas";
+ }
+
+ public int sleepBetweenRound() {
+ return 0;
+ }
+ public int sleepBeforeStart() {
+ return 1000;
+ }
+
+ public void oneRound() {
+ mView.postInvalidate();
+ }
+
+ public void onCreate(Bundle bundle) {
+ super.onCreate(bundle);
+ mView = new MyView(this);
+ setContentView(mView);
+ }
+
+ class MyView extends View {
+ int i = 0;
+ Random mRandom;
+
+ MyView(Context context) {
+ super(context);
+ mRandom = new Random();
+ }
+
+ @Override
+ protected void onWindowVisibilityChanged(int visibility) {
+ super.onWindowVisibilityChanged(visibility);
+ if (visibility != View.VISIBLE) {
+ return;
+ }
+
+ startTester();
+ }
+
+ @Override
+ public void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ // int r = 0xFF & mRandom.nextInt();
+ int r = (0x00151515| mRandom.nextInt() ) | Color.BLACK;
+ canvas.drawRGB(r, r, r);
+ decreaseCounter();
+ }
+ }
+}
diff --git a/src/org/zeroxlab/benchmark/TesterGC.java b/src/org/zeroxlab/benchmark/TesterGC.java
new file mode 100644
index 0000000..9147822
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/TesterGC.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import org.zeroxlab.gc.GCBenchmark;
+
+import android.app.Activity;
+
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.content.Intent;
+import android.widget.TextView;
+
+public class TesterGC extends Tester{
+
+ private TextView mTextView1;
+
+ public static double time = 0.0;
+ public static Handler mHandler;
+ public static final int GUINOTIFIER = 0x1234;
+
+
+ protected String getTag() {
+ return "GC";
+ }
+
+ protected int sleepBeforeStart() {
+ return 1000;
+ }
+
+ protected int sleepBetweenRound() {
+ return 0;
+ }
+
+ protected void oneRound() {
+ GCBenchmark.benchmark();
+ decreaseCounter();
+ }
+
+ @Override
+ protected boolean saveResult(Intent intent) {
+ intent.putExtra(CaseGC.GCRESULT, GCBenchmark.out.toString());
+ intent.putExtra(CaseGC.TIME, time);
+ return true;
+ }
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.gc);
+
+ mTextView1 = (TextView) findViewById(R.id.myTextView1);
+
+ mHandler = new Handler() {
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case GUINOTIFIER:
+ mTextView1.setText(GCBenchmark.out);
+ break;
+ }
+ super.handleMessage(msg);
+ }
+ };
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ startTester();
+ }
+}
diff --git a/src/org/zeroxlab/benchmark/TesterScimark2.java b/src/org/zeroxlab/benchmark/TesterScimark2.java
new file mode 100644
index 0000000..c9a5905
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/TesterScimark2.java
@@ -0,0 +1,253 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import jnt.scimark2.commandline;
+
+import android.util.Log;
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.content.Intent;
+import android.widget.TextView;
+import java.util.HashMap;
+import java.util.ArrayList;
+
+public class TesterScimark2 extends Tester{
+
+ TextView mTextView;
+ Bundle mInfo[];
+ public final static String COMPOSITE = "COMPOSITE";
+ public final static String FFT = "FTT";
+ public final static String SOR = "SOR";
+ public final static String MONTECARLO = "MONTECARLO";
+ public final static String SPARSEMATMULT= "SPARSEMATMULT";
+ public final static String LU = "LU";
+
+ protected String getTag() {
+ return "Scimark2";
+ }
+
+ protected int sleepBeforeStart() {
+ return 1000;
+ }
+
+ protected int sleepBetweenRound() {
+ return 200;
+ }
+
+ protected void oneRound() {
+ commandline.main(mInfo[mNow - 1]);
+ decreaseCounter();
+ }
+
+ @Override
+ protected boolean saveResult(Intent intent) {
+ Bundle result = new Bundle();
+ TesterScimark2.average(result, mInfo);
+
+ intent.putExtra(CaseScimark2.LIN_RESULT, result);
+ return true;
+ }
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ int length = mRound;
+ mInfo = new Bundle[length];
+ for (int i = 0; i < length; i++) {
+ mInfo[i] = new Bundle();
+ }
+
+ mTextView = new TextView(this);
+ mTextView.setText("Running benchmark....");
+ mTextView.setTextSize(mTextView.getTextSize() + 5);
+ setContentView(mTextView);
+ startTester();
+ }
+
+ public static void average(Bundle result, Bundle[] list) {
+
+ if (result == null) {
+ result = new Bundle();
+ }
+
+ if (list == null) {
+ Log.i("Scimark2", "Array is null");
+ return;
+ }
+
+ int length = list.length;
+ double composite_total = 0.0;
+ double fft_total = 0.0;
+ double sor_total = 0.0;
+ double montecarlo_total = 0.0;
+ double sparsematmult_total = 0.0;
+ double lu_total = 0.0;
+
+ HashMap<String, double[]> store = new HashMap<String, double[]>();
+ store.put(COMPOSITE , new double[length] );
+ store.put(FFT , new double[length] );
+ store.put(SOR , new double[length] );
+ store.put(MONTECARLO , new double[length] );
+ store.put(SPARSEMATMULT, new double[length] );
+ store.put(LU , new double[length] );
+
+
+ for (int i = 0; i < length; i ++) {
+ Bundle info = list[i];
+
+ if (info == null) {
+ Log.i("Scimark2", "one item of array is null!");
+ return;
+ }
+
+ composite_total += info.getDouble(COMPOSITE );
+ fft_total += info.getDouble(FFT );
+ sor_total += info.getDouble(SOR );
+ montecarlo_total += info.getDouble(MONTECARLO );
+ sparsematmult_total += info.getDouble(SPARSEMATMULT);
+ lu_total += info.getDouble(LU );
+
+ store.get(COMPOSITE )[i] = info.getDouble(COMPOSITE );
+ store.get(FFT )[i] = info.getDouble(FFT );
+ store.get(SOR )[i] = info.getDouble(SOR );
+ store.get(MONTECARLO )[i] = info.getDouble(MONTECARLO );
+ store.get(SPARSEMATMULT)[i] = info.getDouble(SPARSEMATMULT);
+ store.get(LU )[i] = info.getDouble(LU );
+ }
+
+ result.putDouble(COMPOSITE , composite_total / length);
+ result.putDouble(FFT , fft_total / length);
+ result.putDouble(SOR , sor_total / length);
+ result.putDouble(MONTECARLO , montecarlo_total / length);
+ result.putDouble(SPARSEMATMULT, sparsematmult_total/ length);
+ result.putDouble(LU , lu_total / length);
+
+ result.putDoubleArray(COMPOSITE +"array" , store.get(COMPOSITE ) );
+ result.putDoubleArray(FFT +"array" , store.get(FFT ) );
+ result.putDoubleArray(SOR +"array" , store.get(SOR ) );
+ result.putDoubleArray(MONTECARLO +"array" , store.get(MONTECARLO ) );
+ result.putDoubleArray(SPARSEMATMULT +"array", store.get(SPARSEMATMULT) );
+ result.putDoubleArray(LU +"array" , store.get(LU ) );
+ }
+
+ public static String bundleToString(Bundle bundle) {
+ String result = "";
+ result += "\nComposite:\n " + bundle.getDouble(COMPOSITE, 0.0);
+ result += "\nFast Fourier Transform:\n " + bundle.getDouble(FFT, 0.0);
+ result += "\nJacobi Successive Over-relaxation:\n " + bundle.getDouble(SOR, 0.0);
+ result += "\nMonte Carlo integration:\n " + bundle.getDouble(MONTECARLO, 0.0);
+ result += "\nSparse matrix multiply:\n " + bundle.getDouble(SPARSEMATMULT, 0.0);
+ result += "\ndense LU matrix factorization:\n " + bundle.getDouble(LU, 0.0);
+
+ return result;
+ }
+
+ public static String bundleListToXML(Bundle[] mInfo) {
+
+ int length = mInfo.length;
+ double composite_total = 0.0;
+ double fft_total = 0.0;
+ double sor_total = 0.0;
+ double montecarlo_total = 0.0;
+ double sparsematmult_total = 0.0;
+ double lu_total = 0.0;
+
+ for (int i = 0; i < length; i++) {
+ Bundle info = mInfo[i];
+
+ composite_total += info.getDouble(COMPOSITE );
+ fft_total += info.getDouble(FFT );
+ sor_total += info.getDouble(SOR );
+ montecarlo_total += info.getDouble(MONTECARLO );
+ sparsematmult_total += info.getDouble(SPARSEMATMULT);
+ lu_total += info.getDouble(LU );
+ }
+
+
+ String benchName = "Scimark2";
+
+ String result = "";
+
+ if(composite_total != 0.0) {
+ result += "<scenario";
+ result += " benchmark=\"" + benchName + "-COMPOSITE\" unit=\"mflops\"";
+ result += ">";
+ for (int i = 0; i < length; i++) {
+ result += "" + mInfo[i].getDouble(COMPOSITE) + " ";
+ }
+ result += "</scenario>";
+ }
+
+ if(fft_total != 0.0) {
+ result += "<scenario";
+ result += " benchmark=\"" + benchName + "-FFT\" unit=\"mflops\"";
+ result += ">";
+ for (int i = 0; i < length; i++) {
+ result += "" + mInfo[i].getDouble(FFT) + " ";
+ }
+ result += "</scenario>";
+ }
+
+ if(sor_total != 0.0) {
+ result += "<scenario";
+ result += " benchmark=\"" + benchName + "-SOR\" unit=\"mflops\"";
+ result += ">";
+ for (int i = 0; i < length; i++) {
+ result += "" + mInfo[i].getDouble(SOR) + " ";
+ }
+ result += "</scenario>";
+ }
+
+ if(montecarlo_total != 0.0) {
+ result += "<scenario";
+ result += " benchmark=\"" + benchName + "-MonteCarlo\" unit=\"mflops\"";
+ result += ">";
+ for (int i = 0; i < length; i++) {
+ result += "" + mInfo[i].getDouble(MONTECARLO) + " ";
+ }
+ result += "</scenario>";
+ }
+
+ if(sparsematmult_total != 0.0) {
+ result += "<scenario";
+ result += " benchmark=\"" + benchName + "-SparseMatrixMult\" unit=\"mflops\"";
+ result += ">";
+ for (int i = 0; i < length; i++) {
+ result += "" + mInfo[i].getDouble(SPARSEMATMULT) + " ";
+ }
+ result += "</scenario>";
+ }
+
+ if(lu_total != 0.0) {
+ result += "<scenario";
+ result += " benchmark=\"" + benchName + "-LU\" unit=\"mflops\"";
+ result += ">";
+ for (int i = 0; i < length; i++) {
+ result += "" + mInfo[i].getDouble(LU) + " ";
+ }
+ result += "</scenario>";
+ }
+
+ return result;
+ }
+}
+
diff --git a/src/org/zeroxlab/benchmark/Upload.java b/src/org/zeroxlab/benchmark/Upload.java
new file mode 100644
index 0000000..669aab1
--- /dev/null
+++ b/src/org/zeroxlab/benchmark/Upload.java
@@ -0,0 +1,333 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.benchmark;
+
+import org.zeroxlab.benchmark.MicroBenchmark;
+
+import android.util.Log;
+import android.content.SharedPreferences;
+import android.app.Activity;
+import android.os.Bundle;
+import android.content.Intent;
+
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.Toast;
+import android.view.View;
+
+import android.text.TextWatcher;
+import android.text.Editable;
+
+import android.app.Dialog;
+import android.app.AlertDialog;
+import android.app.ProgressDialog;
+import android.content.DialogInterface;
+
+import android.os.SystemClock;
+import android.os.Handler;
+import android.os.Bundle;
+import android.os.Message;
+
+import java.util.HashSet;
+
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+import android.webkit.WebChromeClient;
+import android.webkit.JsResult;
+import android.graphics.Bitmap;
+
+
+public class Upload extends Activity implements View.OnClickListener {
+
+ public final static String TAG = "Upload";
+ public final static String XML = "XML";
+
+ public final static String mMobileLoginUrl = "http://0xbenchmark.appspot.com/mobileLogin";
+
+ EditText mBenchName;
+ EditText mEmail;
+ EditText mAPIKey;
+ Button mLoginGoogle;
+ Button mSend;
+ CheckBox mLogin;
+
+ String mURL;
+ String mXML;
+ String mFailMsg;
+
+ String mHash;
+ HashSet<String> mHashSet = new HashSet<String>();
+
+ MicroBenchmark mb;
+
+ Handler mUploadHandler;
+ Handler mLoginHandler;
+
+ boolean mLogedin = false;
+
+ @Override
+ protected void onCreate(Bundle bundle) {
+ super.onCreate(bundle);
+ setContentView(R.layout.upload);
+
+ mLogin = (CheckBox)findViewById(R.id.login);
+ mLogin.setChecked(false);
+ mLogin.setOnClickListener(this);
+
+ mBenchName = (EditText)findViewById(R.id.benchName);
+ mEmail = (EditText)findViewById(R.id.email);
+ mAPIKey = (EditText)findViewById(R.id.api);
+ mLoginGoogle = (Button)findViewById(R.id.login_google);
+ mLoginGoogle.setOnClickListener(this);
+ mBenchName.setEnabled(false);
+ mEmail.setEnabled(false);
+ mAPIKey.setEnabled(false);
+ mLoginGoogle.setEnabled(false);
+
+ mSend = (Button)findViewById(R.id.send);
+ mSend.setOnClickListener(this);
+
+ Intent intent = getIntent();
+ mXML = intent.getStringExtra(XML);
+
+ mUploadHandler = new Handler() {
+ public void handleMessage(Message msg) {
+ int state = msg.getData().getInt(MicroBenchmark.STATE);
+ if (state != MicroBenchmark.RUNNING) {
+ try {
+ dismissDialog(0);
+ removeDialog(0);
+ } catch (Exception e) {
+ }
+ if (state == MicroBenchmark.DONE) {
+ showDialog(3);
+ showDialog(1);
+ mHashSet.add(mHash);
+ }
+ else {
+ showDialog(2);
+ }
+ Log.e(TAG, msg.getData().getString(MicroBenchmark.MSG));
+ }
+ }
+ };
+
+
+ mLoginHandler = new Handler() {
+ public void handleMessage(Message msg) {
+ dismissDialog(5);
+ }
+ };
+
+
+ }
+
+ public void onClick(View v) {
+ Log.i(TAG, "onclick listener");
+ if (v == mSend) {
+ StringBuffer _mXML;
+ int _index;
+ String attr;
+
+ String benchName = getString(R.string.default_benchname);
+ String apiKey = getString(R.string.default_api);
+ String eMail = getString(R.string.default_email);
+ if (mLogin.isChecked()) {
+ benchName = mBenchName.getText().toString();
+ apiKey = mAPIKey.getText().toString();
+ eMail = mEmail.getText().toString();
+ }
+
+ attr = "";
+ attr += " apiKey=\"" + apiKey + "\"";
+ attr += " benchmark=\"" + benchName + "\"";
+ _mXML = new StringBuffer(mXML);
+ _index = _mXML.indexOf("result") + 6;
+ _mXML.insert(_index, attr);
+ Log.e(TAG, _mXML.toString());
+
+ mURL = "http://" + getString(R.string.default_appspot) + ".appspot.com:80/run/";
+ mb = new MicroBenchmark(_mXML.toString(), mURL, apiKey, benchName, mUploadHandler) ;
+ // this is not really a hash
+ mHash = apiKey + benchName;
+ if(!mHashSet.contains(mHash)){
+ showDialog(0);
+ mb.start();
+ } else {
+ showDialog(4);
+ }
+ } else if (v == mLogin) {
+ if(mLogin.isChecked()) {
+ mBenchName.setEnabled(true);
+ mEmail.setEnabled(true);
+ mAPIKey.setEnabled(true);
+ mLoginGoogle.setEnabled(true);
+ } else {
+ mBenchName.setEnabled(false);
+ mEmail.setEnabled(false);
+ mAPIKey.setEnabled(false);
+ mLoginGoogle.setEnabled(false);
+ }
+ } else if (v == mLoginGoogle) {
+ showDialog(5);
+ }
+
+ }
+
+ protected Dialog onCreateDialog(int id) {
+ switch(id) {
+ case(0):
+ ProgressDialog dialog = new ProgressDialog(this);
+ dialog.setMessage("Uploading, please wait...");
+ return dialog;
+ case(1):
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setMessage("Upload complete.")
+ .setCancelable(false)
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ return builder.create();
+ case(2):
+ AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
+ builder2.setMessage("Upload failed.")
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ return builder2.create();
+ case(3):
+ String url = "http://" + getString(R.string.default_appspot) + ".appspot.com/";
+
+ AlertDialog.Builder builder3 = new AlertDialog.Builder(this);
+ builder3.setMessage( "Please goto " + url + " for results" )
+ .setTitle("Result URL")
+ .setPositiveButton("OK", null)
+ ;
+ return builder3.create();
+ case(4):
+ AlertDialog.Builder builder4 = new AlertDialog.Builder(this);
+ builder4.setMessage( "You have already uploaded results to this location." )
+ .setTitle("Error")
+ .setPositiveButton("OK", null)
+ ;
+ return builder4.create();
+ case(5): // webview
+ Dialog mWebDialog = new Dialog(this);
+ mWebDialog.setContentView(R.layout.login_dialog);
+ mWebDialog.setTitle("Login to Google");
+
+ WebView mWebView = (WebView) mWebDialog.findViewById(R.id.web_view);
+ mWebView.setWebViewClient(new MyWebViewClient());
+ mWebView.setWebChromeClient(new MyWebChromeClient());
+
+ WebSettings webSettings = mWebView.getSettings();
+ webSettings.setJavaScriptEnabled(true);
+ webSettings.setSupportZoom(false);
+
+ mWebView.loadUrl(mMobileLoginUrl);
+ return mWebDialog;
+
+ case(6):
+ ProgressDialog dialog2 = new ProgressDialog(this);
+ dialog2.setMessage("Connecting, please wait...");
+ return dialog2;
+
+ default:
+ return null;
+ }
+ }
+
+ final class MyWebChromeClient extends WebChromeClient {
+ @Override
+ public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
+ Log.e(TAG, message);
+ String [] values = message.split("\t");
+ if (values.length == 3 && values[0].equals("returnValue")) {
+ mEmail.setText(values[1]);
+ mAPIKey.setText(values[2]);
+ mLoginHandler.sendMessage(new Message());
+ }
+ result.confirm();
+ return true;
+ }
+ }
+
+ final class MyWebViewClient extends WebViewClient {
+ @Override
+ public void onPageStarted (WebView view, String url, Bitmap favicon) {
+ super.onPageStarted(view, url, favicon);
+ showDialog(6);
+ }
+ @Override
+ public void onPageFinished (WebView view, String url) {
+ super.onPageFinished(view, url);
+ dismissDialog(6);
+ removeDialog(6);
+ dismissDialog(5);
+ showDialog(5);
+ }
+ @Override
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
+ view.loadUrl(url);
+ return true;
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ SharedPreferences prefs = getPreferences(0);
+ String restoredText;
+ restoredText = prefs.getString("mBenchName", null);
+ if (restoredText != null)
+ mBenchName.setText(restoredText, TextView.BufferType.EDITABLE);
+ restoredText = prefs.getString("mEmail", null);
+ if (restoredText != null)
+ mEmail.setText(restoredText, TextView.BufferType.EDITABLE);
+ restoredText = prefs.getString("mAPIKey", null);
+ if (restoredText != null)
+ mAPIKey.setText(restoredText, TextView.BufferType.EDITABLE);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+
+ SharedPreferences.Editor editor = getPreferences(0).edit();
+ editor.putString("mBenchName",mBenchName.getText().toString());
+ editor.putString("mEmail",mEmail.getText().toString());
+ editor.putString("mAPIKey",mAPIKey.getText().toString());
+ editor.commit();
+ }
+
+ public static String fullClassName() {
+ return "org.zeroxlab.benchmark.Upload";
+ }
+
+ public static String packageName() {
+ return "org.zeroxlab.benchmark";
+ }
+
+}
diff --git a/src/org/zeroxlab/gc/GCBench.java b/src/org/zeroxlab/gc/GCBench.java
new file mode 100644
index 0000000..2224b62
--- /dev/null
+++ b/src/org/zeroxlab/gc/GCBench.java
@@ -0,0 +1,182 @@
+// This is adapted from a benchmark written by John Ellis and Pete Kovac
+// of Post Communications.
+// It was modified by Hans Boehm of Silicon Graphics.
+//
+// This is no substitute for real applications. No actual application
+// is likely to behave in exactly this way. However, this benchmark was
+// designed to be more representative of real applications than other
+// Java GC benchmarks of which we are aware.
+// It attempts to model those properties of allocation requests that
+// are important to current GC techniques.
+// It is designed to be used either to obtain a single overall performance
+// number, or to give a more detailed estimate of how collector
+// performance varies with object lifetimes. It prints the time
+// required to allocate and collect balanced binary trees of various
+// sizes. Smaller trees result in shorter object lifetimes. Each cycle
+// allocates roughly the same amount of memory.
+// Two data structures are kept around during the entire process, so
+// that the measured performance is representative of applications
+// that maintain some live in-memory data. One of these is a tree
+// containing many pointers. The other is a large array containing
+// double precision floating point numbers. Both should be of comparable
+// size.
+//
+// The results are only really meaningful together with a specification
+// of how much memory was used. It is possible to trade memory for
+// better time performance. This benchmark should be run in a 32 MB
+// heap, though we don't currently know how to enforce that uniformly.
+//
+// Unlike the original Ellis and Kovac benchmark, we do not attempt
+// measure pause times. This facility should eventually be added back
+// in. There are several reasons for omitting it for now. The original
+// implementation depended on assumptions about the thread scheduler
+// that don't hold uniformly. The results really measure both the
+// scheduler and GC. Pause time measurements tend to not fit well with
+// current benchmark suites. As far as we know, none of the current
+// commercial Java implementations seriously attempt to minimize GC pause
+// times.
+//
+// Known deficiencies:
+// - No way to check on memory use
+// - No cyclic data structures
+// - No attempt to measure variation with object size
+// - Results are sensitive to locking cost, but we dont
+// check for proper locking
+
+class Node {
+ Node left, right;
+ int i, j;
+ Node(Node l, Node r) { left = l; right = r; }
+ Node() { }
+}
+
+public class GCBench {
+
+ public static final int kStretchTreeDepth = 18; // about 16Mb
+ public static final int kLongLivedTreeDepth = 16; // about 4Mb
+ public static final int kArraySize = 500000; // about 4Mb
+ public static final int kMinTreeDepth = 4;
+ public static final int kMaxTreeDepth = 16;
+
+ // Nodes used by a tree of a given size
+ static int TreeSize(int i) {
+ return ((1 << (i + 1)) - 1);
+ }
+
+ // Number of iterations to use for a given tree depth
+ static int NumIters(int i) {
+ return 2 * TreeSize(kStretchTreeDepth) / TreeSize(i);
+ }
+
+ // Build tree top down, assigning to older objects.
+ static void Populate(int iDepth, Node thisNode) {
+ if (iDepth<=0) {
+ return;
+ } else {
+ iDepth--;
+ thisNode.left = new Node();
+ thisNode.right = new Node();
+ Populate (iDepth, thisNode.left);
+ Populate (iDepth, thisNode.right);
+ }
+ }
+
+ // Build tree bottom-up
+ static Node MakeTree(int iDepth) {
+ if (iDepth<=0) {
+ return new Node();
+ } else {
+ return new Node(MakeTree(iDepth-1),
+ MakeTree(iDepth-1));
+ }
+ }
+
+ static void PrintDiagnostics() {
+ long lFreeMemory = Runtime.getRuntime().freeMemory();
+ long lTotalMemory = Runtime.getRuntime().totalMemory();
+
+ System.out.print(" Total memory available="
+ + lTotalMemory + " bytes");
+ System.out.println(" Free memory=" + lFreeMemory + " bytes");
+ }
+
+ static void TimeConstruction(int depth) {
+ Node root;
+ long tStart, tFinish;
+ int iNumIters = NumIters(depth);
+ Node tempTree;
+
+ System.out.println("Creating " + iNumIters +
+ " trees of depth " + depth);
+ tStart = System.currentTimeMillis();
+ for (int i = 0; i < iNumIters; ++i) {
+ tempTree = new Node();
+ Populate(depth, tempTree);
+ tempTree = null;
+ }
+ tFinish = System.currentTimeMillis();
+ System.out.println("\tTop down construction took "
+ + (tFinish - tStart) + "msecs");
+ tStart = System.currentTimeMillis();
+ for (int i = 0; i < iNumIters; ++i) {
+ tempTree = MakeTree(depth);
+ tempTree = null;
+ }
+ tFinish = System.currentTimeMillis();
+ System.out.println("\tBottom up construction took "
+ + (tFinish - tStart) + "msecs");
+
+ }
+
+ public static void main(String args[]) {
+ Node root;
+ Node longLivedTree;
+ Node tempTree;
+ long tStart, tFinish;
+ long tElapsed;
+
+
+ System.out.println("Garbage Collector Test");
+ System.out.println(
+ " Stretching memory with a binary tree of depth "
+ + kStretchTreeDepth);
+ PrintDiagnostics();
+ tStart = System.currentTimeMillis();
+
+ // Stretch the memory space quickly
+ tempTree = MakeTree(kStretchTreeDepth);
+ tempTree = null;
+
+ // Create a long lived object
+ System.out.println(
+ " Creating a long-lived binary tree of depth " +
+ kLongLivedTreeDepth);
+ longLivedTree = new Node();
+ Populate(kLongLivedTreeDepth, longLivedTree);
+
+ // Create long-lived array, filling half of it
+ System.out.println(
+ " Creating a long-lived array of "
+ + kArraySize + " doubles");
+ double array[] = new double[kArraySize];
+ for (int i = 0; i < kArraySize/2; ++i) {
+ array[i] = 1.0/i;
+ }
+ PrintDiagnostics();
+
+ for (int d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2) {
+ TimeConstruction(d);
+ }
+
+ if (longLivedTree == null || array[1000] != 1.0/1000)
+ System.out.println("Failed");
+ // fake reference to LongLivedTree
+ // and array
+ // to keep them from being optimized away
+
+ tFinish = System.currentTimeMillis();
+ tElapsed = tFinish-tStart;
+ PrintDiagnostics();
+ System.out.println("Completed in " + tElapsed + "ms.");
+ }
+} // class JavaGC
diff --git a/src/org/zeroxlab/gc/GCBenchmark.java b/src/org/zeroxlab/gc/GCBenchmark.java
new file mode 100644
index 0000000..cce6c85
--- /dev/null
+++ b/src/org/zeroxlab/gc/GCBenchmark.java
@@ -0,0 +1,201 @@
+/*
+ * This is adapted from a benchmark written by John Ellis and Pete Kovac
+ * of Post Communications.
+ * It was modified by Hans Boehm of Silicon Graphics.
+ *
+ * This is no substitute for real applications. No actual application
+ * is likely to behave in exactly this way. However, this benchmark was
+ * designed to be more representative of real applications than other
+ * Java GC benchmarks of which we are aware.
+ * It attempts to model those properties of allocation requests that
+ * are important to current GC techniques.
+ * It is designed to be used either to obtain a single overall performance
+ * number, or to give a more detailed estimate of how collector
+ * performance varies with object lifetimes. It prints the time
+ * required to allocate and collect balanced binary trees of various
+ * sizes. Smaller trees result in shorter object lifetimes. Each cycle
+ * allocates roughly the same amount of memory.
+ * Two data structures are kept around during the entire process, so
+ * that the measured performance is representative of applications
+ * that maintain some live in-memory data. One of these is a tree
+ * containing many pointers. The other is a large array containing
+ * double precision floating point numbers. Both should be of comparable
+ * size.
+ *
+ * The results are only really meaningful together with a specification
+ * of how much memory was used. It is possible to trade memory for
+ * better time performance. This benchmark should be run in a 32 MB
+ * heap, though we don't currently know how to enforce that uniformly.
+ * Unlike the original Ellis and Kovac benchmark, we do not attempt
+ * measure pause times. This facility should eventually be added back
+ * in. There are several reasons for omitting it for now. The original
+ * implementation depended on assumptions about the thread scheduler
+ * that don't hold uniformly. The results really measure both the
+ * scheduler and GC. Pause time measurements tend to not fit well with
+ * current benchmark suites. As far as we know, none of the current
+ * commercial Java implementations seriously attempt to minimize GC pause
+ * times.
+ *
+ * Known deficiencies:
+ * - No way to check on memory use
+ * - No cyclic data structures
+ * - No attempt to measure variation with object size
+ * - Results are sensitive to locking cost, but we dont
+ * check for proper locking
+ */
+
+package org.zeroxlab.gc;
+
+import org.zeroxlab.benchmark.TesterGC;
+
+import android.os.Message;
+
+class Node {
+ Node left, right;
+ int i, j;
+ Node(Node l, Node r) { left = l; right = r; }
+ Node() { }
+}
+
+public class GCBenchmark {
+ public static final int kStretchTreeDepth = 16; // about 8Mb
+ public static final int kLongLivedTreeDepth = 14; // about 2Mb
+ public static final int kArraySize = 125000; // about 2Mb
+ public static final int kMinTreeDepth = 2;
+ public static final int kMaxTreeDepth = 8;
+
+ public static StringBuffer out = new StringBuffer();
+
+ static void update(String s){
+ out.append(s+"\n");
+ Message m = new Message();
+ m.what = TesterGC.GUINOTIFIER;
+ TesterGC.mHandler.sendMessage(m);
+ }
+
+ // Nodes used by a tree of a given size
+ static int TreeSize(int i) {
+ return ((1 << (i + 1)) - 1);
+ }
+
+ // Number of iterations to use for a given tree depth
+ static int NumIters(int i) {
+ return 2 * TreeSize(kStretchTreeDepth) / TreeSize(i);
+ }
+
+ // Build tree top down, assigning to older objects.
+ static void Populate(int iDepth, Node thisNode) {
+ if (iDepth<=0) {
+ return;
+ } else {
+ iDepth--;
+ thisNode.left = new Node();
+ thisNode.right = new Node();
+ Populate (iDepth, thisNode.left);
+ Populate (iDepth, thisNode.right);
+ }
+ }
+
+ // Build tree bottom-up
+ static Node MakeTree(int iDepth) {
+ if (iDepth<=0) {
+ return new Node();
+ } else {
+ return new Node(MakeTree(iDepth-1),
+ MakeTree(iDepth-1));
+ }
+ }
+
+ static void PrintDiagnostics() {
+ long lFreeMemory = Runtime.getRuntime().freeMemory();
+ long lTotalMemory = Runtime.getRuntime().totalMemory();
+
+ update("*Total memory:"
+ + lTotalMemory + " bytes");
+ update("*Free memory:" + lFreeMemory + " bytes\n");
+ }
+
+ static void TimeConstruction(int depth) {
+ Node root;
+ long tStart, tFinish;
+ int iNumIters = NumIters(depth);
+ Node tempTree;
+
+ update("Create " + iNumIters +
+ " trees of depth " + depth);
+ tStart = System.currentTimeMillis();
+ for (int i = 0; i < iNumIters; ++i) {
+ tempTree = new Node();
+ Populate(depth, tempTree);
+ tempTree = null;
+ }
+ tFinish = System.currentTimeMillis();
+ update("- Top down: "
+ + (tFinish - tStart) + "msecs");
+ tStart = System.currentTimeMillis();
+ for (int i = 0; i < iNumIters; ++i) {
+ tempTree = MakeTree(depth);
+ tempTree = null;
+ }
+ tFinish = System.currentTimeMillis();
+ update("- Bottom up: "
+ + (tFinish - tStart) + "msecs");
+
+ }
+
+ public static void benchmark() {
+ out = new StringBuffer();
+ Node root;
+ Node longLivedTree;
+ Node tempTree;
+ long tStart, tFinish;
+ long tElapsed;
+
+ // Debug.startMethodTracing("gcbench");
+ // update("Garbage Collector Test");
+ update(
+ "Stretching memory:\n binary tree of depth "
+ + kStretchTreeDepth);
+ PrintDiagnostics();
+ tStart = System.currentTimeMillis();
+
+ // Stretch the memory space quickly
+ tempTree = MakeTree(kStretchTreeDepth);
+ tempTree = null;
+
+ // Create a long lived object
+ update(
+ "Creating:\n long-lived binary tree of depth " +
+ kLongLivedTreeDepth);
+ longLivedTree = new Node();
+ Populate(kLongLivedTreeDepth, longLivedTree);
+
+ // Create long-lived array, filling half of it
+ update(
+ " long-lived array of "
+ + kArraySize + " doubles");
+ double array[] = new double[kArraySize];
+ for (int i = 0; i < kArraySize/2; ++i) {
+ array[i] = 1.0/i;
+ }
+ PrintDiagnostics();
+
+ for (int d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2) {
+ TimeConstruction(d);
+ }
+
+ if (longLivedTree == null || array[1000] != 1.0/1000)
+ update("Failed");
+ // fake reference to LongLivedTree
+ // and array
+ // to keep them from being optimized away
+
+ tFinish = System.currentTimeMillis();
+ tElapsed = tFinish-tStart;
+ PrintDiagnostics();
+ update("Completed in " + tElapsed + "ms.");
+ TesterGC.time = tElapsed;
+ //Debug.stopMethodTracing();
+ }
+}
+
diff --git a/src/org/zeroxlab/graphics/DrawCircle.java b/src/org/zeroxlab/graphics/DrawCircle.java
new file mode 100644
index 0000000..93daea6
--- /dev/null
+++ b/src/org/zeroxlab/graphics/DrawCircle.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2010 0xlab - http://0xlab.org/
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.graphics;
+
+import org.zeroxlab.benchmark.Tester;
+
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+
+import android.os.Bundle;
+import android.view.View;
+
+public class DrawCircle extends Tester {
+ /** Called when the activity is first created. */
+
+ SampleView mView;
+
+ public String getTag() {
+ return "DrawCircle";
+ }
+
+ public int sleepBeforeStart() {
+ return 1000;
+ }
+
+ public int sleepBetweenRound() {
+ return 0;
+ }
+
+ public void oneRound() {
+ mView.postInvalidate();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mView = new SampleView(this);
+ setContentView(mView);
+ }
+
+ private class SampleView extends View {
+ private Paint[] mPaints;
+ private Paint mFramePaint;
+
+ private float mSweep;
+ private int mBigIndex;
+
+ private final float SWEEP_INC = 2;
+ private int counter = 0;
+ int i, row;
+ long current;
+ long last;
+
+ public SampleView(Context context) {
+ super(context);
+
+ mPaints = new Paint[4];
+
+ mPaints[0] = new Paint();
+ mPaints[0].setAntiAlias(true);
+ mPaints[0].setStyle(Paint.Style.FILL);
+ mPaints[0].setColor(0x88FF0000);
+
+ mPaints[1] = new Paint(mPaints[0]);
+ mPaints[1].setColor(0x8800FF00);
+
+ mPaints[2] = new Paint(mPaints[0]);
+ mPaints[2].setStyle(Paint.Style.STROKE);
+ mPaints[2].setStrokeWidth(4);
+ mPaints[2].setColor(0x880000FF);
+
+ mPaints[3] = new Paint(mPaints[2]);
+ mPaints[3].setColor(0x88888888);
+
+ mFramePaint = new Paint();
+ mFramePaint.setAntiAlias(true);
+ mFramePaint.setTextSize(40);
+ mFramePaint.setStyle(Paint.Style.STROKE);
+ mFramePaint.setStrokeWidth(0);
+ }
+
+ @Override
+ protected void onWindowVisibilityChanged(int visibility) {
+ super.onWindowVisibilityChanged(visibility);
+ if (visibility != View.VISIBLE) {
+ return;
+ }
+
+ startTester();
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ canvas.drawColor(Color.WHITE);
+
+ canvas.drawCircle(160f, 150f, 120f, mPaints[mBigIndex]);
+ canvas.drawText(counter + "th time", 30, 160, mFramePaint);
+ canvas.drawText((current - last) + "ms", 30, 200, mFramePaint);
+
+ for (row = 0; row < 8; row++) {
+ for (i = 0; i < 4; i++) {
+ canvas.drawCircle(40.0f + i * 80, 40.0f + row * 60, mSweep,
+ mPaints[i]);
+ }
+ }
+
+ mSweep += SWEEP_INC;
+ if (mSweep > 80) {
+ mSweep -= 80;
+ mBigIndex = (mBigIndex + 1) % 4;
+ counter++;
+ last = current;
+ current = System.currentTimeMillis();
+
+ }
+
+ invalidate();
+ decreaseCounter();
+ }
+ }
+}
diff --git a/src/org/zeroxlab/kubench/Cube.java b/src/org/zeroxlab/kubench/Cube.java
new file mode 100644
index 0000000..c164208
--- /dev/null
+++ b/src/org/zeroxlab/kubench/Cube.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.kubench;
+
+
+public class Cube extends GLShape {
+
+ public Cube(GLWorld world, float left, float bottom, float back, float right, float top, float front) {
+ super(world);
+ GLVertex leftBottomBack = addVertex(left, bottom, back);
+ GLVertex rightBottomBack = addVertex(right, bottom, back);
+ GLVertex leftTopBack = addVertex(left, top, back);
+ GLVertex rightTopBack = addVertex(right, top, back);
+ GLVertex leftBottomFront = addVertex(left, bottom, front);
+ GLVertex rightBottomFront = addVertex(right, bottom, front);
+ GLVertex leftTopFront = addVertex(left, top, front);
+ GLVertex rightTopFront = addVertex(right, top, front);
+
+ // vertices are added in a clockwise orientation (when viewed from the outside)
+ // bottom
+ addFace(new GLFace(leftBottomBack, leftBottomFront, rightBottomFront, rightBottomBack));
+ // front
+ addFace(new GLFace(leftBottomFront, leftTopFront, rightTopFront, rightBottomFront));
+ // left
+ addFace(new GLFace(leftBottomBack, leftTopBack, leftTopFront, leftBottomFront));
+ // right
+ addFace(new GLFace(rightBottomBack, rightBottomFront, rightTopFront, rightTopBack));
+ // back
+ addFace(new GLFace(leftBottomBack, rightBottomBack, rightTopBack, leftTopBack));
+ // top
+ addFace(new GLFace(leftTopBack, rightTopBack, rightTopFront, leftTopFront));
+
+ }
+
+ public static final int kBottom = 0;
+ public static final int kFront = 1;
+ public static final int kLeft = 2;
+ public static final int kRight = 3;
+ public static final int kBack = 4;
+ public static final int kTop = 5;
+
+
+}
diff --git a/src/org/zeroxlab/kubench/GLColor.java b/src/org/zeroxlab/kubench/GLColor.java
new file mode 100644
index 0000000..eb247ec
--- /dev/null
+++ b/src/org/zeroxlab/kubench/GLColor.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.kubench;
+
+public class GLColor {
+
+ public final int red;
+ public final int green;
+ public final int blue;
+ public final int alpha;
+
+ public GLColor(int red, int green, int blue, int alpha) {
+ this.red = red;
+ this.green = green;
+ this.blue = blue;
+ this.alpha = alpha;
+ }
+
+ public GLColor(int red, int green, int blue) {
+ this.red = red;
+ this.green = green;
+ this.blue = blue;
+ this.alpha = 0x10000;
+ }
+
+ public boolean equals(Object other) {
+ if (other instanceof GLColor) {
+ GLColor color = (GLColor)other;
+ return (red == color.red && green == color.green &&
+ blue == color.blue && alpha == color.alpha);
+ }
+ return false;
+ }
+}
diff --git a/src/org/zeroxlab/kubench/GLFace.java b/src/org/zeroxlab/kubench/GLFace.java
new file mode 100644
index 0000000..e48fb51
--- /dev/null
+++ b/src/org/zeroxlab/kubench/GLFace.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.kubench;
+
+import android.util.Log;
+
+import java.nio.ShortBuffer;
+import java.util.ArrayList;
+
+public class GLFace {
+
+ public GLFace() {
+
+ }
+
+ // for triangles
+ public GLFace(GLVertex v1, GLVertex v2, GLVertex v3) {
+ addVertex(v1);
+ addVertex(v2);
+ addVertex(v3);
+ }
+ // for quadrilaterals
+ public GLFace(GLVertex v1, GLVertex v2, GLVertex v3, GLVertex v4) {
+ addVertex(v1);
+ addVertex(v2);
+ addVertex(v3);
+ addVertex(v4);
+ }
+
+ public void addVertex(GLVertex v) {
+ mVertexList.add(v);
+ }
+
+ // must be called after all vertices are added
+ public void setColor(GLColor c) {
+
+ int last = mVertexList.size() - 1;
+ if (last < 2) {
+ Log.e("GLFace", "not enough vertices in setColor()");
+ } else {
+ GLVertex vertex = mVertexList.get(last);
+
+ // only need to do this if the color has never been set
+ if (mColor == null) {
+ while (vertex.color != null) {
+ mVertexList.add(0, vertex);
+ mVertexList.remove(last + 1);
+ vertex = mVertexList.get(last);
+ }
+ }
+
+ vertex.color = c;
+ }
+
+ mColor = c;
+ }
+
+ public int getIndexCount() {
+ return (mVertexList.size() - 2) * 3;
+ }
+
+ public void putIndices(ShortBuffer buffer) {
+ int last = mVertexList.size() - 1;
+
+ GLVertex v0 = mVertexList.get(0);
+ GLVertex vn = mVertexList.get(last);
+
+ // push triangles into the buffer
+ for (int i = 1; i < last; i++) {
+ GLVertex v1 = mVertexList.get(i);
+ buffer.put(v0.index);
+ buffer.put(v1.index);
+ buffer.put(vn.index);
+ v0 = v1;
+ }
+ }
+
+ private ArrayList<GLVertex> mVertexList = new ArrayList<GLVertex>();
+ private GLColor mColor;
+}
diff --git a/src/org/zeroxlab/kubench/GLShape.java b/src/org/zeroxlab/kubench/GLShape.java
new file mode 100644
index 0000000..7535b15
--- /dev/null
+++ b/src/org/zeroxlab/kubench/GLShape.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.kubench;
+
+import java.nio.ShortBuffer;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+public class GLShape {
+
+ public GLShape(GLWorld world) {
+ mWorld = world;
+ }
+
+ public void addFace(GLFace face) {
+ mFaceList.add(face);
+ }
+
+ public void setFaceColor(int face, GLColor color) {
+ mFaceList.get(face).setColor(color);
+ }
+
+ public void putIndices(ShortBuffer buffer) {
+ Iterator<GLFace> iter = mFaceList.iterator();
+ while (iter.hasNext()) {
+ GLFace face = iter.next();
+ face.putIndices(buffer);
+ }
+ }
+
+ public int getIndexCount() {
+ int count = 0;
+ Iterator<GLFace> iter = mFaceList.iterator();
+ while (iter.hasNext()) {
+ GLFace face = iter.next();
+ count += face.getIndexCount();
+ }
+ return count;
+ }
+
+ public GLVertex addVertex(float x, float y, float z) {
+
+ // look for an existing GLVertex first
+ Iterator<GLVertex> iter = mVertexList.iterator();
+ while (iter.hasNext()) {
+ GLVertex vertex = iter.next();
+ if (vertex.x == x && vertex.y == y && vertex.z == z) {
+ return vertex;
+ }
+ }
+
+ // doesn't exist, so create new vertex
+ GLVertex vertex = mWorld.addVertex(x, y, z);
+ mVertexList.add(vertex);
+ return vertex;
+ }
+
+ public void animateTransform(M4 transform) {
+ mAnimateTransform = transform;
+
+ if (mTransform != null)
+ transform = mTransform.multiply(transform);
+
+ Iterator<GLVertex> iter = mVertexList.iterator();
+ while (iter.hasNext()) {
+ GLVertex vertex = iter.next();
+ mWorld.transformVertex(vertex, transform);
+ }
+ }
+
+ public void startAnimation() {
+ }
+
+ public void endAnimation() {
+ if (mTransform == null) {
+ mTransform = new M4(mAnimateTransform);
+ } else {
+ mTransform = mTransform.multiply(mAnimateTransform);
+ }
+ }
+
+ public M4 mTransform;
+ public M4 mAnimateTransform;
+ protected ArrayList<GLFace> mFaceList = new ArrayList<GLFace>();
+ protected ArrayList<GLVertex> mVertexList = new ArrayList<GLVertex>();
+ protected ArrayList<Integer> mIndexList = new ArrayList<Integer>(); // make more efficient?
+ protected GLWorld mWorld;
+}
diff --git a/src/org/zeroxlab/kubench/GLSurfaceView.java b/src/org/zeroxlab/kubench/GLSurfaceView.java
new file mode 100644
index 0000000..953379e
--- /dev/null
+++ b/src/org/zeroxlab/kubench/GLSurfaceView.java
@@ -0,0 +1,322 @@
+/*
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.kubench;
+
+import org.zeroxlab.benchmark.Tester;
+
+import android.app.Activity;
+import android.content.Context;
+import android.util.Log;
+import android.view.SurfaceHolder;
+import android.view.SurfaceView;
+
+import javax.microedition.khronos.egl.*;
+import javax.microedition.khronos.opengles.*;
+
+
+/**
+ * Example of how to use OpenGL|ES in a custom view
+ *
+ */
+public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
+ SurfaceHolder mHolder;
+ private GLThread mGLThread;
+ private GLWorld mWorld;
+ private float mAngle;
+ private GLSurfaceViewClient mClient;
+ private Tester mTester;
+
+ /**
+ * The View constructor is a good place to allocate our OpenGL context
+ */
+ public GLSurfaceView(Context context, GLWorld world, Tester tester) {
+ super(context);
+ mTester = tester;
+ mWorld = world;
+ mHolder = getHolder();
+ mHolder.addCallback(this);
+ mHolder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
+ }
+
+ public void surfaceCreated(SurfaceHolder holder) {
+ // The Surface has been created, start our main acquisition thread.
+ Log.d("GLSurfaceView", "surfaceCreated");
+ mGLThread = new GLThread();
+ mGLThread.start();
+ }
+
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ // Surface will be destroyed when we return
+ Log.d("GLSurfaceView", "surfaceDestroyed");
+ mGLThread.requestExitAndWait();
+ mGLThread = null;
+ }
+
+ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
+ // Surface size or format has changed. This should not happen in this
+ // example.
+ Log.d("GLSurfaceView", "surfaceChanged");
+ mGLThread.onWindowResize(w, h);
+ }
+
+ public float getAngle() {
+ return mAngle;
+ }
+
+ public void setAngle(float angle) {
+ mAngle = angle;
+ }
+
+ public void setClient(GLSurfaceViewClient client) {
+ mClient = client;
+ }
+
+ // ----------------------------------------------------------------------
+
+ public interface GLSurfaceViewClient {
+ public void animate();
+ }
+
+ public float getFramerate() {
+ return mGLThread.getFramerate();
+ }
+
+ // ----------------------------------------------------------------------
+
+ class GLThread extends Thread {
+ private boolean mDone;
+ private int mWidth;
+ private int mHeight;
+ private float mFramerate;
+
+ GLThread() {
+ super();
+ mDone = false;
+ mWidth = 0;
+ mHeight = 0;
+ mFramerate = 0.0f;
+ }
+
+ public float getFramerate() {
+ return mFramerate;
+ }
+
+ @Override
+ public void run() {
+ /*
+ * Get an EGL instance
+ */
+ EGL10 egl = (EGL10)EGLContext.getEGL();
+
+ /*
+ * Get to the default display.
+ */
+ EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
+
+ /*
+ * We can now initialize EGL for that display
+ */
+ int[] version = new int[2];
+ egl.eglInitialize(dpy, version);
+
+ /*
+ * Specify a configuration for our opengl session
+ * and grab the first configuration that matches is
+ */
+ int[] configSpec = {
+ EGL10.EGL_DEPTH_SIZE, 16,
+ EGL10.EGL_NONE
+ };
+ EGLConfig[] configs = new EGLConfig[1];
+ int[] num_config = new int[1];
+ egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config);
+ EGLConfig config = configs[0];
+
+ /*
+ * Create an OpenGL ES context. This must be done only once, an
+ * OpenGL context is a somewhat heavy object.
+ */
+ EGLContext context = egl.eglCreateContext(dpy, config,
+ EGL10.EGL_NO_CONTEXT, null);
+
+ /*
+ * Create an EGL surface we can render into.
+ */
+ EGLSurface surface = egl.eglCreateWindowSurface(dpy, config, mHolder, null);
+
+ /*
+ * Before we can issue GL commands, we need to make sure
+ * the context is current and bound to a surface.
+ */
+ egl.eglMakeCurrent(dpy, surface, surface, context);
+
+ /*
+ * Get to the appropriate GL interface.
+ * This is simply done by casting the GL context to either
+ * GL10 or GL11.
+ */
+ GL10 gl = (GL10)context.getGL();
+
+
+ /*
+ * Some one-time OpenGL initialization can be made here
+ * probably based on features of this particular context
+ */
+ gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
+
+
+ // This is our main acquisition thread's loop, we go until
+ // asked to quit.
+ long starttime=0, stoptime=0, drawcount=0;
+ long startTester = System.currentTimeMillis();
+ while (!mDone) {
+ // Update the asynchronous state (window size, key events)
+ int w, h;
+ synchronized(this) {
+ w = mWidth;
+ h = mHeight;
+ }
+ if (starttime == 0) {
+ starttime = System.currentTimeMillis();
+ }
+
+ /* draw a frame here */
+ drawFrame(gl, w, h);
+
+ /*
+ * Once we're done with GL, we need to call post()
+ */
+ egl.eglSwapBuffers(dpy, surface);
+ gl.glFinish();
+ mTester.decreaseCounter();
+ mDone = mTester.isTesterFinished();
+ drawcount++;
+ stoptime = System.currentTimeMillis();
+ if (stoptime - starttime >= 1) {
+ mFramerate = (float)(1000 * drawcount)/(float)(stoptime - starttime);
+ drawcount = 0;
+ }
+
+ /*
+ * Always check for EGL_CONTEXT_LOST, which means the context
+ * and all associated data were lost (For instance because
+ * the device went to sleep). We need to quit immediately.
+ */
+ if (egl.eglGetError() == EGL11.EGL_CONTEXT_LOST) {
+ // we lost the gpu, quit immediately
+ Context c = getContext();
+ if (c instanceof Activity) {
+ ((Activity)c).finish();
+ }
+ }
+ }
+
+ long stopTester = System.currentTimeMillis();
+ /*
+ * clean-up everything...
+ */
+ egl.eglMakeCurrent(dpy,
+ EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
+ egl.eglDestroyContext(dpy, context);
+ egl.eglDestroySurface(dpy, surface);
+ egl.eglTerminate(dpy);
+ mTester.finishTester(startTester, stopTester);
+ }
+
+ private void drawFrame(GL10 gl, int w, int h) {
+ gl.glViewport(0, 0, w, h);
+
+ /*
+ * Set our projection matrix. This doesn't have to be done
+ * each time we draw, but usually a new projection needs to be set
+ * when the viewport is resized.
+ */
+
+ float ratio = (float)w / h;
+ gl.glMatrixMode(GL10.GL_PROJECTION);
+ gl.glLoadIdentity();
+ gl.glFrustumf(-ratio, ratio, -1, 1, 2, 12);
+
+ /*
+ * By default, OpenGL enables features that improve quality
+ * but reduce performance. One might want to tweak that
+ * especially on software renderer.
+ */
+ gl.glDisable(GL10.GL_DITHER);
+ gl.glActiveTexture(GL10.GL_TEXTURE0);
+ gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
+ gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
+ gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
+ gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST);
+ gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
+ gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);
+
+ /*
+ * Usually, the first thing one might want to do is to clear
+ * the screen. The most efficient way of doing this is to use
+ * glClear(). However we must make sure to set the scissor
+ * correctly first. The scissor is always specified in window
+ * coordinates:
+ */
+
+ gl.glClearColor(0.5f,0.5f,0.5f,1);
+ gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
+
+ /*
+ * Now we're ready to draw some 3D object
+ */
+
+ gl.glMatrixMode(GL10.GL_MODELVIEW);
+ gl.glLoadIdentity();
+ gl.glTranslatef(0, 0, -3.0f);
+ gl.glScalef(0.5f, 0.5f, 0.5f);
+ gl.glRotatef(mAngle, 0, 1, 0);
+ gl.glRotatef(mAngle*0.25f, 1, 0, 0);
+
+ gl.glColor4f(0.7f, 0.7f, 0.7f, 1.0f);
+ gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
+ gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
+ gl.glEnable(GL10.GL_CULL_FACE);
+ gl.glShadeModel(GL10.GL_SMOOTH);
+ gl.glEnable(GL10.GL_DEPTH_TEST);
+
+ mWorld.draw(gl);
+
+ if (mClient != null) {
+ mClient.animate();
+ }
+ }
+
+ public void onWindowResize(int w, int h) {
+ synchronized(this) {
+ mWidth = w;
+ mHeight = h;
+ }
+ }
+
+ public void requestExitAndWait() {
+ // don't call this from GLThread thread or it a guaranteed
+ // deadlock!
+ mDone = true;
+ try {
+ join();
+ } catch (InterruptedException ex) { }
+ }
+ }
+}
+
+
diff --git a/src/org/zeroxlab/kubench/GLVertex.java b/src/org/zeroxlab/kubench/GLVertex.java
new file mode 100644
index 0000000..cf11cca
--- /dev/null
+++ b/src/org/zeroxlab/kubench/GLVertex.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.kubench;
+
+import java.nio.IntBuffer;
+
+public class GLVertex {
+
+ public float x;
+ public float y;
+ public float z;
+ final short index; // index in vertex table
+ GLColor color;
+
+ GLVertex() {
+ this.x = 0;
+ this.y = 0;
+ this.z = 0;
+ this.index = -1;
+ }
+
+ GLVertex(float x, float y, float z, int index) {
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.index = (short)index;
+ }
+
+ public boolean equals(Object other) {
+ if (other instanceof GLVertex) {
+ GLVertex v = (GLVertex)other;
+ return (x == v.x && y == v.y && z == v.z);
+ }
+ return false;
+ }
+
+ static public int toFixed(float x) {
+ return (int)(x*65536.0f);
+ }
+
+ public void put(IntBuffer vertexBuffer, IntBuffer colorBuffer) {
+ vertexBuffer.put(toFixed(x));
+ vertexBuffer.put(toFixed(y));
+ vertexBuffer.put(toFixed(z));
+ if (color == null) {
+ colorBuffer.put(0);
+ colorBuffer.put(0);
+ colorBuffer.put(0);
+ colorBuffer.put(0);
+ } else {
+ colorBuffer.put(color.red);
+ colorBuffer.put(color.green);
+ colorBuffer.put(color.blue);
+ colorBuffer.put(color.alpha);
+ }
+ }
+
+ public void update(IntBuffer vertexBuffer, M4 transform) {
+ // skip to location of vertex in mVertex buffer
+ vertexBuffer.position(index * 3);
+
+ if (transform == null) {
+ vertexBuffer.put(toFixed(x));
+ vertexBuffer.put(toFixed(y));
+ vertexBuffer.put(toFixed(z));
+ } else {
+ GLVertex temp = new GLVertex();
+ transform.multiply(this, temp);
+ vertexBuffer.put(toFixed(temp.x));
+ vertexBuffer.put(toFixed(temp.y));
+ vertexBuffer.put(toFixed(temp.z));
+ }
+ }
+}
diff --git a/src/org/zeroxlab/kubench/GLWorld.java b/src/org/zeroxlab/kubench/GLWorld.java
new file mode 100644
index 0000000..3b17ff0
--- /dev/null
+++ b/src/org/zeroxlab/kubench/GLWorld.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.kubench;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.IntBuffer;
+import java.nio.ShortBuffer;
+import java.util.Iterator;
+import java.util.ArrayList;
+
+import javax.microedition.khronos.opengles.GL10;
+
+public class GLWorld {
+
+ public void addShape(GLShape shape) {
+ mShapeList.add(shape);
+ mIndexCount += shape.getIndexCount();
+ }
+
+ public void generate() {
+ ByteBuffer bb = ByteBuffer.allocateDirect(mVertexList.size()*4*4);
+ bb.order(ByteOrder.nativeOrder());
+ mColorBuffer = bb.asIntBuffer();
+
+ bb = ByteBuffer.allocateDirect(mVertexList.size()*4*3);
+ bb.order(ByteOrder.nativeOrder());
+ mVertexBuffer = bb.asIntBuffer();
+
+ bb = ByteBuffer.allocateDirect(mIndexCount*2);
+ bb.order(ByteOrder.nativeOrder());
+ mIndexBuffer = bb.asShortBuffer();
+
+ Iterator<GLVertex> iter2 = mVertexList.iterator();
+ while (iter2.hasNext()) {
+ GLVertex vertex = iter2.next();
+ vertex.put(mVertexBuffer, mColorBuffer);
+ }
+
+ Iterator<GLShape> iter3 = mShapeList.iterator();
+ while (iter3.hasNext()) {
+ GLShape shape = iter3.next();
+ shape.putIndices(mIndexBuffer);
+ }
+ }
+
+ public GLVertex addVertex(float x, float y, float z) {
+ GLVertex vertex = new GLVertex(x, y, z, mVertexList.size());
+ mVertexList.add(vertex);
+ return vertex;
+ }
+
+ public void transformVertex(GLVertex vertex, M4 transform) {
+ vertex.update(mVertexBuffer, transform);
+ }
+
+ int count = 0;
+ public void draw(GL10 gl)
+ {
+ mColorBuffer.position(0);
+ mVertexBuffer.position(0);
+ mIndexBuffer.position(0);
+
+ gl.glFrontFace(GL10.GL_CW);
+ gl.glShadeModel(GL10.GL_FLAT);
+ gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer);
+ gl.glColorPointer(4, GL10.GL_FIXED, 0, mColorBuffer);
+ gl.glDrawElements(GL10.GL_TRIANGLES, mIndexCount, GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
+ count++;
+ }
+
+ static public float toFloat(int x) {
+ return x/65536.0f;
+ }
+
+ private ArrayList<GLShape> mShapeList = new ArrayList<GLShape>();
+ private ArrayList<GLVertex> mVertexList = new ArrayList<GLVertex>();
+
+ private int mIndexCount = 0;
+
+ private IntBuffer mVertexBuffer;
+ private IntBuffer mColorBuffer;
+ private ShortBuffer mIndexBuffer;
+}
diff --git a/src/org/zeroxlab/kubench/Kubench.java b/src/org/zeroxlab/kubench/Kubench.java
new file mode 100644
index 0000000..252f616
--- /dev/null
+++ b/src/org/zeroxlab/kubench/Kubench.java
@@ -0,0 +1,388 @@
+/*
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.kubench;
+
+import org.zeroxlab.benchmark.Tester;
+
+import android.app.Activity;
+import android.graphics.PixelFormat;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.KeyEvent;
+
+import java.util.Random;
+
+public class Kubench extends Tester implements GLSurfaceView.GLSurfaceViewClient {
+
+ public final String TAG = "Kubench";
+ public final static String PACKAGE = "org.zeroxlab.kubench";
+
+ public String getTag() {
+ return TAG;
+ }
+
+ public static String getFullClassName() {
+ return PACKAGE + ".Kubench";
+ }
+
+ public int sleepBeforeStart() {
+ return 1000; //1 second
+ }
+
+ public int sleepBetweenRound() {
+ return 0;
+ }
+
+ public void oneRound() {
+ // do nothing;
+ }
+
+ private GLWorld makeGLWorld()
+ {
+ GLWorld world = new GLWorld();
+
+ int one = 0x10000;
+ int half = 0x08000;
+ GLColor red = new GLColor(one, 0, 0);
+ GLColor green = new GLColor(0, one, 0);
+ GLColor blue = new GLColor(0, 0, one);
+ GLColor yellow = new GLColor(one, one, 0);
+ GLColor orange = new GLColor(one, half, 0);
+ GLColor white = new GLColor(one, one, one);
+ GLColor black = new GLColor(0, 0, 0);
+
+ // coordinates for our cubes
+ float c0 = -1.0f;
+ float c1 = -0.38f;
+ float c2 = -0.32f;
+ float c3 = 0.32f;
+ float c4 = 0.38f;
+ float c5 = 1.0f;
+
+ // top back, left to right
+ mCubes[0] = new Cube(world, c0, c4, c0, c1, c5, c1);
+ mCubes[1] = new Cube(world, c2, c4, c0, c3, c5, c1);
+ mCubes[2] = new Cube(world, c4, c4, c0, c5, c5, c1);
+ // top middle, left to right
+ mCubes[3] = new Cube(world, c0, c4, c2, c1, c5, c3);
+ mCubes[4] = new Cube(world, c2, c4, c2, c3, c5, c3);
+ mCubes[5] = new Cube(world, c4, c4, c2, c5, c5, c3);
+ // top front, left to right
+ mCubes[6] = new Cube(world, c0, c4, c4, c1, c5, c5);
+ mCubes[7] = new Cube(world, c2, c4, c4, c3, c5, c5);
+ mCubes[8] = new Cube(world, c4, c4, c4, c5, c5, c5);
+ // middle back, left to right
+ mCubes[9] = new Cube(world, c0, c2, c0, c1, c3, c1);
+ mCubes[10] = new Cube(world, c2, c2, c0, c3, c3, c1);
+ mCubes[11] = new Cube(world, c4, c2, c0, c5, c3, c1);
+ // middle middle, left to right
+ mCubes[12] = new Cube(world, c0, c2, c2, c1, c3, c3);
+ mCubes[13] = null;
+ mCubes[14] = new Cube(world, c4, c2, c2, c5, c3, c3);
+ // middle front, left to right
+ mCubes[15] = new Cube(world, c0, c2, c4, c1, c3, c5);
+ mCubes[16] = new Cube(world, c2, c2, c4, c3, c3, c5);
+ mCubes[17] = new Cube(world, c4, c2, c4, c5, c3, c5);
+ // bottom back, left to right
+ mCubes[18] = new Cube(world, c0, c0, c0, c1, c1, c1);
+ mCubes[19] = new Cube(world, c2, c0, c0, c3, c1, c1);
+ mCubes[20] = new Cube(world, c4, c0, c0, c5, c1, c1);
+ // bottom middle, left to right
+ mCubes[21] = new Cube(world, c0, c0, c2, c1, c1, c3);
+ mCubes[22] = new Cube(world, c2, c0, c2, c3, c1, c3);
+ mCubes[23] = new Cube(world, c4, c0, c2, c5, c1, c3);
+ // bottom front, left to right
+ mCubes[24] = new Cube(world, c0, c0, c4, c1, c1, c5);
+ mCubes[25] = new Cube(world, c2, c0, c4, c3, c1, c5);
+ mCubes[26] = new Cube(world, c4, c0, c4, c5, c1, c5);
+
+ // paint the sides
+ int i, j;
+ // set all faces black by default
+ for (i = 0; i < 27; i++) {
+ Cube cube = mCubes[i];
+ if (cube != null) {
+ for (j = 0; j < 6; j++)
+ cube.setFaceColor(j, black);
+ }
+ }
+
+ // paint top
+ for (i = 0; i < 9; i++)
+ mCubes[i].setFaceColor(Cube.kTop, orange);
+ // paint bottom
+ for (i = 18; i < 27; i++)
+ mCubes[i].setFaceColor(Cube.kBottom, red);
+ // paint left
+ for (i = 0; i < 27; i += 3)
+ mCubes[i].setFaceColor(Cube.kLeft, yellow);
+ // paint right
+ for (i = 2; i < 27; i += 3)
+ mCubes[i].setFaceColor(Cube.kRight, white);
+ // paint back
+ for (i = 0; i < 27; i += 9)
+ for (j = 0; j < 3; j++)
+ mCubes[i + j].setFaceColor(Cube.kBack, blue);
+ // paint front
+ for (i = 6; i < 27; i += 9)
+ for (j = 0; j < 3; j++)
+ mCubes[i + j].setFaceColor(Cube.kFront, green);
+
+ for (i = 0; i < 27; i++)
+ if (mCubes[i] != null)
+ world.addShape(mCubes[i]);
+
+ // initialize our permutation to solved position
+ mPermutation = new int[27];
+ for (i = 0; i < mPermutation.length; i++)
+ mPermutation[i] = i;
+
+ createLayers();
+ updateLayers();
+
+ world.generate();
+
+ return world;
+ }
+
+ private void createLayers() {
+ mLayers[kUp] = new Layer(Layer.kAxisY);
+ mLayers[kDown] = new Layer(Layer.kAxisY);
+ mLayers[kLeft] = new Layer(Layer.kAxisX);
+ mLayers[kRight] = new Layer(Layer.kAxisX);
+ mLayers[kFront] = new Layer(Layer.kAxisZ);
+ mLayers[kBack] = new Layer(Layer.kAxisZ);
+ mLayers[kMiddle] = new Layer(Layer.kAxisX);
+ mLayers[kEquator] = new Layer(Layer.kAxisY);
+ mLayers[kSide] = new Layer(Layer.kAxisZ);
+ }
+
+ private void updateLayers() {
+ Layer layer;
+ GLShape[] shapes;
+ int i, j, k;
+
+ // up layer
+ layer = mLayers[kUp];
+ shapes = layer.mShapes;
+ for (i = 0; i < 9; i++)
+ shapes[i] = mCubes[mPermutation[i]];
+
+ // down layer
+ layer = mLayers[kDown];
+ shapes = layer.mShapes;
+ for (i = 18, k = 0; i < 27; i++)
+ shapes[k++] = mCubes[mPermutation[i]];
+
+ // left layer
+ layer = mLayers[kLeft];
+ shapes = layer.mShapes;
+ for (i = 0, k = 0; i < 27; i += 9)
+ for (j = 0; j < 9; j += 3)
+ shapes[k++] = mCubes[mPermutation[i + j]];
+
+ // right layer
+ layer = mLayers[kRight];
+ shapes = layer.mShapes;
+ for (i = 2, k = 0; i < 27; i += 9)
+ for (j = 0; j < 9; j += 3)
+ shapes[k++] = mCubes[mPermutation[i + j]];
+
+ // front layer
+ layer = mLayers[kFront];
+ shapes = layer.mShapes;
+ for (i = 6, k = 0; i < 27; i += 9)
+ for (j = 0; j < 3; j++)
+ shapes[k++] = mCubes[mPermutation[i + j]];
+
+ // back layer
+ layer = mLayers[kBack];
+ shapes = layer.mShapes;
+ for (i = 0, k = 0; i < 27; i += 9)
+ for (j = 0; j < 3; j++)
+ shapes[k++] = mCubes[mPermutation[i + j]];
+
+ // middle layer
+ layer = mLayers[kMiddle];
+ shapes = layer.mShapes;
+ for (i = 1, k = 0; i < 27; i += 9)
+ for (j = 0; j < 9; j += 3)
+ shapes[k++] = mCubes[mPermutation[i + j]];
+
+ // equator layer
+ layer = mLayers[kEquator];
+ shapes = layer.mShapes;
+ for (i = 9, k = 0; i < 18; i++)
+ shapes[k++] = mCubes[mPermutation[i]];
+
+ // side layer
+ layer = mLayers[kSide];
+ shapes = layer.mShapes;
+ for (i = 3, k = 0; i < 27; i += 9)
+ for (j = 0; j < 3; j++)
+ shapes[k++] = mCubes[mPermutation[i + j]];
+ }
+
+ @Override
+ public void onCreate(Bundle icicle)
+ {
+ super.onCreate(icicle);
+
+ // Make sure to create a TRANSLUCENT window. This is required
+ // for SurfaceView to work. Eventually this'll be done by
+ // the system automatically.
+ getWindow().setFormat(PixelFormat.TRANSLUCENT);
+
+ // We don't need a title either.
+ // requestWindowFeature(Window.FEATURE_NO_TITLE);
+
+ setTitle(TAG);
+
+ mView = new GLSurfaceView(getApplication(), makeGLWorld(), this);
+ setContentView(mView);
+ mView.setClient(this);
+ mPrevFramerate = 0.0f;
+ }
+
+ @Override
+ protected void onResume()
+ {
+ super.onResume();
+ }
+
+ @Override
+ protected void onStop()
+ {
+ super.onStop();
+ }
+
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ switch(keyCode) {
+ case KeyEvent.KEYCODE_BACK:
+ return super.onKeyDown(keyCode, event);
+ }
+ setTitle("Kubench: " + mView.getFramerate() + " fps");
+ return true;
+ }
+
+ public void animate() {
+ // change our angle of view
+ mView.setAngle(mView.getAngle() + 1.2f);
+
+ if (mCurrentLayer == null) {
+ int layerID = mRandom.nextInt(9);
+ mCurrentLayer = mLayers[layerID];
+ mCurrentLayerPermutation = mLayerPermutations[layerID];
+ mCurrentLayer.startAnimation();
+ boolean direction = mRandom.nextBoolean();
+ int count = mRandom.nextInt(3) + 1;
+
+ count = 1;
+ direction = false;
+ mCurrentAngle = 0;
+ if (direction) {
+ mAngleIncrement = (float)Math.PI / 50;
+ mEndAngle = mCurrentAngle + ((float)Math.PI * count) / 2f;
+ } else {
+ mAngleIncrement = -(float)Math.PI / 50;
+ mEndAngle = mCurrentAngle - ((float)Math.PI * count) / 2f;
+ }
+ }
+
+ mCurrentAngle += mAngleIncrement;
+
+ if ((mAngleIncrement > 0f && mCurrentAngle >= mEndAngle) ||
+ (mAngleIncrement < 0f && mCurrentAngle <= mEndAngle)) {
+ mCurrentLayer.setAngle(mEndAngle);
+ mCurrentLayer.endAnimation();
+ mCurrentLayer = null;
+
+ // adjust mPermutation based on the completed layer rotation
+ int[] newPermutation = new int[27];
+ for (int i = 0; i < 27; i++) {
+ newPermutation[i] = mPermutation[mCurrentLayerPermutation[i]];
+ // newPermutation[i] = mCurrentLayerPermutation[mPermutation[i]];
+ }
+ mPermutation = newPermutation;
+ updateLayers();
+
+ } else {
+ mCurrentLayer.setAngle(mCurrentAngle);
+ }
+
+ if (mPrevFramerate != mView.getFramerate()) {
+ mPrevFramerate = mView.getFramerate();
+ // setTitle(mPrevFramerate + "fps");
+ //Log.v("Kubench", mPrevFramerate + "fps");
+ }
+ }
+
+ GLSurfaceView mView;
+ Cube[] mCubes = new Cube[27];
+ // a Layer for each possible move
+ Layer[] mLayers = new Layer[9];
+ // permutations corresponding to a pi/2 rotation of each layer about its axis
+ static int[][] mLayerPermutations = {
+ // permutation for UP layer
+ { 2, 5, 8, 1, 4, 7, 0, 3, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 },
+ // permutation for DOWN layer
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 23, 26, 19, 22, 25, 18, 21, 24 },
+ // permutation for LEFT layer
+ { 6, 1, 2, 15, 4, 5, 24, 7, 8, 3, 10, 11, 12, 13, 14, 21, 16, 17, 0, 19, 20, 9, 22, 23, 18, 25, 26 },
+ // permutation for RIGHT layer
+ { 0, 1, 8, 3, 4, 17, 6, 7, 26, 9, 10, 5, 12, 13, 14, 15, 16, 23, 18, 19, 2, 21, 22, 11, 24, 25, 20 },
+ // permutation for FRONT layer
+ { 0, 1, 2, 3, 4, 5, 24, 15, 6, 9, 10, 11, 12, 13, 14, 25, 16, 7, 18, 19, 20, 21, 22, 23, 26, 17, 8 },
+ // permutation for BACK layer
+ { 18, 9, 0, 3, 4, 5, 6, 7, 8, 19, 10, 1, 12, 13, 14, 15, 16, 17, 20, 11, 2, 21, 22, 23, 24, 25, 26 },
+ // permutation for MIDDLE layer
+ { 0, 7, 2, 3, 16, 5, 6, 25, 8, 9, 4, 11, 12, 13, 14, 15, 22, 17, 18, 1, 20, 21, 10, 23, 24, 19, 26 },
+ // permutation for EQUATOR layer
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 14, 17, 10, 13, 16, 9, 12, 15, 18, 19, 20, 21, 22, 23, 24, 25, 26 },
+ // permutation for SIDE layer
+ { 0, 1, 2, 21, 12, 3, 6, 7, 8, 9, 10, 11, 22, 13, 4, 15, 16, 17, 18, 19, 20, 23, 14, 5, 24, 25, 26 }
+ };
+
+
+
+ // current permutation of starting position
+ int[] mPermutation;
+
+ // for random cube movements
+ Random mRandom = new Random(System.currentTimeMillis());
+ // currently turning layer
+ Layer mCurrentLayer = null;
+ // current and final angle for current Layer animation
+ float mCurrentAngle, mEndAngle;
+ // amount to increment angle
+ float mAngleIncrement;
+ int[] mCurrentLayerPermutation;
+
+ float mPrevFramerate;
+
+ // names for our 9 layers (based on notation from http://www.cubefreak.net/notation.html)
+ static final int kUp = 0;
+ static final int kDown = 1;
+ static final int kLeft = 2;
+ static final int kRight = 3;
+ static final int kFront = 4;
+ static final int kBack = 5;
+ static final int kMiddle = 6;
+ static final int kEquator = 7;
+ static final int kSide = 8;
+
+}
diff --git a/src/org/zeroxlab/kubench/Layer.java b/src/org/zeroxlab/kubench/Layer.java
new file mode 100644
index 0000000..5fc2145
--- /dev/null
+++ b/src/org/zeroxlab/kubench/Layer.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.kubench;
+
+public class Layer {
+
+ public Layer(int axis) {
+ // start with identity matrix for transformation
+ mAxis = axis;
+ mTransform.setIdentity();
+ }
+
+ public void startAnimation() {
+ for (int i = 0; i < mShapes.length; i++) {
+ GLShape shape = mShapes[i];
+ if (shape != null) {
+ shape.startAnimation();
+ }
+ }
+ }
+
+ public void endAnimation() {
+ for (int i = 0; i < mShapes.length; i++) {
+ GLShape shape = mShapes[i];
+ if (shape != null) {
+ shape.endAnimation();
+ }
+ }
+ }
+
+ public void setAngle(float angle) {
+ // normalize the angle
+ float twopi = (float)Math.PI *2f;
+ while (angle >= twopi) angle -= twopi;
+ while (angle < 0f) angle += twopi;
+// mAngle = angle;
+
+ float sin = (float)Math.sin(angle);
+ float cos = (float)Math.cos(angle);
+
+ float[][] m = mTransform.m;
+ switch (mAxis) {
+ case kAxisX:
+ m[1][1] = cos;
+ m[1][2] = sin;
+ m[2][1] = -sin;
+ m[2][2] = cos;
+ m[0][0] = 1f;
+ m[0][1] = m[0][2] = m[1][0] = m[2][0] = 0f;
+ break;
+ case kAxisY:
+ m[0][0] = cos;
+ m[0][2] = sin;
+ m[2][0] = -sin;
+ m[2][2] = cos;
+ m[1][1] = 1f;
+ m[0][1] = m[1][0] = m[1][2] = m[2][1] = 0f;
+ break;
+ case kAxisZ:
+ m[0][0] = cos;
+ m[0][1] = sin;
+ m[1][0] = -sin;
+ m[1][1] = cos;
+ m[2][2] = 1f;
+ m[2][0] = m[2][1] = m[0][2] = m[1][2] = 0f;
+ break;
+ }
+
+ for (int i = 0; i < mShapes.length; i++) {
+ GLShape shape = mShapes[i];
+ if (shape != null) {
+ shape.animateTransform(mTransform);
+ }
+ }
+ }
+
+ public GLShape[] mShapes = new GLShape[9];
+ M4 mTransform = new M4();
+// float mAngle;
+
+ // which axis do we rotate around?
+ // 0 for X, 1 for Y, 2 for Z
+ int mAxis;
+ static public final int kAxisX = 0;
+ static public final int kAxisY = 1;
+ static public final int kAxisZ = 2;
+}
diff --git a/src/org/zeroxlab/kubench/M4.java b/src/org/zeroxlab/kubench/M4.java
new file mode 100644
index 0000000..66a0d20
--- /dev/null
+++ b/src/org/zeroxlab/kubench/M4.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zeroxlab.kubench;
+
+/**
+ *
+ * A 4x4 float matrix
+ *
+ */
+public class M4 {
+ public float[][] m = new float[4][4];
+
+ public M4() {
+ }
+
+ public M4(M4 other) {
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ m[i][j] = other.m[i][j];
+ }
+ }
+ }
+
+ public void multiply(GLVertex src, GLVertex dest) {
+ dest.x = src.x * m[0][0] + src.y * m[1][0] + src.z * m[2][0] + m[3][0];
+ dest.y = src.x * m[0][1] + src.y * m[1][1] + src.z * m[2][1] + m[3][1];
+ dest.z = src.x * m[0][2] + src.y * m[1][2] + src.z * m[2][2] + m[3][2];
+ }
+
+ public M4 multiply(M4 other) {
+ M4 result = new M4();
+ float[][] m1 = m;
+ float[][] m2 = other.m;
+
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ result.m[i][j] = m1[i][0]*m2[0][j] + m1[i][1]*m2[1][j] + m1[i][2]*m2[2][j] + m1[i][3]*m2[3][j];
+ }
+ }
+
+ return result;
+ }
+
+ public void setIdentity() {
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ m[i][j] = (i == j ? 1f : 0f);
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder("[ ");
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ builder.append(m[i][j]);
+ builder.append(" ");
+ }
+ if (i < 2)
+ builder.append("\n ");
+ }
+ builder.append(" ]");
+ return builder.toString();
+ }
+}