AccurateTime
This library will fix the shortfalls with debugprofilestart() and debugprofilestop() with the goal of providing a conflict-free way for addons to get accurate timing information. A common use-case for this would be for timing coroutines in order to limit the amount of processing that's done, or to do something in the "background" without using up too much CPU time.
Manually Installing
- Download the latest version.
- Rename the extracted folder to "!AccurateTime" (add the '!' to the front).
- Place the "!AccurateTime" folder in your World of Warcraft/Interface/Addons/ folder just as you would for a normal addon.
Including AccurateTime
AccurateTime is designed to be run as a standalone addon. It should be distributed accordingly. You may run it as part of your addon instead, but do so at your own risk.
If you're using wowace/curseforge repositories:
- Add an external pointing to svn://svn.wowace.com/wow/accuratetime/mainline/trunk in the .pkgmeta file.
- Add a move-folders in the .pkgmeta file. See the example below.
- Set up a dependency on !AccurateTime in your .toc file (optional). Don't forget the '!' from the front of the name.
Example .pkgmeta:
externals: AccurateTime: url: svn://svn.wowace.com/wow/accuratetime/mainline/trunk tag: latest move-folders: <YOUR_ADDON>/AccurateTime: "!AccurateTime"
Otherwise
- Download the latest version.
- Rename the extracted folder to "!AccurateTime" (add the '!' to the front).
- Ensure the !AccurateTime folder is at the same level as your top-most addon folder (one level above your .toc file).
Usage
If you're already using debugprofilestop() then you likely don't have to change anything to take advantage of the increased accuracy provided by this library. If you are currently using debugprofilestart(), you should remove all calls to debugprofilestart() and instead calculate time intervals by taking the difference of two debugprofilestop() calls. This will ensure you're getting the most accurate time values, and avoid conflicts with others who are still using debugprofilestart().
If AccurateTime is loaded, it requires no additional initialization or setup. AccurateTime does not use LibStub. In addition to replacing debugprofilestart() and debugprofilestop(), this library provides some APIs of its own to allow simple millisecond-level time keeping.
NOTE: All time values are in milliseconds, and represented using floating point numbers.
AccurateTime:GetAbsTime()
This function will return the current absolute time (since AccurateTime was loaded). This is equivalent to calling debugprofilestop() if debugprofilestart() has never been called (except on-load by AccurateTime). However, this also includes any detected error from somebody else calling the original debugprofilestart() function.
returns
The current absolute time in milliseconds.
AccurateTime:StartTimer([key])
Starts a timer. The timer is designated by the optional key. If no key is specified, a unique key will be created (as a table reference).
Parameters
- key
- Optional key used to reference your timer. If none is passed, a unique key will be created (and returned).
returns
The key used for the timer (created if none is passed, or passed through if one is).
AccurateTime:GetTimer(key[, silent])
Gets the current value of the timer. This is the number of milliseconds since it was started. The timer will remain running after this function is called.
Parameters
- key
- The key which was returned from AccurateTime:StartTimer().
- silent
- Optional parameter which causes this function to silently fail and return nil if the timer does not exist (will assert otherwise).
returns
The amount of time since the timer was started or nil if silent is true and the timer does not exist.
AccurateTime:StopTimer(key)
Stops a timer. This will return the final value of the timer (the number of milliseconds since the timer was started). This will also destroy the timer. You are then free to re-use the key for a new timer if you wish.
Parameters
- key
- The key which was returned from AccurateTime:StartTimer().
returns
The amount of time since the timer was started.
Comments