Commit f9cee5c7 authored by Dave Griffiths's avatar Dave Griffiths
Browse files

massive speedup by moving id tracking to c++, fixed memory corruption crash

parent 4386da26
......@@ -145,9 +145,20 @@
(cons (car sorted-lst)
(insert elt fn (cdr sorted-lst))))))
(define (choose l)
(list-ref l (abs (random (- (length l) 1)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; time
(define (time->seconds t)
(+ (car t) (/ (cadr t) 1000000)))
(define start-time (time->seconds (time)))
(define (time-now)
(- (time->seconds (time)) start-time))
;; just for graph so don't have to be accurate!!!
(define (date->day d)
(+ (* (list-ref d 2) 360)
......@@ -495,19 +506,93 @@
; (set! current-id (+ current-id 1))
; (get-id name)))))
(define (get-id name)
(cadr (sorted-find id-map name)))
;(define (get-id name)
; (cadr (sorted-find id-map name)))
(define (make-id name)
(let ((sf (sorted-find id-map name)))
(if (not sf)
(let ((id current-id))
(set! id-map (sorted-add id-map (list name id)))
(set! current-id (+ current-id 1))
id)
(cadr sf))))
;(define (make-id name)
; (prof-start "make-id")
; (prof-start "make-id sorted find")
; (let ((sf (sorted-find id-map name)))
; (prof-end "make-id sorted find")
; (let ((r (if (not sf)
; (let ((id current-id))
; (prof-start "make-id sorted add")
; (set! id-map (sorted-add id-map (list name id)))
; (prof-end "make-id sorted add")
; (set! current-id (+ current-id 1))
; id)
; (cadr sf))))
; (prof-end "make-id")
; r)))
(define (get-id name)
(id-map-get name))
(define (make-id name)
(let ((id (id-map-get name)))
(cond
((zero? id)
; (prof-start "make-id")
(id-map-add name current-id)
(set! current-id (+ current-id 1))
; (prof-end "make-id")
(- current-id 1))
(else id))))
(define prof-map '())
(define (new-prof-item id)
(list id (time-now) 0 0))
(define (prof-item-id p) (list-ref p 0))
(define (prof-item-time p) (list-ref p 1))
(define (prof-item-accum p) (list-ref p 2))
(define (prof-item-calls p) (list-ref p 3))
(define (prof-item-restart p)
(list
(prof-item-id p)
(time-now)
(prof-item-accum p)
(prof-item-calls p)))
(define (prof-item-end p)
(list
(prof-item-id p)
0
(+ (prof-item-accum p)
(- (time-now) (prof-item-time p)))
(+ (prof-item-calls p) 1)))
(define (prof-start id)
(let ((dd (sorted-find prof-map id)))
(if dd
(set! prof-map
(sorted-add
prof-map (prof-item-restart dd)))
(set! prof-map
(sorted-add
prof-map (new-prof-item id))))))
(define (prof-end id)
(let ((d (sorted-find prof-map id)))
(set! prof-map
(sorted-add
prof-map
(prof-item-end d)))))
(define (prof-print)
(let ((tot (foldl
(lambda (d r)
(+ (prof-item-accum d) r))
0 prof-map)))
(for-each
(lambda (d)
(msg (prof-item-id d)
(prof-item-calls d)
(prof-item-accum d)
(* (/ (prof-item-accum d) tot) 100) "%"))
prof-map)))
(define wrap (layout 'wrap-content 'wrap-content 1 'left))
(define fillwrap (layout 'fill-parent 'wrap-content 1 'left))
(define wrapfill (layout 'wrap-content 'fill-parent 1 'left))
......@@ -663,13 +748,19 @@
;; called by java
(define (activity-callback type activity-name args)
(let ((activity (activity-list-find activities activity-name)))
(top-callback type activity-name activity args)))
(prof-start "activity-callback")
(let ((r (let ((activity (activity-list-find activities activity-name)))
(top-callback type activity-name activity args))))
(prof-end "activity-callback")
r))
;; called by java
(define (fragment-callback type fragment-name args)
(let ((fragment (activity-list-find fragments fragment-name)))
(top-callback type fragment-name fragment args)))
(prof-start "activity-callback")
(let ((r (let ((fragment (activity-list-find fragments fragment-name)))
(top-callback type fragment-name fragment args))))
(prof-end "activity-callback")
r))
(define (top-callback type activity-name activity args)
;;(display "activity-callback ")(display type)(display " ")(display args)(newline)
......@@ -703,6 +794,7 @@
(activity-list-find fragments name))))
(define (widget-callback activity-name widget-id args)
(prof-start "widget-callback")
(let ((cb (find-callback widget-id)))
(if (not cb)
(msg "no widget" widget-id "found!")
......@@ -724,4 +816,5 @@
(msg "no callbacks for type" (callback-type cb))))))
;;(update-callbacks! events)
(update-dialogs! events)
(send (scheme->json events))))))
(send (scheme->json events))
(prof-end "widget-callback")))))
......@@ -284,7 +284,7 @@
(lambda (item)
(let ((item-name (fast-get-name item)))
(list (make-id (string-append name item-name))
item
item
item-name)))
items)))
(update-widget
......@@ -453,7 +453,7 @@
(mtext "text" "Type of care")
(horiz
(spinner (make-id "pf-pupcare-type") (list "Carry" "Lead" "Sniff" "Play" "Ano-genital sniff") fillwrap (lambda (v) '()))
(mbutton "pf-scan-done" "Done" (lambda () (list (replace-fragment (get-id "pf-bot") "events")))))))
(mbutton "pf-pupcare-done" "Done" (lambda () (list (replace-fragment (get-id "pf-bot") "events")))))))
(lambda (fragment arg)
(activity-layout fragment))
......@@ -1273,7 +1273,9 @@
(lambda ()
(cons (toast "Downloading data...") (suck-new db "sync")))))
(text-view (make-id "sync-console") "..." 15 (layout 300 'wrap-content 1 'left))
(mbutton "main-send" "Done" (lambda () (list (finish-activity 2)))))
(horiz
(mbutton2 "sync-prof" "Profile" (lambda () (prof-print) '()))
(mbutton2 "sync-send" "Done" (lambda () (list (finish-activity 2))))))
(lambda (activity arg)
(activity-layout activity))
......
......@@ -98,7 +98,6 @@
(update-entity db table e (list (ktv "param3" "real" 3.3)))
(let ((e (get-entity db table e)))
(msg e)
(asserteq "update-entity 3" (ktv-get e "param1") "wotzit")
(asserteq "update-entity 4" (ktv-get e "param2") 1)
(assert "update-entity 5" (feq (ktv-get e "param3") 3.3)))
......@@ -133,5 +132,58 @@
(asserteq "cleaning" (length (dirty-entities db table)) 0)
(msg (db-status db))
(msg "testing some interface building...")
(setup db "sync")
(define i (insert-entity
db "sync" "pack" "user"
(list (ktv "name" "varchar" "pack one"))))
(define p (get-entity db "sync" i))
(msg (ktv-get p "unique_id"))
(define (make-mongoose name)
(insert-entity
db "sync" "mongoose" (ktv-get p "unique_id")
(list
(ktv "name" "varchar" name)
(ktv "gender" "varchar" "Female")
(ktv "litter-code" "varchar" "34")
(ktv "chip-code" "varchar" "34")
(ktv "pack-id" "varchar" "unique_id")
)))
(make-mongoose "bob")
(make-mongoose "fred")
(make-mongoose "arnold")
(make-mongoose "lucy")
(make-mongoose "doris")
(make-mongoose "kylie")
(make-mongoose "jenny")
(for-each
(lambda (fragment)
(msg "calling fragment" fragment)
(fragment-callback 'on-create fragment '("")))
(build-list
(lambda (i)
(choose (list
"pf-timer"
"pf-scan1"
"events"
"pf-timer"
"ev-pupfeed"
"ev-pupcare"
"ev-pupfind"
"ev-pupaggr"
"ev-grpint"
"ev-grpalarm"
"ev-grpmov")))
100))
......@@ -13,6 +13,7 @@ LOCAL_SRC_FILES := \
core/db_container.cpp \
sqlite/sqlite3.c \
scheme/scheme.cpp \
core/idmap.cpp \
app-android.c
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog
......
......@@ -18,6 +18,7 @@ env.Program( target = 'app',
'core/list.cpp',
'core/db.cpp',
'core/db_container.cpp',
'core/idmap.cpp',
'sqlite/sqlite3.c',
'scheme/scheme.cpp'
] )
......@@ -37,6 +37,11 @@ jstring Java_foam_mongoose_Scheme_nativeEval(JNIEnv* env, jobject thiz, jstring
scheme_load_string(sc,native_code);
fflush(log_file);
(*env)->ReleaseStringUTFChars(env, code, native_code);
if (starwisp_data!=NULL) return (*env)->NewStringUTF(env,starwisp_data);
if (starwisp_data!=NULL) {
jstring ret = (*env)->NewStringUTF(env,starwisp_data);
free(starwisp_data);
starwisp_data=NULL;
return ret;
}
return (*env)->NewStringUTF(env,"");
}
// Copyright (C) 2011 Dave Griffiths
//
// This program 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 2 of the License, or
// (at your option) any later version.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <stdlib.h>
#include <string.h>
#include "idmap.h"
idmap::idmap() {}
idmap::~idmap() {}
void idmap::add(char *name, int id)
{
idmap_node *nm = new idmap_node;
nm->m_name=strdup(name);
nm->m_id=id;
m_map.add_to_front(nm);
}
int idmap::get(char *name)
{
list::node *p=m_map.m_head;
while (p!=NULL)
{
idmap_node *mn = (idmap_node*)p;
if (!strcmp(name,mn->m_name))
return mn->m_id;
p=p->m_next;
}
return 0;
}
// Copyright (C) 2011 Dave Griffiths
//
// This program 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 2 of the License, or
// (at your option) any later version.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <stdlib.h>
#include "types.h"
#include "list.h"
#ifndef BB_IDMAP
#define BB_IDMAP
class idmap
{
public:
idmap();
~idmap();
void add(char *name, int id);
int get(char *name);
class idmap_node: public list::node
{
public:
virtual ~idmap_node()
{
free(m_name);
}
char *m_name;
int m_id;
};
private:
list m_map;
};
#endif
......@@ -198,6 +198,8 @@
_OP_DEF(opexe_6, "db-insert", 2, INF_ARG, TST_NONE, OP_INSERT_DB )
_OP_DEF(opexe_6, "db-status", 1, 1, TST_NONE, OP_STATUS_DB )
_OP_DEF(opexe_6, "time", 0, 0, TST_NONE, OP_TIME )
_OP_DEF(opexe_6, "id-map-add", 2, 2, TST_NONE, OP_ID_MAP_ADD )
_OP_DEF(opexe_6, "id-map-get", 1, 1, TST_NONE, OP_ID_MAP_GET )
#undef _OP_DEF
......@@ -31,10 +31,17 @@
#include <float.h>
#include <ctype.h>
#include <sys/time.h>
#ifdef ANDROID_NDK
#include <android/log.h>
#endif
char *starwisp_data = NULL;
#include "core/db_container.h"
db_container the_db_container;
#include "core/idmap.h"
idmap the_idmap;
#ifdef _EE
#define USE_STRLWR 0
......@@ -48,7 +55,6 @@ db_container the_db_container;
# endif
#endif
char *starwisp_data = NULL;
/* Used for documentation purposes, to signal functions in 'interface' */
#define INTERFACE
......@@ -4309,11 +4315,17 @@ static pointer opexe_6(scheme *sc, enum scheme_opcodes op) {
s_retbool(is_macro(car(sc->args)));
///////////// FLUXUS
case OP_ALOG:
#ifdef ANDROID_NDK
__android_log_print(ANDROID_LOG_INFO, "starwisp", string_value(car(sc->args)));
#endif
s_return(sc,sc->F);
case OP_SEND:
if (is_string(car(sc->args))) {
starwisp_data=string_value(car(sc->args));
if (starwisp_data!=NULL) {
__android_log_print(ANDROID_LOG_INFO, "starwisp", "deleting starwisp data: something is wrong!");
free(starwisp_data);
}
starwisp_data=strdup(string_value(car(sc->args)));
}
s_return(sc,sc->F);
case OP_OPEN_DB: {
......@@ -4362,6 +4374,17 @@ static pointer opexe_6(scheme *sc, enum scheme_opcodes op) {
s_return(sc,cons(sc,mk_integer(sc,t.tv_sec),
cons(sc,mk_integer(sc,t.tv_usec),sc->NIL)));
}
case OP_ID_MAP_ADD: {
the_idmap.add(
string_value(car(sc->args)),
ivalue(cadr(sc->args)));
s_return(sc,sc->F);
}
case OP_ID_MAP_GET: {
s_return(
sc,mk_integer(sc,the_idmap.get(
string_value(car(sc->args)))));
}
////////////////////
default:
snprintf(sc->strbuff,STRBUFFSIZE,"%d: illegal operator", sc->op);
......
android/res/drawable/arrow_left.png

3.07 KB | W: | H:

android/res/drawable/arrow_left.png

2.48 KB | W: | H:

android/res/drawable/arrow_left.png
android/res/drawable/arrow_left.png
android/res/drawable/arrow_left.png
android/res/drawable/arrow_left.png
  • 2-up
  • Swipe
  • Onion skin
android/res/drawable/arrow_right.png

2.51 KB | W: | H:

android/res/drawable/arrow_right.png

2.48 KB | W: | H:

android/res/drawable/arrow_right.png
android/res/drawable/arrow_right.png
android/res/drawable/arrow_right.png
android/res/drawable/arrow_right.png
  • 2-up
  • Swipe
  • Onion skin
android/res/drawable/bgpaw.png

1.51 KB | W: | H:

android/res/drawable/bgpaw.png

1.51 KB | W: | H:

android/res/drawable/bgpaw.png
android/res/drawable/bgpaw.png
android/res/drawable/bgpaw.png
android/res/drawable/bgpaw.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -2,38 +2,38 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape>
<gradient android:endColor="#ffff7777"
android:startColor="#ffff7777" android:angle="270" />
<stroke android:width="2dp" android:color="#000000" />
<padding android:left="5dp" android:top="5dp"
android:right="5dp" android:bottom="5dp" />
<gradient android:endColor="#eeffffff"
android:startColor="#eeffffff" android:angle="270" />
<corners android:radius="5dp" />
<padding android:left="4dp" android:top="4dp"
android:right="4dp" android:bottom="4dp" />
</shape>
</item>
<item android:state_pressed="true">
<shape>
<gradient android:endColor="#77dddddd"
android:startColor="#77dddddd" android:angle="270" />
<stroke android:width="2dp" android:color="#000000" />
<padding android:left="5dp" android:top="5dp"
android:right="5dp" android:bottom="5dp" />
<corners android:radius="5dp" />
<padding android:left="4dp" android:top="4dp"
android:right="4dp" android:bottom="4dp" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<gradient android:endColor="#77eeeeee"
android:startColor="#77eeeeee" android:angle="270" />
<stroke android:width="2dp" android:color="#000000" />
<padding android:left="5dp" android:top="5dp"
android:right="5dp" android:bottom="5dp" />
<corners android:radius="5dp" />
<padding android:left="4dp" android:top="4dp"
android:right="4dp" android:bottom="4dp" />
</shape>
</item>
<item>
<shape>
<gradient android:endColor="#77ffffff"
android:startColor="#77ffffff" android:angle="270" />
<stroke android:width="2dp" android:color="#000000" />
<padding android:left="5dp" android:top="5dp"
android:right="5dp" android:bottom="5dp" />
<corners android:radius="5dp" />
<padding android:left="4dp" android:top="4dp"
android:right="4dp" android:bottom="4dp" />
</shape>
</item>
......
......@@ -141,7 +141,7 @@ public class StarwispBuilder
BuildLayoutParam(arr.getString(2)),
(float)arr.getDouble(3));
lp.gravity=BuildLayoutGravity(arr.getString(4));
lp.setMargins(0,0,0,0);
lp.setMargins(1,1,1,1);
return lp;
} catch (JSONException e) {
Log.e("starwisp", "Error parsing data " + e.toString());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment