screepers / screeps-profiler Goto Github PK
View Code? Open in Web Editor NEWThis is a profiler designed for use in the game of screeps.
This is a profiler designed for use in the game of screeps.
I did a Game.profiler.profile(20), and then later did a Game.profiler.output() a few times. Basically, the tick counter on this output increases even though further profiling is not happening. This only affects the final summary line. Here is the summary line from two different Game.profiler.output() calls:
Avg: 9.13 Total: 246.43 Ticks: 27
Avg: 3.52 Total: 246.43 Ticks: 70
I can see that constructors have been blacklisted from profiling... however, I have a few classes that I would like to profile the constructor for. registerFN is not doing the trick, as it still gets blacklisted. How would I go about registering these constructors for profiling?
The profiler should be able to profile a certain section of code.
Currently you would have to wrap it into a function and call that:
// some code
profiler.registerFN(() => {
// some complex code that should get profiled
}, 'mySection') ();
// some code
Because you can't just drop-in section profiling I suggest one of the following alternatives:
// some code
const end = profiler.start('mySection');
// some complex code that should get profiled
end(); // maybe even return profiling data for this section
// some code
or
// some code
profiler.start('mySection');
// some complex code that should get profiled
profiler.end('mySection'); // maybe even return profiling data for this section
// some code
Once this is implemented it should probably also be used internally to wrap functions.
When I use the profiler it seems to go through phases where for a few ticks, it crashes with an AlreadyWrappedError. I added a log statement, and it turns out its complaining about Room.toString. Then for subsequent ticks it will not through this error.
function already wrapped: Room.toString
[12:42:13 PM]screeps-profiler:86
if (originalFunction.profilerWrapped) { console.log("function already wrapped:", name); throw new AlreadyWrappedError(); }
^
Error
at new AlreadyWrappedError (screeps-profiler:10:18)
at wrapFunction (screeps-profiler:86:97)
at profileFunction (screeps-profiler:179:10)
at Object.getOwnPropertyNames.forEach.functionName (screeps-profiler:165:34)
at Array.forEach (native)
at profileObjectFunctions (screeps-profiler:124:44)
at Profiler.prototypes.forEach.proto (screeps-profiler:117:5)
at Array.forEach (native)
at hookUpPrototypes (screeps-profiler:116:23)
How to read this?
Looking at column names, I assume that calls
is the number of function calls during profiling period
In what units is time measured? seconds, ms, ns?
How are those averages calculated? If you look at screenshot, it shows 887114 of calls for lookFor
, but total average is 32.18, what does it mean.
I was looking for some ways of estimating CPU\RAM usage running code in training room before buying game license, how do I interpolate data from profiler into approximate usage?
class Yogi {
stealPicnicBasket() {
// something the ranger wouldn't like.
}
}
profiler.profileObject(Yogi.prototype, 'Yogi');
^ I'd expect this to properly profile the object, but it seems that es6 classes don't directly assign fields to the prototype, so you can't see them with Object.keys(Yogi.prototype)
. Instead you'd have to do Object.getOwnProperties(Yogi.prototype)
.
This should also probably result in a new api... registerClass
Report is an object that can be created (and optionally saved) from the current profiling data.
It can be consumed by output functions (stream, email, custom).
Long term I can imagine some utility functions to compare Reports.
It's currently not possible to profile Memory deserialization cost, because the Profiler accesses (and therefor deserializes) Memory when checking if it should be profiling.
This can be solved in one of the following ways:
Just in case is helpful for you, this is what i get when i do Game.profiler.reset()
screeps-profiler:214
if (currentLength + line.length + 1 < outputLengthLimit) {
^
TypeError: Cannot read property 'length' of undefined
at Object.output (screeps-profiler:214:31)
at Object.printProfile (screeps-profiler:184:26)
at Object.report (screeps-profiler:282:16)
at Object.endTick (screeps-profiler:276:16)
at Object.wrap (screeps-profiler:326:16)
at Object.module.exports.loop (main:14:16)
at __mainLoop:1:52
at sigintHandlersWrap (vm.js:32:31)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.