From f179568e1d6b9cd2a6e7babde2ec36f75e4ba7f7 Mon Sep 17 00:00:00 2001 From: Mykhailo Bykhovtsev Date: Fri, 12 Oct 2018 07:46:19 -0700 Subject: [PATCH] Port Rust-g DLL and use it for logging (#5394) --- .travis.yml | 11 +++++++- TGS3.json | 3 ++- code/_helpers/logging.dm | 23 ++++++++++++++-- code/world.dm | 7 ++--- html/changelogs/Sindorman-logging.yml | 37 ++++++++++++++++++++++++++ rust_g.dll | Bin 0 -> 1159168 bytes scripts/rust_g.sh | 19 +++++++++++++ 7 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 html/changelogs/Sindorman-logging.yml create mode 100644 rust_g.dll create mode 100644 scripts/rust_g.sh diff --git a/.travis.yml b/.travis.yml index 9eeff2acda9..54773e6fbd7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ env: MACRO_COUNT=77 FLYWAY_BUILD="5.1.4" NODE_VERSION=10 + RUST_G_VERSION="0.4.1" matrix: - USE_MAP=aurora - USE_MAP=runtime @@ -18,6 +19,7 @@ cache: - $HOME/BYOND-${BYOND_MAJOR}.${BYOND_MINOR} - $HOME/flyway-${FLYWAY_BUILD} - vueui/dist + - $HOME/rust_g-${RUST_G_VERSION} addons: mariadb: '10.1' @@ -26,6 +28,9 @@ addons: - libc6-i386 - libgcc1:i386 - libstdc++6:i386 + - libssl-dev:i386 + - pkg-config:i386 + - gcc-multilib node_js: - "10" @@ -38,8 +43,10 @@ install: - ./install-byond.sh - chmod +x ./install-flyway.sh - ./install-flyway.sh - - export LD_LIBRARY_PATH=./:$LD_LIBRARY_PATH + - export LD_LIBRARY_PATH=./:$HOME/rust_g-$RUST_G_VERSION:$LD_LIBRARY_PATH - shopt -s globstar + - chmod +x ./scripts/rust_g.sh + - ./scripts/rust_g.sh stages: - code check @@ -63,6 +70,8 @@ jobs: install: - chmod +x ./vueui/install - ./vueui/install + - chmod +x ./scripts/rust_g.sh + - ./scripts/rust_g.sh script: - (! grep 'step_[xy]' maps/**/*.dmm) - (! find nano/templates/ -type f -exec md5sum {} + | sort | uniq -D -w 32 | grep nano) diff --git a/TGS3.json b/TGS3.json index 0a39b575898..fb40fffb209 100644 --- a/TGS3.json +++ b/TGS3.json @@ -17,6 +17,7 @@ "data" ], "dlls": [ - "libmysql.dll" + "libmysql.dll", + "rust_g.dll" ] } diff --git a/code/_helpers/logging.dm b/code/_helpers/logging.dm index 49463c32764..3253c6c11e5 100644 --- a/code/_helpers/logging.dm +++ b/code/_helpers/logging.dm @@ -1,5 +1,6 @@ //print an error message to world.log - +#define RUST_G "rust_g" // Using Rust g dll to log faster with less CPU usage. +#define WRITE_LOG(log, text) call(RUST_G, "log_write")(log, text) // On Linux/Unix systems the line endings are LF, on windows it's CRLF, admins that don't use notepad++ // will get logs that are one big line if the system is Linux and they are using notepad. This solves it by adding CR to every line ending @@ -15,9 +16,24 @@ /var/global/log_end = world.system_type == UNIX ? ascii2text(13) : "" +// logging.dm +/proc/log_startup() + var/static/already_logged = FALSE + if (!already_logged) + WRITE_LOG(diary, "[log_end]\n[log_end]\nStarting up. (ID: [game_id]) [time2text(world.timeofday, "hh:mm.ss")][log_end]\n---------------------[log_end]") + already_logged = TRUE + else + crash_with("log_startup() was called more then once") + +/proc/log_topic(T, addr, master, key, var/list/queryparams) + WRITE_LOG(diary, "TOPIC: \"[T]\", from:[addr], master:[master], key:[key], auth:[queryparams["auth"] ? queryparams["auth"] : "null"] [log_end]") + /proc/error(msg) world.log << "## ERROR: [msg][log_end]" +/proc/shutdown_logging() + call(RUST_G, "log_close_all")() + #define WARNING(MSG) warning("[MSG] in [__FILE__] at line [__LINE__] src: [src] usr: [usr].") //print a warning message to world.log /proc/warning(msg) @@ -28,7 +44,7 @@ world.log << "## TESTING: [msg][log_end]" /proc/game_log(category, text) - diary << "\[[time_stamp()]] [game_id] [category]: [text][log_end]" + WRITE_LOG(diary, "\[[time_stamp()]] [game_id] [category]: [text][log_end]") /proc/log_admin(text,level=SEVERITY_NOTICE,ckey="",admin_key="",ckey_target="") admin_log.Add(text) @@ -260,3 +276,6 @@ /proc/key_name_admin(var/whom, var/include_name = 1) return key_name(whom, 1, include_name, 1) + +#undef RUST_G +#undef WRITE_LOG \ No newline at end of file diff --git a/code/world.dm b/code/world.dm index 9a172f41a81..53582399fb2 100644 --- a/code/world.dm +++ b/code/world.dm @@ -63,8 +63,8 @@ var/global/datum/global_init/init = new () //logs diary_date_string = time2text(world.realtime, "YYYY/MM-Month/DD-Day") href_logfile = file("data/logs/[diary_date_string] hrefs.htm") - diary = file("data/logs/[diary_date_string].log") - diary << "[log_end]\n[log_end]\nStarting up. (ID: [game_id]) [time2text(world.timeofday, "hh:mm.ss")][log_end]\n---------------------[log_end]" + diary = "data/logs/[diary_date_string].log" + log_startup() changelog_hash = md5('html/changelog.html') //used for telling if the changelog has changed recently if(config.log_runtime) @@ -115,7 +115,7 @@ var/list/world_api_rate_limit = list() queryparams = list() log_debug("API: Request Received - from:[addr], master:[master], key:[key]") - diary << "TOPIC: \"[T]\", from:[addr], master:[master], key:[key], auth:[queryparams["auth"] ? queryparams["auth"] : "null"] [log_end]" + log_topic(T, addr, master, key, queryparams) // TGS topic hook. Returns if successful, expects old-style serialization. var/tgs_topic_return = TgsTopic(T) @@ -192,6 +192,7 @@ var/list/world_api_rate_limit = list() world.TgsReboot() Master.Shutdown() + shutdown_logging() if(config.server) //if you set a server location in config.txt, it sends you there instead of trying to reconnect to the same world address. -- NeoFite for(var/client/C in clients) diff --git a/html/changelogs/Sindorman-logging.yml b/html/changelogs/Sindorman-logging.yml new file mode 100644 index 00000000000..43e1bf21245 --- /dev/null +++ b/html/changelogs/Sindorman-logging.yml @@ -0,0 +1,37 @@ +################################ +# Example Changelog File +# +# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb. +# +# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.) +# When it is, any changes listed below will disappear. +# +# Valid Prefixes: +# bugfix +# wip (For works in progress) +# tweak +# soundadd +# sounddel +# rscadd (general adding of nice things) +# rscdel (general deleting of nice things) +# imageadd +# imagedel +# maptweak +# spellcheck (typo fixes) +# experiment +# balance +################################# + +# Your name. +author: PoZe + +# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again. +delete-after: True + +# Any changes you've made. See valid prefix list above. +# INDENT WITH TWO SPACES. NOT TABS. SPACES. +# SCREW THIS UP AND IT WON'T WORK. +# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries. +# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog. +changes: + - tweak: "Logging now is using fast RUST DLL which will reduce CPU usage and reduce lag during high player count rounds with bunch of logs." diff --git a/rust_g.dll b/rust_g.dll new file mode 100644 index 0000000000000000000000000000000000000000..ec072b01b00ebde836724c789b867e2fa62c4f37 GIT binary patch literal 1159168 zcmeFae|%KM^*_9uEM&ojyU}1{jS_9Fps0zWhMH=C>=J~84UhyCkXFQ)T8p>~s3dOK zY{=wtF}7fBOD$GxsiiGez=(iZz-&;eQF&@qS_5jGHM9k_3h2jt-{;J|`y&KvKi@vD z=btC9SN7idanGDNbLPyMGiPSXZfv!s+iW%m{`>lDwl+NJub6+o{AZNiW*a_o+i=_F zA%8lr%|7){=gq9S{qEd_i+*t1qVIe^_m=P6dFK!Ox!=7tcTwQZ+}rQWEtxhW_xnGX zf9s{gh7HX#LB}3k^u_OvWtTp!KYc!}yuK@i{!N@V)iB4IKXZ#y{YB zE%I&V=UE%K@-utm4o*L3<4!z(cjTPk-Gb-+zs=tGIG$%dn7#2lj?eksH#nTLaU(y^ z<>&Ob?1PE}){$7Y*qA7s1o+MnHI<>|4Vf8J^K;X`eW!)>-gqN2?<<};Vg=Elo9 z#L*kQr`c?SDTF`kX|tWKh>o~4TQMk!jFdP2RKcDn-L{S2vDsFhk!f2;$*1~TmuYLB zW3%<#@3zexAkVs>+m?;^LOhF;(}8CY_?_zSQva<>{Yc!o9Q7gmsIJ5;Nq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