Code Monkey home page Code Monkey logo

defold-metrics's Introduction

Defold Metrics

Calculate and display performance metrics in Defold games.

Installation

You can use Defold Metrics in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add:

https://github.com/britzl/defold-metrics/archive/master.zip

Or point to the ZIP file of a specific release.

Usage

  • In your game.project settings, go to Dependencies,and add https://github.com/britzl/defold-metrics/archive/master.zip.
  • In the outline in your scene, right-click and "Add Game Object File" and choose "/metrics/fps.go"
  • Change the position on the game object to ex 10, 20, 0 to make it visible.
  • If you also want to use the Lua memory counter, add the "/metrics/mem.go" in the same way, but on position 10, 40, 0.

Demo: https://britzl.github.io/Metrics/

FPS

The FPS counter uses socket.gettime() to get an accurate timestamp and calculates an average FPS based on a sequence of samples. The FPS counter can be used in several ways:

  1. Using fps.go() - Draw FPS counter at game object world position using draw text
  2. Using fps.script - Draw FPS counter at game object world position using draw text
  3. Using fps.lua - Draw FPS counter at specified position or get current FPS

fps.create(samples, format, position, color)

Create an instance of the FPS counter

PARAMETERS

  • samples (number) - Optional sample count. This is the number of samples required before the module will calculate FPS. Defaults to 60.
  • format (string) - Optional format to draw FPS in. Defaults to "FPS %.2f"
  • position (string) - Optional position to draw FPS at. Defaults to v3(10, 20, 0)
  • color (string) - Optional color to use when drawing FPS text. Defaults to v4(0,0,1,1)

RETURNS

  • instance (table) - An FPS counter instance

fps.update()

Call this once per frame. Once enough samples have been collected it is possible to call fps() to get the current FPS.

fps.fps()

Get the current FPS, based on collected samples.

RETURNS

  • fps (number) - The calculated FPS

fps.draw()

Draw fps count text using draw_debug_text.

Memory

The memory counter uses collectgarbage("count") to get the amount of Lua memory used. The memory counter can be used in several ways:

  1. Using mem.go() - Draw memory usage at game object world position using draw text
  2. Using mem.script - Draw memory usage at game object world position using draw text
  3. Using mem.lua - Draw memory usage at specified position or get current memory usage

mem.create(format, position, color)

Create an instance of the memory counter

PARAMETERS

  • format (string) - Optional format to draw memory usage in. Defaults to "MEM %dkb"
  • position (string) - Optional position to draw memory usage at. Defaults to v3(10, 20, 0)
  • color (string) - Optional color to use when drawing memory usage text. Defaults to v4(0,0,1,1)

RETURNS

  • instance (table) - A memory counter counter instance

mem.update()

Call this to get a new memory usage reading.

mem.mem()

Get the current memory usage, in kilobytes.

RETURNS

  • mem (number) - The Lua memory usage

mem.draw()

Draw memory usage text using draw_debug_text.

defold-metrics's People

Contributors

britzl avatar sandstedt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

defold-metrics's Issues

Not true FPS?

Just a warning the FPS won't be accurate because of the way update and dt works in the engine. Have to save and update system time instead.

Or is dt not used?

socket.gettime() is used nevermind then. ๐Ÿค 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.