diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 242: Android: Display the benchmark results log in the GUI.

Message ID 20120801095911.15805.96869.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org Aug. 1, 2012, 9:59 a.m. UTC
Merge authors:
  Alexandros Frantzis (afrantzis)
Related merge proposals:
  https://code.launchpad.net/~linaro-graphics-wg/glmark2/android-gui-log/+merge/117448
  proposed by: Alexandros Frantzis (afrantzis)
  review: Approve - Jesse Barker (jesse-barker)
------------------------------------------------------------
revno: 242 [merge]
committer: Alexandros Frantzis <alexandros.frantzis@linaro.org>
branch nick: trunk
timestamp: Wed 2012-08-01 12:57:46 +0300
message:
  Android: Display the benchmark results log in the GUI.
added:
  android/res/drawable/menu_results.png
  android/res/layout/activity_results.xml
  android/src/org/linaro/glmark2/ResultsActivity.java
modified:
  android/AndroidManifest.xml
  android/res/menu/main_options_menu.xml
  android/res/values/strings.xml
  android/res/xml/preferences.xml
  android/src/org/linaro/glmark2/Glmark2Native.java
  android/src/org/linaro/glmark2/Glmark2SurfaceView.java
  android/src/org/linaro/glmark2/MainActivity.java
  src/android.cpp
  src/libmatrix/log.cc
  src/libmatrix/log.h
  wscript


--
lp:glmark2
https://code.launchpad.net/~glmark2-dev/glmark2/trunk

You are subscribed to branch lp:glmark2.
To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'android/AndroidManifest.xml'
--- android/AndroidManifest.xml	2012-07-26 11:29:49 +0000
+++ android/AndroidManifest.xml	2012-07-31 10:28:13 +0000
@@ -19,7 +19,6 @@ 
         </activity>
         <activity android:label="@string/title_activity_glmark2"
                   android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
-                  android:launchMode="singleTask"
                   android:screenOrientation="nosensor"
                   android:process=":glmark2"
                   android:name="org.linaro.glmark2.Glmark2Activity">
@@ -40,6 +39,12 @@ 
                 <action android:name="android.intent.action.MAIN" />
             </intent-filter>
         </activity>
+        <activity android:label="@string/title_activity_results"
+                  android:name="org.linaro.glmark2.ResultsActivity">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+            </intent-filter>
+        </activity>
     </application>
     <uses-permission android:name="android.permission.WAKE_LOCK" />
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

=== added file 'android/res/drawable/menu_results.png'
Binary files android/res/drawable/menu_results.png	1970-01-01 00:00:00 +0000 and android/res/drawable/menu_results.png	2012-07-30 13:14:25 +0000 differ
=== added file 'android/res/layout/activity_results.xml'
--- android/res/layout/activity_results.xml	1970-01-01 00:00:00 +0000
+++ android/res/layout/activity_results.xml	2012-07-30 13:14:25 +0000
@@ -0,0 +1,15 @@ 
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content">
+
+    <HorizontalScrollView android:layout_width="match_parent"
+                          android:layout_height="wrap_content">
+
+        <TextView android:id="@+id/results"
+                  android:layout_width="match_parent"
+                  android:layout_height="wrap_content"
+                  android:typeface="monospace" />
+
+    </HorizontalScrollView>
+
+</ScrollView>

=== modified file 'android/res/menu/main_options_menu.xml'
--- android/res/menu/main_options_menu.xml	2012-07-26 09:18:27 +0000
+++ android/res/menu/main_options_menu.xml	2012-07-30 13:14:25 +0000
@@ -16,6 +16,10 @@ 
           android:title="@string/settingsMainOptionsText"
           android:icon="@drawable/menu_settings" />
 
+    <item android:id="@+id/results"
+          android:title="@string/resultsMainOptionsText"
+          android:icon="@drawable/menu_results" />
+
     <item android:id="@+id/about"
           android:title="@string/aboutMainOptionsText"
           android:icon="@drawable/menu_about" />

=== modified file 'android/res/values/strings.xml'
--- android/res/values/strings.xml	2012-07-26 11:29:49 +0000
+++ android/res/values/strings.xml	2012-07-31 10:35:18 +0000
@@ -5,6 +5,7 @@ 
     <string name="title_activity_editor">GLMark2 Benchmark Editor</string>
     <string name="title_activity_preferences">GLMark2 Settings</string>
     <string name="title_activity_about">About GLMark2</string>
