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

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