From 11c350a5dbca70ccf614449f22ec7214c0a42266 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Thu, 17 Oct 2019 13:52:59 +0800 Subject: [PATCH 1/7] ci: bring up benchmark --- .travis.yml | 1 + test/benchmark.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 test/benchmark.sh diff --git a/.travis.yml b/.travis.yml index 824bbdff9f..a5f2f33e75 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ node_js: script: - npm run eslint - npm run test-cov + - ./test/benchmark.sh after_script: - npm install coveralls diff --git a/test/benchmark.sh b/test/benchmark.sh new file mode 100755 index 0000000000..4cffffb385 --- /dev/null +++ b/test/benchmark.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +echo "========== Hexo Benchmark ==========" + +echo "- Set up dummy Hexo site" +cd $TRAVIS_BUILD_DIR +cd .. +git clone https://github.com/hexojs/hexo-theme-unit-test.git --depth=1 --quiet +cd hexo-theme-unit-test + +echo "- Install hexo-theme-landscape" +git clone https://github.com/hexojs/hexo-theme-landscape --depth=1 --quiet themes/landscape + +echo "- npm install" +npm install --silent + +echo "- Import 300 posts" +git clone https://github.com/SukkaLab/hexo-many-posts.git source/_posts/hexo-many-posts --depth=1 --quiet +rm -rf source/_posts/hexo-many-posts/.git/ + +echo "- Replace node_modules/hexo" +ln -sf $TRAVIS_BUILD_DIR node_modules/hexo + +echo "- Start test run" + +echo "-------------- Test 1 --------------" +npx --no-install hexo g --debug > build.log +cat build.log | grep "Hexo version" +cat build.log | grep "Start processing" +cat build.log | grep "loaded in" +cat build.log | grep "generated in" +cat build.log | grep "Database saved" +echo "-------------- Test 2 --------------" +npx --no-install hexo g --debug > build.log +cat build.log | grep "Hexo version" +cat build.log | grep "Start processing" +cat build.log | grep "loaded in" +cat build.log | grep "generated in" +cat build.log | grep "Database saved" +rm -rf build.log + +cd $TRAVIS_BUILD_DIR From 9e4911d241fea761cbf7beff5bfad021fb21542e Mon Sep 17 00:00:00 2001 From: SukkaW Date: Fri, 18 Oct 2019 01:45:48 +0800 Subject: [PATCH 2/7] ci: update benchmark - output log - add another cold process --- test/benchmark.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/test/benchmark.sh b/test/benchmark.sh index 4cffffb385..b06df5724c 100755 --- a/test/benchmark.sh +++ b/test/benchmark.sh @@ -1,6 +1,6 @@ #!/bin/sh -echo "========== Hexo Benchmark ==========" +echo "============== Hexo Benchmark ==============" echo "- Set up dummy Hexo site" cd $TRAVIS_BUILD_DIR @@ -23,14 +23,22 @@ ln -sf $TRAVIS_BUILD_DIR node_modules/hexo echo "- Start test run" -echo "-------------- Test 1 --------------" +echo "------------- Cold processing --------------" npx --no-install hexo g --debug > build.log cat build.log | grep "Hexo version" cat build.log | grep "Start processing" cat build.log | grep "loaded in" cat build.log | grep "generated in" cat build.log | grep "Database saved" -echo "-------------- Test 2 --------------" +echo "-------------- Hot processing --------------" +npx --no-install hexo g --debug > build.log +cat build.log | grep "Hexo version" +cat build.log | grep "Start processing" +cat build.log | grep "loaded in" +cat build.log | grep "generated in" +cat build.log | grep "Database saved" +echo "--------- Another Cold processing ----------" +npx --no-install hexo clean > build.log npx --no-install hexo g --debug > build.log cat build.log | grep "Hexo version" cat build.log | grep "Start processing" From 08ae1889f1b4ab6bda8386196994ba081189d7fd Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sat, 19 Oct 2019 00:57:15 +0800 Subject: [PATCH 3/7] ci: format benchmark result output --- test/benchmark.sh | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/test/benchmark.sh b/test/benchmark.sh index b06df5724c..e42801f8a5 100755 --- a/test/benchmark.sh +++ b/test/benchmark.sh @@ -1,5 +1,19 @@ #!/bin/sh +_SUBSTRUCTION () { + echo | awk "{print $1-$2}" +} + +LOG_TABLE () { + time_begin=$(date +%s -d "$(awk '/.*DEBUG Hexo version/{print $1}' build.log)") + time_process_start=$(date +%s.%3N -d "$(awk '/.*INFO Start processing/{print $1}' build.log)") + time_render_start=$(date +%s.%3N -d "$(awk '/.*INFO Files loaded in/{print $1}' build.log)") + time_render_finish=$(date +%s.%3N -d "$(awk '/.*INFO.*generated in /{print $1}' build.log)") + time_database_saved=$(date +%s.%3N -d "$(awk '/.*DEBUG Database saved/{print $1}' build.log)") + + echo "Load Plugin/Scripts/Database $(_SUBSTRUCTION $time_process_start $time_begin)\nProcess Source $(_SUBSTRUCTION $time_render_start $time_process_start)\nRender Files $(_SUBSTRUCTION $time_render_finish $time_render_start)\nSave Database $(_SUBSTRUCTION $time_database_saved $time_render_finish)" | awk '{printf "| %-28s | %7.3fs |\n",$1" "$2,$3"s"}' +} + echo "============== Hexo Benchmark ==============" echo "- Set up dummy Hexo site" @@ -19,32 +33,24 @@ git clone https://github.com/SukkaLab/hexo-many-posts.git source/_posts/hexo-man rm -rf source/_posts/hexo-many-posts/.git/ echo "- Replace node_modules/hexo" +rm -rf node_modules/hexo ln -sf $TRAVIS_BUILD_DIR node_modules/hexo echo "- Start test run" echo "------------- Cold processing --------------" npx --no-install hexo g --debug > build.log -cat build.log | grep "Hexo version" -cat build.log | grep "Start processing" -cat build.log | grep "loaded in" -cat build.log | grep "generated in" -cat build.log | grep "Database saved" +LOG_TABLE + echo "-------------- Hot processing --------------" npx --no-install hexo g --debug > build.log -cat build.log | grep "Hexo version" -cat build.log | grep "Start processing" -cat build.log | grep "loaded in" -cat build.log | grep "generated in" -cat build.log | grep "Database saved" +LOG_TABLE + echo "--------- Another Cold processing ----------" npx --no-install hexo clean > build.log npx --no-install hexo g --debug > build.log -cat build.log | grep "Hexo version" -cat build.log | grep "Start processing" -cat build.log | grep "loaded in" -cat build.log | grep "generated in" -cat build.log | grep "Database saved" +LOG_TABLE + rm -rf build.log cd $TRAVIS_BUILD_DIR From 4be2490f8be4f67969ca9535a57f8068e0ec23f5 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sat, 19 Oct 2019 16:51:11 +0800 Subject: [PATCH 4/7] ci: simplify benchmark code & add total time --- test/benchmark.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/benchmark.sh b/test/benchmark.sh index e42801f8a5..fbde6138b4 100755 --- a/test/benchmark.sh +++ b/test/benchmark.sh @@ -4,6 +4,10 @@ _SUBSTRUCTION () { echo | awk "{print $1-$2}" } +_MESSAGE_FORMATTER () { + awk '{printf "| %-29s | %7.3fs |\n",$1" "$2,$3"s"}' +} + LOG_TABLE () { time_begin=$(date +%s -d "$(awk '/.*DEBUG Hexo version/{print $1}' build.log)") time_process_start=$(date +%s.%3N -d "$(awk '/.*INFO Start processing/{print $1}' build.log)") @@ -11,7 +15,11 @@ LOG_TABLE () { time_render_finish=$(date +%s.%3N -d "$(awk '/.*INFO.*generated in /{print $1}' build.log)") time_database_saved=$(date +%s.%3N -d "$(awk '/.*DEBUG Database saved/{print $1}' build.log)") - echo "Load Plugin/Scripts/Database $(_SUBSTRUCTION $time_process_start $time_begin)\nProcess Source $(_SUBSTRUCTION $time_render_start $time_process_start)\nRender Files $(_SUBSTRUCTION $time_render_finish $time_render_start)\nSave Database $(_SUBSTRUCTION $time_database_saved $time_render_finish)" | awk '{printf "| %-28s | %7.3fs |\n",$1" "$2,$3"s"}' + echo "Load Plugin/Scripts/Database $(_SUBSTRUCTION $time_process_start $time_begin)" | _MESSAGE_FORMATTER + echo "Process Source $(_SUBSTRUCTION $time_render_start $time_process_start)" | _MESSAGE_FORMATTER + echo "Render Files $(_SUBSTRUCTION $time_render_finish $time_render_start)" | _MESSAGE_FORMATTER + echo "Save Database $(_SUBSTRUCTION $time_database_saved $time_render_finish)" | _MESSAGE_FORMATTER + echo "Total time $(_SUBSTRUCTION $time_database_saved $time_begin)" | _MESSAGE_FORMATTER } echo "============== Hexo Benchmark ==============" From d4f217a82bb039b40694e3c41d0faa231d4d324c Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sun, 20 Oct 2019 18:00:15 +0800 Subject: [PATCH 5/7] ci: add memory usage to benchmark --- .travis.yml | 5 +++++ test/benchmark.sh | 22 +++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index a5f2f33e75..c19590596c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,11 @@ language: node_js sudo: false +addons: + apt: + packages: + - time + cache: apt: true directories: diff --git a/test/benchmark.sh b/test/benchmark.sh index fbde6138b4..63a0319f75 100755 --- a/test/benchmark.sh +++ b/test/benchmark.sh @@ -5,7 +5,7 @@ _SUBSTRUCTION () { } _MESSAGE_FORMATTER () { - awk '{printf "| %-29s | %7.3fs |\n",$1" "$2,$3"s"}' + awk '{printf "| %-29s | %7.3fs |\n",$1" "$2,$3}' } LOG_TABLE () { @@ -15,11 +15,14 @@ LOG_TABLE () { time_render_finish=$(date +%s.%3N -d "$(awk '/.*INFO.*generated in /{print $1}' build.log)") time_database_saved=$(date +%s.%3N -d "$(awk '/.*DEBUG Database saved/{print $1}' build.log)") - echo "Load Plugin/Scripts/Database $(_SUBSTRUCTION $time_process_start $time_begin)" | _MESSAGE_FORMATTER - echo "Process Source $(_SUBSTRUCTION $time_render_start $time_process_start)" | _MESSAGE_FORMATTER - echo "Render Files $(_SUBSTRUCTION $time_render_finish $time_render_start)" | _MESSAGE_FORMATTER - echo "Save Database $(_SUBSTRUCTION $time_database_saved $time_render_finish)" | _MESSAGE_FORMATTER - echo "Total time $(_SUBSTRUCTION $time_database_saved $time_begin)" | _MESSAGE_FORMATTER + memory_usage=$(awk '/.*Maximum resident set size/{print $6}' build.log) + + echo "Load Plugin/Scripts/Database $(_SUBSTRUCTION $time_process_start $time_begin)s" | _MESSAGE_FORMATTER + echo "Process Source $(_SUBSTRUCTION $time_render_start $time_process_start)s" | _MESSAGE_FORMATTER + echo "Render Files $(_SUBSTRUCTION $time_render_finish $time_render_start)s" | _MESSAGE_FORMATTER + echo "Save Database $(_SUBSTRUCTION $time_database_saved $time_render_finish)s" | _MESSAGE_FORMATTER + echo "Total time $(_SUBSTRUCTION $time_database_saved $time_begin)s" | _MESSAGE_FORMATTER + echo "Memory Usage (RSS) $(echo | awk "{print $memory_usage/1024}")MB" | _MESSAGE_FORMATTER } echo "============== Hexo Benchmark ==============" @@ -47,18 +50,19 @@ ln -sf $TRAVIS_BUILD_DIR node_modules/hexo echo "- Start test run" echo "------------- Cold processing --------------" -npx --no-install hexo g --debug > build.log +{ /usr/bin/time -v npx --no-install hexo g --debug > build.log 2>&1 ; } 2> build.log LOG_TABLE echo "-------------- Hot processing --------------" -npx --no-install hexo g --debug > build.log +{ /usr/bin/time -v npx --no-install hexo g --debug > build.log 2>&1 ; } 2> build.log LOG_TABLE echo "--------- Another Cold processing ----------" npx --no-install hexo clean > build.log -npx --no-install hexo g --debug > build.log +{ /usr/bin/time -v npx --no-install hexo g --debug > build.log 2>&1 ; } 2> build.log LOG_TABLE +echo "--------------------------------------------" rm -rf build.log cd $TRAVIS_BUILD_DIR From bf03ad83971696f8f3d60639267b244a886cfb76 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sun, 20 Oct 2019 19:36:52 +0800 Subject: [PATCH 6/7] ci: fix memory usage output --- test/benchmark.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/benchmark.sh b/test/benchmark.sh index 63a0319f75..20c35a54a8 100755 --- a/test/benchmark.sh +++ b/test/benchmark.sh @@ -5,7 +5,7 @@ _SUBSTRUCTION () { } _MESSAGE_FORMATTER () { - awk '{printf "| %-29s | %7.3fs |\n",$1" "$2,$3}' + awk '{printf "| %-29s | %7.3f |\n",$1" "$2,$3}' } LOG_TABLE () { @@ -22,7 +22,7 @@ LOG_TABLE () { echo "Render Files $(_SUBSTRUCTION $time_render_finish $time_render_start)s" | _MESSAGE_FORMATTER echo "Save Database $(_SUBSTRUCTION $time_database_saved $time_render_finish)s" | _MESSAGE_FORMATTER echo "Total time $(_SUBSTRUCTION $time_database_saved $time_begin)s" | _MESSAGE_FORMATTER - echo "Memory Usage (RSS) $(echo | awk "{print $memory_usage/1024}")MB" | _MESSAGE_FORMATTER + echo "Memory Usage(RSS) $(echo | awk "{print $memory_usage/1024}")MB" | _MESSAGE_FORMATTER } echo "============== Hexo Benchmark ==============" From 27b89c13a6c4e8c1c89314013f289f2d9c08b0f2 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sun, 20 Oct 2019 20:13:14 +0800 Subject: [PATCH 7/7] ci: fix benchmark output format --- test/benchmark.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/benchmark.sh b/test/benchmark.sh index 20c35a54a8..e04c13e7dc 100755 --- a/test/benchmark.sh +++ b/test/benchmark.sh @@ -1,11 +1,11 @@ #!/bin/sh _SUBSTRUCTION () { - echo | awk "{print $1-$2}" + echo | awk "{printf \"%.3f\", $1-$2}" } _MESSAGE_FORMATTER () { - awk '{printf "| %-29s | %7.3f |\n",$1" "$2,$3}' + awk '{printf "| %-28s | %9s |\n",$1" "$2,$3}' } LOG_TABLE () { @@ -22,7 +22,7 @@ LOG_TABLE () { echo "Render Files $(_SUBSTRUCTION $time_render_finish $time_render_start)s" | _MESSAGE_FORMATTER echo "Save Database $(_SUBSTRUCTION $time_database_saved $time_render_finish)s" | _MESSAGE_FORMATTER echo "Total time $(_SUBSTRUCTION $time_database_saved $time_begin)s" | _MESSAGE_FORMATTER - echo "Memory Usage(RSS) $(echo | awk "{print $memory_usage/1024}")MB" | _MESSAGE_FORMATTER + echo "Memory Usage(RSS) $(echo | awk "{printf \"%.3f\", $memory_usage/1024}")MB" | _MESSAGE_FORMATTER } echo "============== Hexo Benchmark =============="