+    <string name="title_activity_results">GLMark2 Results</string>
     <string name="title_activity_glmark2">GLMark2</string>
     <string name="runButtonText">Run</string>
     <string name="saveButtonText">Save</string>
@@ -13,12 +14,17 @@ 
     <string name="loadMainOptionsText">Load list</string>
     <string name="deleteMainOptionsText">Delete list</string>
     <string name="settingsMainOptionsText">Settings</string>
+    <string name="resultsMainOptionsText">Last results</string>
     <string name="aboutMainOptionsText">About</string>
 
     <string name="externalSaveDialogText">Save to external storage</string>
 
     <string name="runForeverPreferenceTitle">Run forever</string>
     <string name="runForeverPreferenceSummary">Run indefinitely, looping from the last benchmark back to the first</string>
+    <string name="logDebugPreferenceTitle">Log debug messages</string>
+    <string name="logDebugPreferenceSummary">Display debug messages in the log</string>
+    <string name="showResultsPreferenceTitle">Show benchmark results</string>
+    <string name="showResultsPreferenceSummary">Show results after running benchmarks</string>
 
     <string name="about_name_version_format">GLMark2 %1$s</string>
     <string name="about_description">OpenGL (ES) 2.0 benchmark suite</string>

=== modified file 'android/res/xml/preferences.xml'
--- android/res/xml/preferences.xml	2012-07-26 09:18:27 +0000
+++ android/res/xml/preferences.xml	2012-07-31 10:35:18 +0000
@@ -4,4 +4,12 @@ 
                         android:title="@string/runForeverPreferenceTitle"
                         android:summary="@string/runForeverPreferenceSummary"
                         android:defaultValue="false" />
+    <CheckBoxPreference android:key="log_debug"
+                        android:title="@string/logDebugPreferenceTitle"
+                        android:summary="@string/logDebugPreferenceSummary"
+                        android:defaultValue="false" />
+    <CheckBoxPreference android:key="show_results"
+                        android:title="@string/showResultsPreferenceTitle"
+                        android:summary="@string/showResultsPreferenceSummary"
+                        android:defaultValue="true" />
 </PreferenceScreen>

