aboutsummaryrefslogtreecommitdiff
path: root/src/logoutputbuffer.h
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2014-07-16 16:37:41 +0200
committersapier <Sapier at GMX dot net>2014-07-16 16:37:41 +0200
commit9a016a6294f289e1687b9a4655ea3f02f2208201 (patch)
treefa86e42ef6d3a612a43574cac0e3a1c2900f5b70 /src/logoutputbuffer.h
parent65b8b524c02df853163fc1284a00a684a046d67c (diff)
downloadminetest-9a016a6294f289e1687b9a4655ea3f02f2208201.tar.gz
minetest-9a016a6294f289e1687b9a4655ea3f02f2208201.tar.bz2
minetest-9a016a6294f289e1687b9a4655ea3f02f2208201.zip
Fix flipped textures for drawtype "glasslike"
Diffstat (limited to 'src/logoutputbuffer.h')
0 files changed, 0 insertions, 0 deletions
a id='n113' href='#n113'>113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
-- Minetest: builtin/game/mod_profiling.lua

local mod_statistics = {}
mod_statistics.step_total = 0
mod_statistics.data = {}
mod_statistics.stats = {}
mod_statistics.stats["total"] = {
	min_us = math.huge,
	max_us = 0,
	avg_us = 0,
	min_per = 100,
	max_per = 100,
	avg_per = 100
}

local replacement_table = {
	"register_globalstep",
	"register_on_placenode",
	"register_on_dignode",
	"register_on_punchnode",
	"register_on_generated",
	"register_on_newplayer",
	"register_on_dieplayer",
	"register_on_respawnplayer",
	"register_on_prejoinplayer",
	"register_on_joinplayer",
	"register_on_leaveplayer",
	"register_on_cheat",
	"register_on_chat_message",
	"register_on_player_receive_fields",
	"register_on_mapgen_init",
	"register_on_craft",
	"register_craft_predict",
	"register_on_item_eat"
}

--------------------------------------------------------------------------------
function mod_statistics.log_time(type, modname, time_in_us)

	if modname == nil then
		modname = "builtin"
	end
	
	if mod_statistics.data[modname] == nil then
		mod_statistics.data[modname] = {}
	end
	
	if mod_statistics.data[modname][type] == nil then
		mod_statistics.data[modname][type] = 0
	end
	
	mod_statistics.data[modname][type] =
		mod_statistics.data[modname][type] + time_in_us
	mod_statistics.step_total = mod_statistics.step_total + time_in_us
end

--------------------------------------------------------------------------------
function mod_statistics.update_statistics(dtime)
	for modname,types in pairs(mod_statistics.data) do
		
		if mod_statistics.stats[modname] == nil then
			mod_statistics.stats[modname] = {
				min_us = math.huge,
				max_us = 0,
				avg_us = 0,
				min_per = 100,
				max_per = 0,
				avg_per = 0
			}
		end
		
		local modtime = 0
		for type,time in pairs(types) do
			modtime = modtime + time
			if mod_statistics.stats[modname].types == nil then
				mod_statistics.stats[modname].types = {}
			end
			if mod_statistics.stats[modname].types[type] == nil then
				mod_statistics.stats[modname].types[type] = {
					min_us = math.huge,
					max_us = 0,
					avg_us = 0,
					min_per = 100,
					max_per = 0,
					avg_per = 0
				}
			end
			
			local toupdate = mod_statistics.stats[modname].types[type]
			
			--update us values
			toupdate.min_us = math.min(time, toupdate.min_us)
			toupdate.max_us = math.max(time, toupdate.max_us)
			--TODO find better algorithm
			toupdate.avg_us = toupdate.avg_us * 0.99 + modtime * 0.01
				
			--update percentage values
			local cur_per = (time/mod_statistics.step_total) * 100
			toupdate.min_per = math.min(toupdate.min_per, cur_per)
				
			toupdate.max_per = math.max(toupdate.max_per, cur_per)
				
			--TODO find better algorithm
			toupdate.avg_per = toupdate.avg_per * 0.99 + cur_per * 0.01
			
			mod_statistics.data[modname][type] = 0
		end
		
		--per mod statistics
		--update us values
		mod_statistics.stats[modname].min_us =
			math.min(modtime, mod_statistics.stats[modname].min_us)
		mod_statistics.stats[modname].max_us =
			math.max(modtime, mod_statistics.stats[modname].max_us)
		--TODO find better algorithm
		mod_statistics.stats[modname].avg_us =
			mod_statistics.stats[modname].avg_us * 0.99 + modtime * 0.01
			
		--update percentage values
		local cur_per = (modtime/mod_statistics.step_total) * 100
		mod_statistics.stats[modname].min_per =
			math.min(mod_statistics.stats[modname].min_per, cur_per)
			
		mod_statistics.stats[modname].max_per =
			math.max(mod_statistics.stats[modname].max_per, cur_per)
			
		--TODO find better algorithm
		mod_statistics.stats[modname].avg_per =
			mod_statistics.stats[modname].avg_per * 0.99 + cur_per * 0.01
	end
	
	--update "total"
	mod_statistics.stats["total"].min_us =
		math.min(mod_statistics.step_total, mod_statistics.stats["total"].min_us)
	mod_statistics.stats["total"].max_us =
		math.max(mod_statistics.step_total, mod_statistics.stats["total"].max_us)
	--TODO find better algorithm
	mod_statistics.stats["total"].avg_us =
		mod_statistics.stats["total"].avg_us * 0.99 +
		mod_statistics.step_total * 0.01
	
	mod_statistics.step_total = 0
