screepers / screeps-profiler

This is a profiler designed for use in the game of screeps.
192 stars 41 forks source link

AlreadyWrappedError: Room.toString #27

Open wtfrank opened 7 years ago

wtfrank commented 7 years ago

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)
gdborton commented 7 years ago

This is basically happening because you're attempting to wrap something that's already being wrapped... It was added as a convenience function to prevent you from double wrapping functions and inflating their numbers.

This is only a bug if it is happening when you aren't calling any of the register functions manually.

gdborton commented 7 years ago

@wtfrank are you getting this without calling any of the .registerX functions?

wtfrank commented 7 years ago

No I am calling some registerX functions (on functions and objects).

The reason why I suspected it might not be an issue with the way I was using the profiler is because I added error logging and it was complaining about a core function - Room.toString - rather than a function or object I was attempting to instrument.

This error mainly seems to occur when I'm pushing the CPU limit. Perhaps this means that it's caused by something that doesn't get run when my bot gets terminated.

gdborton commented 7 years ago

Do you know if you're registering anything that might be wrapping Room.toString()?

wtfrank commented 7 years ago

I'm not wrapping Room.toString() and it is definitely associated with running out of CPU.

I implemented a spawn governor that stopped spawning creeps if my average cpu usage was getting too high, and didn't see this error for ages. Then on Thursday after the deployment of the shards I ran out of CPU and again today because of a non-terminating loop bug in my code, and I started seeing this error message again for a while after the cpu ran out.

shibdib commented 6 years ago

I'm encountering this issue as well. The only time toString occurs in my project is the 2 times it's used in the profiler

dcolclazier commented 6 years ago

I'm also encountering this issue, simply by installing the profiler w/ npm, installing @types/ for the profiler, then adding 'import * as profiler from "screeps-profiler"' and calling 'profiler.enable()' before the main loop, as well as wrapping the main loop as follows = export const loop = profiler.wrap(mainloop). Those are the only interactions I have with the profiler, and I'm getting the toString already wrapped error.