=== modified file 'android/src/org/linaro/glmark2/Glmark2Native.java'
--- android/src/org/linaro/glmark2/Glmark2Native.java	2012-07-04 14:38:56 +0000
+++ android/src/org/linaro/glmark2/Glmark2Native.java	2012-07-30 12:28:16 +0000
@@ -24,7 +24,8 @@ 
 import android.content.res.AssetManager;
 
 class Glmark2Native {
-    public static native void init(AssetManager assetManager, String args);
+    public static native void init(AssetManager assetManager, String args,
+                                   String logFilePath);
     public static native void resize(int w, int h);
     public static native boolean render();
     public static native void done();

=== modified file 'android/src/org/linaro/glmark2/Glmark2SurfaceView.java'
--- android/src/org/linaro/glmark2/Glmark2SurfaceView.java	2012-07-04 14:27:42 +0000
+++ android/src/org/linaro/glmark2/Glmark2SurfaceView.java	2012-07-30 12:28:16 +0000
@@ -1,5 +1,7 @@ 
 package org.linaro.glmark2;
 
+import java.io.File;
+
 import android.graphics.PixelFormat;
 import android.opengl.GLSurfaceView;
 import android.app.Activity;
@@ -203,7 +205,8 @@ 
 
     public void onSurfaceCreated(GL10 gl, EGLConfig config) {
         String args = mView.getActivity().getIntent().getStringExtra("args");
-        Glmark2Native.init(mView.getActivity().getAssets(), args);
+        File f = new File(mView.getActivity().getFilesDir(), "last_run.log");
+        Glmark2Native.init(mView.getActivity().getAssets(), args, f.getAbsolutePath());
     }
 
     private Glmark2SurfaceView mView;

=== modified file 'android/src/org/linaro/glmark2/MainActivity.java'
--- android/src/org/linaro/glmark2/MainActivity.java	2012-07-26 12:13:44 +0000
+++ android/src/org/linaro/glmark2/MainActivity.java	2012-07-31 10:35:18 +0000
@@ -62,6 +62,9 @@ 
     public static final int DIALOG_LOAD_LIST_ID = 3;
     public static final int DIALOG_DELETE_LIST_ID = 4;
 
+    public static final int ACTIVITY_GLMARK2_REQUEST_CODE = 1;
+    public static final int ACTIVITY_EDITOR_REQUEST_CODE = 2;
+
     /**
      * The supported benchmark item actions.
      */
@@ -266,6 +269,10 @@ 
                 startActivity(new Intent(MainActivity.this, MainPreferencesActivity.class));
                 ret = true;
                 break;
+            case R.id.results:
+                startActivity(new Intent(MainActivity.this, ResultsActivity.class));
+                ret = true;
+                break;
             case R.id.about:
                 startActivity(new Intent(MainActivity.this, AboutActivity.class));
                 ret = true;
@@ -280,7 +287,14 @@ 
 
     @Override
     public void onActivityResult(int requestCode, int resultCode, Intent data) {
-        if (resultCode == RESULT_OK) {
+        if (requestCode == ACTIVITY_GLMARK2_REQUEST_CODE)
+        {
+            startActivity(new Intent(this, ResultsActivity.class));
+            return;
+        }
+        else if (requestCode == ACTIVITY_EDITOR_REQUEST_CODE &&
+                 resultCode == RESULT_OK)
+        {
             String benchmarkText = data.getStringExtra("benchmark-text");
             int benchmarkPos = data.getIntExtra("benchmark-pos", 0);
             doBenchmarkItemAction(benchmarkPos, BenchmarkItemAction.EDIT, benchmarkText);
@@ -312,9 +326,15 @@ 
                     args += "-b " + benchmarks.get(i) + " ";
                 if (prefs.getBoolean("run_forever", false))
                     args += "--run-forever ";
+                if (prefs.getBoolean("log_debug", false))
+                    args += "--debug ";
                 if (!args.isEmpty())
                     intent.putExtra("args", args);
-                startActivity(intent);
+                
+                if (prefs.getBoolean("show_results", true))
+                    startActivityForResult(intent, ACTIVITY_GLMARK2_REQUEST_CODE);
+                else
+                    startActivity(intent);
             }
         });
 
@@ -332,7 +352,7 @@ 
                 intent.putExtra("benchmark-text", t);
                 intent.putExtra("benchmark-pos", position);
                 intent.putExtra("scene-info", sceneInfoList);
-                startActivityForResult(intent, 1);
+                startActivityForResult(intent, ACTIVITY_EDITOR_REQUEST_CODE);
             }
         });
 

=== added file 'android/src/org/linaro/glmark2/ResultsActivity.java'
--- android/src/org/linaro/glmark2/ResultsActivity.java	1970-01-01 00:00:00 +0000
+++ android/src/org/linaro/glmark2/ResultsActivity.java	2012-07-30 13:14:25 +0000
@@ -0,0 +1,58 @@ 
+/*
+ * Copyright © 2012 Linaro Limited
+ *
+ * This file is part of the glmark2 OpenGL (ES) 2.0 benchmark.
+ *
+ * glmark2 is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * glmark2 is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * glmark2.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *  Alexandros Frantzis
+ */
+package org.linaro.glmark2;
+
+import java.io.*;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.widget.TextView;
+
+public class ResultsActivity extends Activity {
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        setContentView(R.layout.activity_results);
+        TextView tv = (TextView) findViewById(R.id.results);
+
+        File f = new File(getFilesDir(), "last_run.log");
+
+        try {
+            /* Read log from file */
+            BufferedReader reader = new BufferedReader(new FileReader(f));
+            String line = null;
+            StringBuffer sb = new StringBuffer();
+
+            while ((line = reader.readLine()) != null) {
+                sb.append(line);
+                sb.append('\n');
+            }
+
+            reader.close();
+            tv.setText(sb.toString());
+        }
+        catch (Exception ex) {
+        }
+    }
+}
+

