/* test/shelf_bench_ondev.c — 真机耗时基准(不进发行包,不参与 mpk)。 * * 目的:在**同一台设备、同一字库/主题环境**下量 App 的同步耗时,用来给书架缓存 / * 行自绘 / 开书路径做前后对比(宿主数字不算数)。 * * 只调 App/SDK 公共入口(与 app.c 的调用顺序一致),不复制任何内部实现: * meow_ui_init → 建三页 → push 书架(= 首次进书架,含扫描) * → push/pop 阅读页 ×N(= 从阅读页返回书架) * → shelf_on_swipe ×N(= 书架滑动,含 widget_draw + flush 上屏) * → reader_open + push 阅读页(= 点书开读首屏)、翻页 * * 用法(设备):shelf_bench_ondev [book1 [book2 ...]] * 输出:`BENCH - (avg ...)` 行,ms 为毫秒(设备时钟 10ms 分辨率, * 单次量用多轮取样给区间;批量操作用「总时长/次数」给出平均值)。 */ #include "reader_internal.h" #include "app/shelf_model.h" #include "meow_ui_internal.h" #include #include #include static uint64_t now_ms(void) { return meow_ui_time_ms(); } static void bench_scan(void) { static shelf_book books[SHELF_MAX_BOOKS]; shelf_scan_report rep; uint64_t t0 = now_ms(); int n = shelf_scan_books(READER_SD_ROOT "/Books", books, SHELF_MAX_BOOKS, NULL, &rep); uint64_t t1 = now_ms(); printf("BENCH scan_ms %llu (n=%d truncated=%d depth_skipped=%d root_missing=%d)\n", (unsigned long long)(t1 - t0), n, rep.truncated, rep.depth_skipped, rep.root_missing); fflush(stdout); } int main(int argc, char **argv) { meow_ui_opts o = { 480, 720 }; if (meow_ui_init(&o) != 0) { printf("BENCH init_fail\n"); return 1; } meow_theme_add_listener(NULL); bench_scan(); /* 纯扫描基线(不建 UI) */ shelf_view_create(); reader_view_create(); settings_view_create(); /* ① 首次进书架(新进程:含全量扫描 + 建控件 + 首帧上屏) */ uint64_t t0 = now_ms(); meow_view_page_push(ACT_SHELF); uint64_t t1 = now_ms(); printf("BENCH shelf_first_enter_ms %llu\n", (unsigned long long)(t1 - t0)); /* ② 从阅读页返回书架:push 阅读页(不等书)→ pop 回书架;连做 5 次给区间 */ unsigned long long rmin = 0, rmax = 0, rsum = 0; for (int i = 0; i < 5; i++) { meow_view_page_push(ACT_READER); uint64_t a = now_ms(); meow_view_page_pop(); uint64_t b = now_ms(); uint64_t d = b - a; if (i == 0 || d < rmin) rmin = d; if (i == 0 || d > rmax) rmax = d; rsum += d; } printf("BENCH shelf_return_ms %llu-%llu (avg %llu)\n", rmin, rmax, rsum / 5); /* ③ 书架滑动:每步 62px(与 survey 同口径:scroll 62 + widget_draw + flush) */ for (int batch = 0; batch < 3; batch++) { uint64_t a = now_ms(); for (int i = 0; i < 30; i++) shelf_on_swipe(MEOW_SWIPE_UP, 0, 62); uint64_t b = now_ms(); printf("BENCH shelf_scroll_step_ms %.1f (batch %d: 30 steps %llu ms)\n", (double)(b - a) / 30.0, batch, (unsigned long long)(b - a)); for (int i = 0; i < 30; i++) shelf_on_swipe(MEOW_SWIPE_DOWN, 0, 62); /* 回到顶部 */ } fflush(stdout); /* ④ 开书首屏 / 翻页(argv 给书路径;不给则跳过) */ for (int i = 1; i < argc; i++) { uint64_t a = now_ms(); int rc = reader_open(argv[i]); uint64_t b = now_ms(); if (rc != 0) { printf("BENCH open_fail %s\n", argv[i]); continue; } meow_view_page_push(ACT_READER); uint64_t c = now_ms(); printf("BENCH open_ms %llu (reader_open %llu + page_push %llu) %s\n", (unsigned long long)(c - a), (unsigned long long)(b - a), (unsigned long long)(c - b), argv[i]); /* 翻页:reader_page_key 置 pending → reader_on_tick 消费(同步段=turn+refill+redraw) * 轮数由 MEOW_BENCH_TURNS 控制(0=不翻页 → 用于「开书不翻页进度文件不变」回归)。 */ const char *et = getenv("MEOW_BENCH_TURNS"); int nturns = et && et[0] ? atoi(et) : 4; unsigned long long tmin = 0, tmax = 0, tsum = 0; for (int p = 0; p < nturns; p++) { reader_page_key(1); uint64_t x = now_ms(); reader_on_tick(now_ms()); uint64_t y = now_ms(); uint64_t d = y - x; if (p == 0 || d < tmin) tmin = d; if (p == 0 || d > tmax) tmax = d; tsum += d; } printf("BENCH turn_ms %llu-%llu (avg %llu) %s\n", tmin, tmax, nturns ? tsum / nturns : 0, argv[i]); meow_view_page_pop(); fflush(stdout); } meow_ui_shutdown(); return 0; }