From 9afad43a3ea781e98895fadbd85fac3fa42d2f45 Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 11 Aug 2016 19:29:09 +0800 Subject: [PATCH 1/2] refactoring utils to tools as discussed in #2197 --- Makefile | 4 ++-- frontend/device/kobo/device.lua | 2 +- spec/unit/touch_probe_spec.lua | 2 +- {utils => tools}/kobo_touch_probe.lua | 2 +- {utils => tools}/trace_require.lua | 2 +- {utils => tools}/wbuilder.lua | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) rename {utils => tools}/kobo_touch_probe.lua (98%) rename {utils => tools}/trace_require.lua (95%) rename {utils => tools}/wbuilder.lua (99%) diff --git a/Makefile b/Makefile index d4e0f9505..ba2491865 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ UBUNTUTOUCH_SDL_DIR:=$(UBUNTUTOUCH_DIR)/ubuntu-touch-sdl WIN32_DIR=$(PLATFORM_DIR)/win32 # files to link from main directory -INSTALL_FILES=reader.lua frontend resources defaults.lua datastorage.lua l10n utils \ +INSTALL_FILES=reader.lua frontend resources defaults.lua datastorage.lua l10n tools \ README.md COPYING # for gettext @@ -336,7 +336,7 @@ pot: mkdir -p $(TEMPLATE_DIR) $(XGETTEXT_BIN) reader.lua `find frontend -iname "*.lua"` \ `find plugins -iname "*.lua"` \ - `find utils -iname "*.lua"` \ + `find tools -iname "*.lua"` \ > $(TEMPLATE_DIR)/$(DOMAIN).pot # push source file to Transifex $(MAKE) -i -C l10n bootstrap push diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index 089a64b7f..707c1e2c7 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -144,7 +144,7 @@ function Kobo:init() local switch_xy = G_reader_settings:readSetting("kobo_touch_switch_xy") -- and has no probe before if switch_xy == nil then - local TouchProbe = require("utils/kobo_touch_probe") + local TouchProbe = require("tools/kobo_touch_probe") local UIManager = require("ui/uimanager") UIManager:show(TouchProbe:new{}) UIManager:run() diff --git a/spec/unit/touch_probe_spec.lua b/spec/unit/touch_probe_spec.lua index ab0c1534d..c2cf072fd 100644 --- a/spec/unit/touch_probe_spec.lua +++ b/spec/unit/touch_probe_spec.lua @@ -5,7 +5,7 @@ describe("touch probe module", function() it("should probe properly for kobo touch", function() local Device = require("device") - local TouchProbe = require("utils/kobo_touch_probe"):new{} + local TouchProbe = require("tools/kobo_touch_probe"):new{} local need_to_switch_xy TouchProbe.saveSwitchXYSetting = function(_, new_need_to_switch_xy) need_to_switch_xy = new_need_to_switch_xy diff --git a/utils/kobo_touch_probe.lua b/tools/kobo_touch_probe.lua similarity index 98% rename from utils/kobo_touch_probe.lua rename to tools/kobo_touch_probe.lua index 0547398d9..0c8ea8f33 100755 --- a/utils/kobo_touch_probe.lua +++ b/tools/kobo_touch_probe.lua @@ -1,5 +1,5 @@ -- touch probe utility --- usage: ./luajit util/kobo_touch_probe.lua +-- usage: ./luajit tools/kobo_touch_probe.lua require "defaults" package.path = "common/?.lua;rocks/share/lua/5.1/?.lua;frontend/?.lua;" .. package.path diff --git a/utils/trace_require.lua b/tools/trace_require.lua similarity index 95% rename from utils/trace_require.lua rename to tools/trace_require.lua index a5e00668d..e32fdee1b 100644 --- a/utils/trace_require.lua +++ b/tools/trace_require.lua @@ -1,5 +1,5 @@ -- trace package loading flow with require call --- usage: ./luajit -lutils/trace_require reader.lua ../../test +-- usage: ./luajit -ltools/trace_require reader.lua ../../test local math = require("math") local _require = require diff --git a/utils/wbuilder.lua b/tools/wbuilder.lua similarity index 99% rename from utils/wbuilder.lua rename to tools/wbuilder.lua index 7c77b60c9..f3440981c 100755 --- a/utils/wbuilder.lua +++ b/tools/wbuilder.lua @@ -1,5 +1,5 @@ -- widget test utility --- usage: ./luajit util/wtest.lua +-- usage: ./luajit tools/wtest.lua require "defaults" print(package.path) From 214c8971e74eb8fbd01fdcf3ffe37bd5ddfc4f2d Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 11 Aug 2016 22:53:00 +0800 Subject: [PATCH 2/2] fix k2pdfopt performance degradation --- base | 2 +- tools/benchmark.lua | 55 ++++++++++++++++++++++++++++++++++++++ tools/kobo_touch_probe.lua | 7 +++-- tools/trace_require.lua | 0 4 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 tools/benchmark.lua mode change 100644 => 100755 tools/trace_require.lua diff --git a/base b/base index 07b6442b4..d33be25e6 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 07b6442b4cc52bfe41b64e2b5e0f528bbb11089f +Subproject commit d33be25e6ad412bb98a6fa2ac3edf5f26d36c8ca diff --git a/tools/benchmark.lua b/tools/benchmark.lua new file mode 100644 index 000000000..f3f1c18c7 --- /dev/null +++ b/tools/benchmark.lua @@ -0,0 +1,55 @@ +-- performance benchmark utility +-- usage: ./luajit tools/benchmark.lua test/sample.pdf + +require "defaults" +package.path = "common/?.lua;rocks/share/lua/5.1/?.lua;frontend/?.lua;" .. package.path +package.cpath = "common/?.so;common/?.dll;/usr/lib/lua/?.so;rocks/lib/lua/5.1/?.so;" .. package.cpath + +local DataStorage = require("datastorage") +--G_reader_settings = require("docsettings"):open(".reader") +G_reader_settings = require("luasettings"):open( + DataStorage:getDataDir().."/settings.reader.lua") + +-- global einkfb for Screen (do not show SDL window) +einkfb = require("ffi/framebuffer") +einkfb.dummy = true + +local DocumentRegistry = require("document/documentregistry") +local Koptinterface = require("document/koptinterface") +local util = require("ffi/util") +local DEBUG = require("dbg") +DEBUG:turnOn() + +DEBUG("args", arg) + +function logDuration(filename, pageno, dur) + local file = io.open(filename, "a+") + if file then + file:write(string.format("%s\t%s\n", pageno, dur)) + file:close() + end +end + +function doAutoBBox(doc, page) + Koptinterface:getAutoBBox(doc, page) +end + +function doReflow(doc, page) + Koptinterface:getCachedContext(doc, page) +end + +function benchmark(filename, doForOnePage) + local doc = DocumentRegistry:openDocument(filename) + for i = 1, doc:getPageCount() do + local secs, usecs = util.gettime() + doForOnePage(doc, i) + local nsecs, nusecs = util.gettime() + local dur = nsecs - secs + (nusecs - usecs) / 1000000 + DEBUG("duration for page", i, dur) + logDuration("benchmark.txt", i, dur) + end +end + +--benchmark(arg[1], doAutoBBox) +benchmark(arg[1], doReflow) + diff --git a/tools/kobo_touch_probe.lua b/tools/kobo_touch_probe.lua index 0c8ea8f33..71aa2ad8c 100755 --- a/tools/kobo_touch_probe.lua +++ b/tools/kobo_touch_probe.lua @@ -5,15 +5,14 @@ require "defaults" package.path = "common/?.lua;rocks/share/lua/5.1/?.lua;frontend/?.lua;" .. package.path package.cpath = "common/?.so;common/?.dll;/usr/lib/lua/?.so;rocks/lib/lua/5.1/?.so;" .. package.cpath -local DocSettings = require("docsettings") +local DataStorage = require("datastorage") local _ = require("gettext") -- read settings and check for language override -- has to be done before requiring other files because -- they might call gettext on load -if G_reader_settings == nil then - G_reader_settings = DocSettings:open(".reader") -end +G_reader_settings = require("luasettings"):open( + DataStorage:getDataDir().."/settings.reader.lua") local lang_locale = G_reader_settings:readSetting("language") if lang_locale then _.changeLang(lang_locale) diff --git a/tools/trace_require.lua b/tools/trace_require.lua old mode 100644 new mode 100755