=== modified file 'src/android.cpp'
--- src/android.cpp	2012-07-18 09:45:59 +0000
+++ src/android.cpp	2012-07-30 12:28:16 +0000
@@ -37,6 +37,7 @@ 
 static Canvas *g_canvas;
 static MainLoop *g_loop;
 static BenchmarkCollection *g_benchmark_collection;
+static std::ostream *g_log_extra;
 
 class MainLoopAndroid : public MainLoop
 {
@@ -258,7 +259,8 @@ 
 void
 Java_org_linaro_glmark2_native_init(JNIEnv* env, jclass clazz,
                                     jobject asset_manager,
-                                    jstring args)
+                                    jstring args,
+                                    jstring log_file)
 {
     static_cast<void>(clazz);
     static const std::string arguments_file("/data/glmark2/args");
@@ -282,10 +284,17 @@ 
     Options::parse_args(argc, argv);
     release_args(argc, argv);
 
+    /* Get the log file path and open the log file */
+    const char *log_file_c_str = env->GetStringUTFChars(log_file, 0);
+    if (log_file_c_str) {
+        g_log_extra = new std::ofstream(log_file_c_str, std::ios::binary);
+        env->ReleaseStringUTFChars(log_file, log_file_c_str);
+    }
+
     /* Force reuse of EGL/GL context */
     Options::reuse_context = true;
 
-    Log::init("glmark2", Options::show_debug);
+    Log::init("glmark2", Options::show_debug, g_log_extra);
     Util::android_set_asset_manager(AAssetManager_fromJava(env, asset_manager));
 
     g_canvas = new CanvasAndroid(100, 100);
@@ -340,6 +349,7 @@ 
     delete g_loop;
     delete g_benchmark_collection;
     delete g_canvas;
+    delete g_log_extra;
 }
 
 jboolean
