root/modules/gui_bench.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. gui_bench_init
  2. gui_bench_draw_results_screen
  3. gui_bench_draw_results_memory
  4. gui_bench_draw_results
  5. gui_bench_draw_results_cpu
  6. gui_bench_draw_results_text
  7. write_log
  8. add_to_log
  9. add_log_head
  10. bench_draw_control_txt
  11. bench_draw_checkbox
  12. draw_controls
  13. gui_bench_draw
  14. getcurrentmachinetime
  15. get_usec_diff
  16. bench_screen_write
  17. bench_screen_read
  18. bench_mem_write
  19. bench_mem_read
  20. bench_measure_text_write
  21. busyloop_thumb
  22. bench_measure_cpuspeed
  23. run_test
  24. gui_bench_kbd_process
  25. basic_module_init

   1 #include "camera_info.h"
   2 #include "stdlib.h"
   3 #include "keyboard.h"
   4 #include "viewport.h"
   5 #include "clock.h"
   6 #include "raw_buffer.h"
   7 #include "lang.h"
   8 #include "gui.h"
   9 #include "gui_lang.h"
  10 #include "gui_draw.h"
  11 #include "cachebit.h"
  12 
  13 #include "module_def.h"
  14 
  15 // draw_txt_string no longer exported, replace it with a macro
  16 #define draw_txt_string(x,y,s,c) draw_string((x)*FONT_WIDTH,(y)*FONT_HEIGHT,s,c)
  17 #define draw_txt_stringnonalign(x,y,s,c) draw_string((x)*FONT_WIDTH+1,(y)*FONT_HEIGHT,s,c)
  18 
  19 void gui_bench_draw();
  20 void gui_module_menu_kbd_process();
  21 int gui_bench_kbd_process();
  22 
  23 gui_handler GUI_MODE_BENCH = 
  24     /*GUI_MODE_BENCH*/  { GUI_MODE_MODULE, gui_bench_draw, gui_bench_kbd_process, gui_module_menu_kbd_process, 0, 0 };
  25 
  26 //-------------------------------------------------------------------
  27 static struct {
  28     int screen_input_bps;
  29     int screen_output_bps;
  30     int memory_read_bps;
  31     int memory_read_uc_bps;
  32     int memory_write_bps;
  33     int memory_write_uc_bps;
  34     int disk_read_buf_kbps;
  35     int disk_write_buf_kbps;
  36     int disk_write_raw_kbps;
  37     int disk_write_mem_kbps;
  38     int cpu_ips;
  39     int text_cps;
  40     int textnonalign_cps;
  41 } bench;
  42 
  43 static char buf[48];
  44 
  45 #define LOGBUFSIZE 1024
  46 #define BENCHLOGFILE "A/BENCH.LOG"
  47 
  48 static char txtbuf[LOGBUFSIZE];
  49 static int txtbufptr = 0;
  50 static int *benchbuf = NULL;
  51 static char clearline[48];
  52 static int bench_to_run = 0;
  53 static int bench_to_draw = 0;
  54 static int bench_mode = 0;
  55 static int bench_log = 0;
  56 
  57 #define BENCH_ALL 1
  58 #define BENCH_NOCARD 2
  59 
  60 #define BENCHTMP "A/BENCH.TMP"
  61 
  62 #define BENCH_CTL_START 0
  63 #define BENCH_CTL_LOG 1
  64 #define BENCH_CTL_SD 2
  65 #define BENCH_CTL_MAX BENCH_CTL_SD
  66 static int bench_cur_ctl = BENCH_CTL_START;
  67 static int bench_mode_next = BENCH_ALL;
  68 
  69 //-------------------------------------------------------------------
  70 void gui_bench_init() {
  71     bench.screen_input_bps=-1;
  72     bench.screen_output_bps=-1;
  73     bench.memory_read_bps=-1;
  74     bench.memory_read_uc_bps=-1;
  75     bench.memory_write_bps=-1;
  76     bench.memory_write_uc_bps=-1;
  77     bench.disk_read_buf_kbps=-1;
  78     bench.disk_write_buf_kbps=-1;
  79     bench.disk_write_raw_kbps=-1;
  80     bench.disk_write_mem_kbps=-1;
  81     bench.cpu_ips=-1;
  82     bench.text_cps=-1;
  83     bench.textnonalign_cps=-1;
  84     bench_to_run = 0;
  85     bench_mode = 0;
  86     bench_to_draw = 1;
  87 }
  88 
  89 //-------------------------------------------------------------------
  90 static void gui_bench_draw_results_screen(int pos, int value, int ss) {
  91     if (value!=-1) {
  92         if (value)
  93             sprintf(buf, "%7d Kb/s   %3d FPS", value/1024, (ss==0)?0:value/ss);
  94         else
  95             strcpy(buf, clearline);
  96         draw_txt_string(17, pos, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
  97     }
  98 }
  99 
 100 //-------------------------------------------------------------------
 101 static void gui_bench_draw_results_memory(int pos, int value, int value_uc) {
 102     if (value!=-1) {
 103         if (value)
 104             sprintf(buf, "%7d C,  %6d UC Kb/s ", value/1024, value_uc/1024);
 105         else
 106             strcpy(buf, clearline);
 107         draw_txt_string(17, pos, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 108     }
 109 }
 110 
 111 //-------------------------------------------------------------------
 112 static void gui_bench_draw_results(int pos, int value) {
 113     if (value!=-1) {
 114         if (value)
 115             sprintf(buf, "%7d Kb/s      ", value);
 116         else
 117             strcpy(buf, clearline);
 118         draw_txt_string(17, pos, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 119     }
 120 }
 121 
 122 //-------------------------------------------------------------------
 123 
 124 static void gui_bench_draw_results_cpu(int pos, int value) {
 125     if (value!=-1) {
 126         if (value)
 127             sprintf(buf, "%7d MIPS    ", value);
 128         else
 129             strcpy(buf, clearline);
 130         draw_txt_string(17, pos, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 131     }
 132 }
 133 
 134 //-------------------------------------------------------------------
 135 
 136 static void gui_bench_draw_results_text(int pos, int value, int valuen, int ss) {
 137     if (value!=-1) {
 138         if (value) {
 139                 int s=(ss==0)?0:FONT_WIDTH*FONT_HEIGHT*value/ss;
 140                 int sn=(ss==0)?0:FONT_WIDTH*FONT_HEIGHT*valuen/ss;
 141                 sprintf(buf, " %d, %d c/s %d, %d FPS", value, valuen, s, sn);
 142             }
 143         else
 144             strcpy(buf, clearline);
 145         draw_txt_string(17, pos, buf, MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 146     }
 147 }
 148 
 149 //-------------------------------------------------------------------
 150 
 151 static void write_log(int really) {
 152     if (!really)
 153         return;
 154     int fd = open(BENCHLOGFILE, O_WRONLY|O_CREAT|O_APPEND, 0777);
 155     if (fd >= 0)
 156     {
 157         lseek(fd, 0, SEEK_END);
 158         write(fd, txtbuf, txtbufptr);
 159         close(fd);
 160     }
 161 }
 162 
 163 static void add_to_log(int really, char *title, char *txt) {
 164     if ((txtbufptr >= LOGBUFSIZE-48) || !really)
 165         return;
 166     txtbufptr+=sprintf(txtbuf+txtbufptr,"%s %s\n",title, txt);
 167 }
 168 
 169 static void add_log_head(int really) {
 170     if ((txtbufptr >= LOGBUFSIZE-200) || !really)
 171         return;
 172     txtbufptr+=sprintf(txtbuf+txtbufptr,"***\n%s %s r%s\n",camera_info.chdk_ver,camera_info.build_number,camera_info.build_svnrev);
 173     txtbufptr+=sprintf(txtbuf+txtbufptr,"Build date: %s %s\n",camera_info.build_date,camera_info.build_time);
 174     txtbufptr+=sprintf(txtbuf+txtbufptr,"Camera    : %s %s\n",camera_info.platform,camera_info.platformsub);
 175     txtbufptr+=sprintf(txtbuf+txtbufptr,"Mode      : 0x%x\n\n",camera_info.state.mode);
 176 }
 177 
 178 static int bench_draw_control_txt(int pos, const char *s, int active) {
 179     twoColors cl;
 180     if(active) {
 181         cl = user_color(conf.menu_cursor_color);
 182     } else {
 183         cl = user_color(conf.menu_color);
 184     }
 185     draw_txt_string(pos, 0,  s, cl);
 186     return pos+strlen(s);
 187 }
 188 static int bench_draw_checkbox(int pos, const char *title, int active, int checked) {
 189     pos = bench_draw_control_txt(pos,title,active);
 190     pos = bench_draw_control_txt(pos," [",active);
 191     pos = bench_draw_control_txt(pos,(checked)?"\x95":" ",active);
 192     pos = bench_draw_control_txt(pos,"]",active);
 193     return pos;
 194 }
 195 static void draw_controls(void) {
 196     int pos = bench_draw_control_txt(1,lang_str(LANG_BENCH_START),bench_cur_ctl == BENCH_CTL_START);
 197     pos = bench_draw_checkbox(pos+1,lang_str(LANG_BENCH_LOG),bench_cur_ctl == BENCH_CTL_LOG,bench_log);
 198     bench_draw_checkbox(pos+1,lang_str(LANG_BENCH_SDTEST),bench_cur_ctl == BENCH_CTL_SD,bench_mode_next == BENCH_ALL);
 199 }
 200 
 201 //-------------------------------------------------------------------
 202 
 203 static void run_test(int num);
 204 
 205 void gui_bench_draw() {
 206     int log_run = 0;
 207     switch (bench_to_run) {
 208         case 0:
 209             break;
 210         case 1:
 211             benchbuf = malloc(0x10000);
 212             txtbufptr = 0;
 213             // fall through
 214         case 2:
 215         case 3:
 216         case 4:
 217         case 5:
 218         case 7:
 219         case 8:
 220         case 9:
 221             run_test(bench_to_run);
 222             bench_to_run++;
 223             break;
 224         case 6:
 225             if (bench_mode!=BENCH_NOCARD) {
 226                 run_test(bench_to_run);
 227                 bench_to_run++;
 228                 break;
 229             }
 230             // fall through
 231         case 10:
 232             run_test(bench_to_run);
 233             if (bench_mode!=BENCH_NOCARD) {
 234                 remove(BENCHTMP);
 235             }
 236             bench_to_run = 0;
 237             bench_mode = 0;
 238             bench_to_draw = 1;
 239             log_run = 1;
 240             if (benchbuf)
 241                 free(benchbuf);
 242             break;
 243     }
 244     switch (bench_to_draw) {
 245         case 1:
 246             draw_rectangle(camera_screen.disp_left, 0, camera_screen.disp_right, camera_screen.height-1, MAKE_COLOR(COLOR_BLACK, COLOR_BLACK), RECT_BORDER0|DRAW_FILLED);
 247             draw_controls();
 248 
 249             draw_txt_string(1, 2,  lang_str(LANG_BENCH_CPU), MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 250 
 251             draw_txt_string(1, 3,  lang_str(LANG_BENCH_SCREEN),       MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 252             draw_txt_string(3, 4,  lang_str(LANG_BENCH_WRITE), MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 253             draw_txt_string(3, 5,  lang_str(LANG_BENCH_READ), MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 254 
 255             draw_txt_string(1, 6,  lang_str(LANG_BENCH_MEMORY),  MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 256             draw_txt_string(3, 7,  lang_str(LANG_BENCH_WRITE), MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 257             draw_txt_string(3, 8,  lang_str(LANG_BENCH_READ), MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 258 
 259             draw_txt_string(1, 9,  lang_str(LANG_BENCH_TEXTOUT), MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 260 
 261             draw_txt_string(1, 10, lang_str(LANG_BENCH_FLASH_CARD), MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 262             draw_txt_string(3, 11, lang_str(LANG_BENCH_WRITE_RAW), MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 263             draw_txt_string(3, 12, lang_str(LANG_BENCH_WRITE_MEM), MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 264             draw_txt_string(3, 13, lang_str(LANG_BENCH_WRITE_64K), MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 265             draw_txt_string(3, 14, lang_str(LANG_BENCH_READ_64K), MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 266             
 267             /* no break here */
 268         case 2:
 269             add_log_head(log_run);
 270             gui_bench_draw_results_cpu(2, bench.cpu_ips);
 271             add_to_log(log_run,"CPU             :",buf);
 272 
 273             gui_bench_draw_results_screen(4, bench.screen_output_bps, camera_screen.buffer_size);
 274             add_to_log(log_run,"Screen write    :",buf);
 275             gui_bench_draw_results_screen(5, bench.screen_input_bps, camera_screen.width * vid_get_viewport_height() * 3);
 276             add_to_log(log_run,"Viewport read   :",buf);
 277 
 278             gui_bench_draw_results_memory(7, bench.memory_write_bps, bench.memory_write_uc_bps);
 279             add_to_log(log_run,"Memory write    :",buf);
 280             gui_bench_draw_results_memory(8, bench.memory_read_bps, bench.memory_read_uc_bps);
 281             add_to_log(log_run,"Memory read     :",buf);
 282 
 283             gui_bench_draw_results_text(9, bench.text_cps, bench.textnonalign_cps, camera_screen.width * camera_screen.height);
 284             add_to_log(log_run,"Text drawing    :",buf);
 285             buf[0] = 0; // empty buffer before optional tests to avoid confusing output when those are not enabled
 286 
 287             gui_bench_draw_results(11, bench.disk_write_raw_kbps);
 288             add_to_log(log_run,"Card write (RAW):",buf);
 289             gui_bench_draw_results(12, bench.disk_write_mem_kbps);
 290             add_to_log(log_run,"Card write (MEM):",buf);
 291             gui_bench_draw_results(13, bench.disk_write_buf_kbps);
 292             add_to_log(log_run,"Card write (64k):",buf);
 293             gui_bench_draw_results(14, bench.disk_read_buf_kbps);
 294             add_to_log(log_run,"Card read  (64k):",buf);
 295 
 296             write_log(log_run);
 297 
 298             bench_to_draw = 0;
 299             break;
 300         default:
 301             bench_to_draw = 0;
 302             break;
 303     }
 304 }
 305 
 306 //-------------------------------------------------------------------
 307 
 308 static unsigned int getcurrentmachinetime() {
 309     return *(unsigned int*)0xc0242014; // should be masked to the lower 20 bits (but high order bits are 0 in practice)
 310 }
 311 
 312 static unsigned int get_usec_diff(unsigned int t) {
 313     unsigned int v = *(unsigned int*)0xc0242014;
 314     if (v<t)
 315         return 0x100000+v-t;
 316     return v-t;
 317 }
 318 
 319 /*
 320  * write bytes uncached
 321  */
 322 static void bench_screen_write() {
 323     long t;
 324     register unsigned int s;
 325     register char c;
 326     register char *scr;
 327     
 328     scr = vid_get_bitmap_fb();
 329     s = camera_screen.buffer_size;
 330     t = get_tick_count();
 331 
 332     for (c=0; c<64; ++c) {
 333         asm volatile (
 334             "mov    r0, %0\n"
 335             "mov    r1, %1\n"
 336         "bsw_loop:\n"
 337             "strb   r0, [r1]\n"
 338             "add    r1, r1, #1\n"
 339             "cmp    r1, %2\n"
 340             "bne    bsw_loop\n"
 341             :: "r" (c), "r" (scr), "r" (scr+s) : "r0", "r1"
 342         );
 343     };
 344     t = get_tick_count() - t;
 345     bench.screen_output_bps = (t==0)?0:s*64*100 / (t/10);
 346     msleep(10);
 347 }
 348 
 349 /*
 350  * read bytes uncached
 351  */
 352 static void bench_screen_read() {
 353     long t;
 354     register unsigned int n, s;
 355     register char *scr;
 356 
 357     scr = vid_get_viewport_active_buffer();
 358     if (!scr) return;
 359     s = camera_screen.width * vid_get_viewport_height() * 3;
 360     // limit used mem area (due to low speed access)
 361     if ((s < 1) || (s > 360*240*3)) s = 360*240*3;
 362     t = get_tick_count();
 363     for (n=0; n<32; ++n) {
 364         asm volatile (
 365             "mov    r1, %0\n"
 366         "bsr_loop:\n"
 367             "ldrb   r0, [r1]\n"
 368             "add    r1, r1, #1\n"
 369             "cmp    r1, %1\n"
 370             "bne    bsr_loop\n"
 371             :: "r" (scr), "r" (scr+s) : "r0", "r1"
 372         );
 373     };
 374     t = get_tick_count() - t;
 375     bench.screen_input_bps = (t==0)?0:s*32*100 / (t/10);
 376     msleep(10);
 377 }
 378 
 379 /*
 380  * write words
 381  */
 382 static void bench_mem_write(int *buff) {
 383     long t, m;
 384     register unsigned int n;
 385     register char *buf = (char *)buff;
 386     int *result[2];
 387     result[0]=&bench.memory_write_bps;
 388     result[1]=&bench.memory_write_uc_bps;
 389     for (m=0; m<2; m++) {
 390         if (m==1) {
 391             buf=ADR_TO_UNCACHED(buf);
 392         }
 393         t = get_tick_count();
 394         for (n=0; n<1024; ++n) {
 395             asm volatile (
 396                 "mov    r0, %0\n"
 397                 "mov    r1, %2\n"
 398             "bmw_loop:\n"
 399                 "str    r1, [r0]\n"
 400                 "add    r0, r0, #4\n"
 401                 "cmp    r0, %1\n"
 402                 "bne    bmw_loop\n"
 403                 :: "r" (buf), "r" (buf+0x10000), "r" (n) : "r0", "r1"
 404             );
 405         };
 406         t = get_tick_count() - t;
 407         *result[m] = (t==0)?0:0x10000*100 / (t/10) * 1024;
 408         msleep(10);
 409     }
 410 }
 411 
 412 /*
 413  * read words
 414  */
 415 static void bench_mem_read(int *buff) {
 416     long t, m;
 417     register unsigned int n;
 418     register char *buf = (char *)buff;
 419     int *result[2];
 420     result[0]=&bench.memory_read_bps;
 421     result[1]=&bench.memory_read_uc_bps;
 422     for (m=0; m<2; m++) {
 423         if (m==1) {
 424             buf=ADR_TO_UNCACHED(buf);
 425         }
 426         t = get_tick_count();
 427         for (n=0; n<1024; ++n) {
 428             asm volatile (
 429                 "mov    r0, %0\n"
 430                 "mov    r1, %2\n"
 431             "bmr_loop:\n"
 432                 "ldr    r1, [r0]\n"
 433                 "add    r0, r0, #4\n"
 434                 "cmp    r0, %1\n"
 435                 "bne    bmr_loop\n"
 436                 :: "r" (buf), "r" (buf+0x10000), "r" (n) : "r0", "r1"
 437             );
 438         };
 439         t = get_tick_count() - t;
 440         *result[m] = (t==0)?0:0x10000*100 / (t/10) * 1024;
 441         msleep(10);
 442     }
 443 }
 444 
 445 /*
 446  * text writing speed (default font)
 447  */
 448 static void bench_measure_text_write() {
 449     unsigned int t, best, d;
 450     register int c;
 451 
 452     // 4 test runs, return the best speed
 453     best = 0xffffffff;
 454     for (d=0; d<4; d++) {
 455         t = getcurrentmachinetime();
 456         for (c=0; c<16; c++) {
 457             // draw 80 chars
 458             draw_txt_string(1, 1,  "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_+", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 459             draw_txt_string(1, 1,  "abcdefghijklmnopqrstuvwxyz0123456789.-_+", MAKE_COLOR(COLOR_GREEN, COLOR_RED));
 460         };
 461         t = get_usec_diff(t);
 462         msleep(10);
 463         if (t < best) best = t;
 464     }
 465     bench.text_cps = (best==0)?0:16*80*1000000/best;
 466     best = 0xffffffff;
 467     for (d=0; d<4; d++) {
 468         t = getcurrentmachinetime();
 469         for (c=0; c<16; c++) {
 470             // draw 80 chars
 471             draw_txt_stringnonalign(1, 1,  "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_+", MAKE_COLOR(COLOR_BLACK, COLOR_WHITE));
 472             draw_txt_stringnonalign(1, 1,  "abcdefghijklmnopqrstuvwxyz0123456789.-_+", MAKE_COLOR(COLOR_GREEN, COLOR_RED));
 473         };
 474         t = get_usec_diff(t);
 475         msleep(10);
 476         if (t < best) best = t;
 477     }
 478     bench.textnonalign_cps = (best==0)?0:16*80*1000000/best;
 479 }
 480 
 481 //-------------------------------------------------------------------
 482 
 483 /*
 484  * simple loop for "measuring" CPU speed
 485  * ARM mode is used due to the ambiguity of thumb mnemonics (sub vs. subs)
 486  */
 487 void __attribute__((naked,noinline)) busyloop_thumb(int loops) {
 488     asm volatile (
 489 #if defined(__thumb__)
 490     ".code 16\n"
 491     "bx      pc\n"
 492     ".code 32\n"
 493 #endif
 494     ".align 4\n"
 495     "z1:\n"
 496     "subs    r0, r0, #1\n"
 497     "bhi     z1\n"
 498     "bx      lr\n"
 499     );
 500 }
 501 
 502 #define CYCLES 100000 // how many cycles to do
 503 #define INSTPERCYCLE 2 // instructions / cycle in the countdown part of code
 504 
 505 static void bench_measure_cpuspeed() {
 506     unsigned int t, best, c;
 507 
 508     // 4 test runs, return the best speed
 509     best = 0xffffffff;
 510     for (c=0; c<4; c++) {
 511         t = getcurrentmachinetime();
 512         busyloop_thumb(CYCLES);
 513         t = get_usec_diff(t);
 514         msleep(10);
 515         if (t < best) best = t;
 516     }
 517     bench.cpu_ips = (best==0)?0:INSTPERCYCLE*CYCLES/best; // MIPS
 518 }
 519 
 520 //-------------------------------------------------------------------
 521 
 522 static void run_test(int num) {
 523     long t;
 524     int x;
 525     unsigned int n, s;
 526     switch (num) {
 527         case 1:
 528             bench.cpu_ips = 0;
 529             bench_measure_cpuspeed();
 530             bench.screen_output_bps = 0;
 531             bench_to_draw = 2;
 532             break;
 533         case 2:
 534             bench_screen_write();
 535             bench.screen_input_bps = 0;
 536             bench_to_draw = 1;
 537             break;
 538         case 3:
 539             bench_screen_read();
 540             bench.memory_write_bps = 0;
 541             bench_to_draw = 2;
 542             break;
 543         case 4:
 544             if (benchbuf) {
 545                 bench_mem_write(benchbuf);
 546             }
 547             bench.memory_read_bps = 0;
 548             bench_to_draw = 2;
 549             break;
 550         case 5:
 551             if (benchbuf) {
 552                 bench_mem_read(benchbuf);
 553             }
 554             bench.text_cps = 0;
 555             bench_to_draw = 2;
 556             break;
 557         case 6:
 558             bench_measure_text_write();
 559             if (bench_mode!=BENCH_NOCARD) {
 560                 bench.disk_write_raw_kbps = 0;
 561             }
 562             bench_to_draw = 1;
 563             break;
 564         case 7:
 565             x = open(BENCHTMP, O_WRONLY|O_CREAT, 0777);
 566             if (x>=0) {
 567                 t = get_tick_count();
 568                 s=write(x, hook_raw_image_addr(), camera_sensor.raw_size)/1024;
 569                 t = get_tick_count() - t;
 570                 close(x);
 571                 bench.disk_write_raw_kbps = (t==0)?0:s*100 / (t/10);
 572             }
 573             bench.disk_write_mem_kbps = 0;
 574             bench_to_draw = 2;
 575             break;
 576         case 8:
 577             x = open(BENCHTMP, O_WRONLY|O_CREAT, 0777);
 578             if (x>=0) {
 579                 t = get_tick_count();
 580                 s=write(x, (void*)0x10000, 0xC00000)/1024;
 581                 t = get_tick_count() - t;
 582                 close(x);
 583                 bench.disk_write_mem_kbps = (t==0)?0:s*100 / (t/10);
 584             }
 585             bench.disk_write_buf_kbps = 0;
 586             bench_to_draw = 2;
 587             break;
 588         case 9:
 589             if (benchbuf) {
 590                 x = open(BENCHTMP, O_WRONLY|O_CREAT, 0777);
 591                 if (x>=0) {
 592                     s = 0;
 593                     t = get_tick_count();
 594                     for (n=0; n<256; ++n)
 595                         s+=write(x, benchbuf, 0x10000);
 596                     t = get_tick_count() - t;
 597                     s = s / 1024;
 598                     close(x);
 599                     bench.disk_write_buf_kbps = (t==0)?0:s*100 / (t/10);
 600                 }
 601             }
 602             bench.disk_read_buf_kbps = 0;
 603             bench_to_draw = 2;
 604             break;
 605         case 10:
 606             if (benchbuf) {
 607                 x = open(BENCHTMP, O_RDONLY, 0777);
 608                 if (x>=0) {
 609                     s = 0;
 610                     t = get_tick_count();
 611                     for (n=0; n<256; ++n)
 612                         s+=read(x, benchbuf, 0x10000);
 613                     t = get_tick_count() - t;
 614                     s = s / 1024;
 615                     close(x);
 616                     bench.disk_read_buf_kbps = (t==0)?0:s*100 / (t/10);
 617                 }
 618             }
 619             bench_to_draw = 2;
 620             break;
 621     }
 622 }
 623 
 624 //-------------------------------------------------------------------
 625 
 626 int gui_bench_kbd_process()
 627 {
 628     if (bench_to_run) return 0; // ignore keyboard during tests
 629     switch (kbd_get_autoclicked_key()) {
 630     case KEY_SET:
 631         switch(bench_cur_ctl) {
 632             case BENCH_CTL_START:
 633                 gui_bench_init();
 634                 bench_mode = bench_mode_next;
 635                 bench_to_run = 1;
 636                 break;
 637              case BENCH_CTL_LOG:
 638                 bench_log = !bench_log;
 639                 bench_to_draw = 1;
 640                 break;
 641              case BENCH_CTL_SD:
 642                 bench_mode_next = (bench_mode_next == BENCH_ALL)?BENCH_NOCARD:BENCH_ALL;
 643                 bench_to_draw = 1;
 644                 break;
 645         }
 646         break;
 647     // switch controls
 648     case KEY_LEFT:
 649         bench_cur_ctl = (bench_cur_ctl>0)?bench_cur_ctl-1:BENCH_CTL_MAX;
 650         bench_to_draw = 1;
 651         break;
 652     case KEY_RIGHT:
 653         bench_cur_ctl = (bench_cur_ctl<BENCH_CTL_MAX)?bench_cur_ctl+1:0;
 654         bench_to_draw = 1;
 655         break;
 656     }
 657     return 0;
 658 }
 659 
 660 //-------------------------------------------------------------------
 661 
 662 int basic_module_init()
 663 {
 664     int cl = strlen(lang_str(LANG_BENCH_CALCULATING));
 665     strncpy(clearline, lang_str(LANG_BENCH_CALCULATING), 27);
 666     if (cl < 27)
 667     {
 668         strncpy(clearline+cl, "                           ", 27-cl);
 669     }
 670 
 671     gui_bench_init();
 672     gui_set_mode(&GUI_MODE_BENCH);
 673     return 1;
 674 }
 675 
 676 #include "simple_module.c"
 677 
 678 /******************** Module Information structure ******************/
 679 
 680 ModuleInfo _module_info =
 681 {
 682     MODULEINFO_V1_MAGICNUM,
 683     sizeof(ModuleInfo),
 684     SIMPLE_MODULE_VERSION,              // Module version
 685 
 686     ANY_CHDK_BRANCH, 0, OPT_ARCHITECTURE,                       // Requirements of CHDK version
 687     ANY_PLATFORM_ALLOWED,               // Specify platform dependency
 688 
 689     -LANG_MENU_DEBUG_BENCHMARK,
 690     MTYPE_TOOL,             //Test camera low level performance
 691 
 692     &_librun.base,
 693 
 694     ANY_VERSION,                // CONF version
 695     CAM_SCREEN_VERSION,         // CAM SCREEN version
 696     CAM_SENSOR_VERSION,         // CAM SENSOR version
 697     ANY_VERSION,                // CAM INFO version
 698 
 699     0x2a,                       // Menu symbol
 700 };

/* [<][>][^][v][top][bottom][index][help] */