end

--------------------------------------------------------------------------------
local function build_callback(log_id, fct)
	return function( toregister )
		local modname = core.get_current_modname()
		
		fct(function(...)
			local starttime = core.get_us_time()
			-- note maximum 10 return values are supported unless someone finds
			-- a way to store a variable lenght return value list
			local r0, r1, r2, r3, r4, r5, r6, r7, r8, r9 = toregister(...)
			local delta = core.get_us_time() - starttime
			mod_statistics.log_time(log_id, modname, delta)
			return r0, r1, r2, r3, r4, r5, r6, r7, r8, r9
			end
		)
	end
end

--------------------------------------------------------------------------------
function profiling_print_log(cmd, filter)

	print("Filter:" .. dump(filter))

	core.log("action", "Values below show times/percentages per server step.")
	core.log("action", "Following suffixes are used for entities:")
	core.log("action", "\t#oa := on_activate, #os := on_step, #op := on_punch, #or := on_rightclick, #gs := get_staticdata")
	core.log("action",
		string.format("%16s | %25s | %10s | %10s | %10s | %9s | %9s | %9s",
		"modname", "type" , "min µs", "max µs", "avg µs", "min %", "max %", "avg %")
	)
	core.log("action",
		"-----------------+---------------------------+-----------+" ..
		"-----------+-----------+-----------+-----------+-----------")
	for modname,statistics in pairs(mod_statistics.stats) do
		if modname ~= "total" then
		
			if (filter == "") or (modname == filter) then
				if modname:len() > 16 then
					modname = "..." .. modname:sub(-13)
				end
			
				core.log("action",
					string.format("%16s | %25s | %9d | %9d | %9d | %9d | %9d | %9d",
					modname,
					" ",
					statistics.min_us,
					statistics.max_us,
					statistics.avg_us,
					statistics.min_per,
					statistics.max_per,
					statistics.avg_per)
				)
				if core.setting_getbool("detailed_profiling") then
					if statistics.types ~= nil then
						for type,typestats in pairs(statistics.types) do
						
							if type:len() > 25 then
								type = "..." .. type:sub(-22)
							end
						
							core.log("action",
								string.format(
								"%16s | %25s | %9d | %9d | %9d | %9d | %9d | %9d",
								" ",
								type,
								typestats.min_us,
								typestats.max_us,
								typestats.avg_us,
								typestats.min_per,
								typestats.max_per,
								typestats.avg_per)
							)
						end
					end
				end
			end
		end
	end
		core.log("action",
			"-----------------+---------------------------+-----------+" ..
			"-----------+-----------+-----------+-----------+-----------")
			
	if filter == "" then
		core.log("action",
			string.format("%16s | %25s | %9d | %9d | %9d | %9d | %9d | %9d",
			"total",
			" ",
			mod_statistics.stats["total"].min_us,
			mod_statistics.stats["total"].max_us,
			mod_statistics.stats["total"].avg_us,
			mod_statistics.stats["total"].min_per,
			mod_statistics.stats["total"].max_per,
			mod_statistics.stats["total"].avg_per)
		)
	end
	core.log("action", " ")
	
	return true
end