Noir
  • πŸšΆβ€β™‚οΈIntro
  • πŸ“Tutorials
    • πŸŽ“Starting Noir
    • πŸ“–Libraries
    • πŸ–₯️Services
    • ❔Libraries VS Services
    • πŸ’¬Callbacks
    • πŸ’₯Classes
    • πŸ”ŽDebugging
  • πŸ“šExamples
  • β˜„οΈAPI Reference
    • Bootstrapper
    • Built-Ins
      • Classes
        • AITarget
        • Body
        • Command
        • Connection
        • Event
        • HTTPRequest
        • HTTPResponse
        • Library
        • Message
        • Object
        • Player
        • Service
        • Task
        • TickIterationProcess
        • Tracker
        • Vehicle
        • Widgets
          • MapLabelWidget
          • MapLineWidget
          • MapObjectWidget
          • PopupWidget
          • ScreenPopupWidget
          • Widget
      • Libraries
        • Base64
        • Dataclasses
        • Deprecation
        • Events
        • HTTP
        • JSON
        • Logging
        • Matrix
        • Number
        • String
        • Table
      • Services
        • CommandService
        • GameSettingsService
        • HTTPService
        • MessageService
        • NotificationService
        • ObjectService
        • PlayerService
        • TaskService
        • TPSService
        • UIService
        • VehicleService
    • Callbacks
    • Class
    • Classes
    • Debugging
    • Definition
    • Libraries
    • Noir
    • Services
    • TypeChecking
Powered by GitBook
On this page
  • Enabling Debug
  • Trackers
  • Viewing All Stats
  • Tracking In Bulk
  • Error Detection
  • And More...
Edit on GitHub
  1. Tutorials

Debugging

This page will go over Noir's debugging system which can be used to figure out where you can optimize your code. You can track the statistics and performance of individual functions, services, etc.

Enabling Debug

Debug is disabled by default, so to enable debug, set Noir.Debugging.Enabledto true.

main.lua
Noir.Started:Once(function()
    -- ...
end)

Noir.Debugging.Enabled = true

Trackers

A tracker represents a function that is being tracked by Noir's debugging suite. You can track a function easily like so:

debugging.lua
function doTheFoo()
    print("Hello world!")
end

local tracker = Noir.Debugging:TrackFunction("doTheFoo", doTheFoo)

You can then overwrite the function with the version that comes with debugging like so:

debugging.lua
doTheFoo = tracker:Mount()

This is done automatically when using :TrackAll()and :TrackService().

Now, when you call a tracked function that has been overwritten with :Mount(), statistics like how long it took to execute the function, the amount of times the function has been called and the average execution time are gathered and saved within the tracker. You can then access the statistics at any point via the tracker's attributes.

debugging.lua
doTheFoo()

tracker:GetCallCount() -- 1
tracker:GetAverageExecutionTime() -- 0.0 (in ms)
tracker:GetLastExecutionTime() -- latest execution time, 0.0 (also in ms)

Viewing All Stats

The best part about the debugging is being able to sort all tracked functions based on how well they perform or how recently they've been called, and then show you the stats to determine where you should optimize. You can do this with a single method call too.

debugging.lua
Noir.Debugging:ShowLeastPerformantTracked()

This will print out all tracked functions and their statistics in order of performance (least performant being shown first).

If you need the tracked functions sorted and returned, you can use the Getvariant instead.

debugging.lua
local trackers = Noir.Debugging:GetLeastPerformantTracked()

Tracking In Bulk

Tracking every function one-by-one is tedious however, so instead if your functions are in a table, or better yet, a service, you can track them like so:

Tables

debugging.lua
functions = {
    foo = function()
        print("foo")
    end,
    
    bar = function()
        print("bar")
    end
}

Noir.Debugging:TrackAll("functions", functions)

Services

debugging.lua
MyService = Noir.Services:CreateService("MyService")

function MyService:Foo()
    print("foo")
end

Noir.Debugging:TrackService(MyService) -- no need for a name argument, the service comes with a name

Error Detection

And More...

See the API Reference for all available methods to mess with.

PreviousClassesNextExamples

Last updated 1 month ago

Unfortunately, Noir's debugging tools does not allow you to detect errors that well. It is recommended to use instead as it detects errors and provides extremely accurate traceback so you can see exactly where your code errored.

SSSWTool
πŸ“
πŸ”Ž
Page cover image