screeps-profiler icon indicating copy to clipboard operation
screeps-profiler copied to clipboard

AlreadyWrappedError: Room.toString

Open wtfrank opened this issue 8 years ago • 7 comments

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)

wtfrank avatar Jul 22 '17 11:07 wtfrank

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 avatar Jul 26 '17 00:07 gdborton

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

gdborton avatar Jul 28 '17 20:07 gdborton

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.

wtfrank avatar Jul 28 '17 20:07 wtfrank

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

gdborton avatar Jul 28 '17 21:07 gdborton

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.

wtfrank avatar Aug 06 '17 23:08 wtfrank

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

shibdib avatar Feb 24 '18 06:02 shibdib

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.

dcolclazier avatar Sep 03 '18 01:09 dcolclazier