@@ -409,7 +419,7 @@ 
 static JNINativeMethod glmark2_native_methods[] = {
     {
         "init",
-        "(Landroid/content/res/AssetManager;Ljava/lang/String;)V",
+        "(Landroid/content/res/AssetManager;Ljava/lang/String;Ljava/lang/String;)V",
         reinterpret_cast<void*>(Java_org_linaro_glmark2_native_init)
     },
     {

=== modified file 'src/libmatrix/log.cc'
--- src/libmatrix/log.cc	2012-01-27 22:01:59 +0000
+++ src/libmatrix/log.cc	2012-07-30 09:27:14 +0000
@@ -10,6 +10,7 @@ 
 //     Alexandros Frantzis <alexandros.frantzis@linaro.org>
 //     Jesse Barker <jesse.barker@linaro.org>
 //
+#include <unistd.h>
 #include <cstdio>
 #include <cstdarg>
 #include <string>
@@ -26,8 +27,7 @@ 
 const string Log::continuation_prefix("\x10");
 string Log::appname_;
 bool Log::do_debug_(false);
-
-#ifndef ANDROID
+std::ostream* Log::extra_out_(0);
 
 static const string terminal_color_normal("\033[0m");
 static const string terminal_color_red("\033[1;31m");
@@ -96,17 +96,26 @@ 
     delete[] buf;
 }
 
+
 void
 Log::info(const char *fmt, ...)
 {
     static const string infoprefix("Info");
+    const string& prefix(do_debug_ ? infoprefix : empty);
+    va_list ap;
+    va_start(ap, fmt);
+
+#ifndef ANDROID
     static const string& infocolor(isatty(fileno(stdout)) ? terminal_color_cyan : empty);
-    va_list ap;
-    va_start(ap, fmt);
-    if (do_debug_)
-        print_prefixed_message(std::cout, infocolor, infoprefix, fmt, ap);
-    else
-        print_prefixed_message(std::cout, empty, empty, fmt, ap);
+    const string& color(do_debug_ ? infocolor : empty);
+    print_prefixed_message(std::cout, color, prefix, fmt, ap);
+#else
+    __android_log_vprint(ANDROID_LOG_INFO, appname_.c_str(), fmt, ap);
+#endif
+
+    if (extra_out_)
+        print_prefixed_message(*extra_out_, empty, prefix, fmt, ap);
+
     va_end(ap);
 }
 
@@ -114,12 +123,21 @@ 
 Log::debug(const char *fmt, ...)
 {
     static const string dbgprefix("Debug");
+    if (!do_debug_)
+        return;
+    va_list ap;
+    va_start(ap, fmt);
+
+#ifndef ANDROID
     static const string& dbgcolor(isatty(fileno(stdout)) ? terminal_color_yellow : empty);
-    if (!do_debug_)
-        return;
-    va_list ap;
-    va_start(ap, fmt);
     print_prefixed_message(std::cout, dbgcolor, dbgprefix, fmt, ap);
+#else
+    __android_log_vprint(ANDROID_LOG_DEBUG, appname_.c_str(), fmt, ap);
+#endif
+
+    if (extra_out_)
+        print_prefixed_message(*extra_out_, empty, dbgprefix, fmt, ap);
+
     va_end(ap);
 }
 
@@ -127,52 +145,29 @@ 
 Log::error(const char *fmt, ...)
 {
     static const string errprefix("Error");
+    va_list ap;
+    va_start(ap, fmt);
+
+#ifndef ANDROID
     static const string& errcolor(isatty(fileno(stderr)) ? terminal_color_red : empty);
-    va_list ap;
-    va_start(ap, fmt);
     print_prefixed_message(std::cerr, errcolor, errprefix, fmt, ap);
+#else
+    __android_log_vprint(ANDROID_LOG_ERROR, appname_.c_str(), fmt, ap);
+#endif
+
+    if (extra_out_)
+        print_prefixed_message(*extra_out_, empty, errprefix, fmt, ap);
+
     va_end(ap);
 }
 
 void
 Log::flush()
 {
+#ifndef ANDROID
     std::cout.flush();
     std::cerr.flush();
-}
-#else
-void
-Log::info(const char *fmt, ...)
-{
-    va_list ap;
-    va_start(ap, fmt);
-    __android_log_vprint(ANDROID_LOG_INFO, appname_.c_str(), fmt, ap);
-    va_end(ap);
-}
-
-void
-Log::debug(const char *fmt, ...)
-{
-    if (!do_debug_)
-        return;
-    va_list ap;
-    va_start(ap, fmt);
-    __android_log_vprint(ANDROID_LOG_DEBUG, appname_.c_str(), fmt, ap);
-    va_end(ap);
-}
-
-void
-Log::error(const char *fmt, ...)
-{
-    va_list ap;
-    va_start(ap, fmt);
-    __android_log_vprint(ANDROID_LOG_ERROR, appname_.c_str(), fmt, ap);
-    va_end(ap);
-}
-
-void
-Log::flush()
-{
-}
-
 #endif
+    if (extra_out_)
+        extra_out_->flush();
+}

=== modified file 'src/libmatrix/log.h'
--- src/libmatrix/log.h	2012-01-27 22:01:59 +0000
+++ src/libmatrix/log.h	2012-07-30 09:27:14 +0000
@@ -14,14 +14,17 @@ 
 #define LOG_H_
 
 #include <string>
+#include <iostream>
 
 class Log
 {
 public:
-    static void init(const std::string& appname, bool do_debug = false)
+    static void init(const std::string& appname, bool do_debug = false,
+                     std::ostream *extra_out = 0)
     {
         appname_ = appname;
         do_debug_ = do_debug;
+        extra_out_ = extra_out;
     }
     // Emit an informational message
     static void info(const char *fmt, ...);
@@ -41,6 +44,8 @@ 
     static std::string appname_;
     // Indicates whether debug level messages should generate any output
     static bool do_debug_;
+    // Extra stream to output log messages to
+    static std::ostream *extra_out_;
 };
 
 #endif /* LOG_H_ */

=== modified file 'wscript'
--- wscript	2012-07-27 09:11:50 +0000
+++ wscript	2012-07-30 09:27:14 +0000
@@ -36,7 +36,7 @@ 
     ctx.check_tool('compiler_cxx')
 
     # Check required headers
-    req_headers = ['stdlib.h', 'string.h', 'stdint.h', 'stdio.h', 'jpeglib.h']
+    req_headers = ['stdlib.h', 'string.h', 'unistd.h', 'stdint.h', 'stdio.h', 'jpeglib.h']
     for header in req_headers:
         ctx.check_cxx(header_name = header, auto_add_header_name = True, mandatory = True)