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

Static functions not displaied

Open juncraul opened this issue 6 years ago • 8 comments

Hello, First of all, thank you for this profiler. It all works fine with the exception of static functions. I had a class with static functions but only after I converted them to non-static functions, they started to appear in the log.

juncraul avatar Feb 17 '19 01:02 juncraul

That is how the profiler operates, even in vanilla JS. it only loops through the prototype. any static functions need to be registered individually: SomeClass.someFunc = profiler.registerFN(SomeClass.someFunc, 'SomeClass.someFunc');

semperrabbit avatar Feb 17 '19 03:02 semperrabbit

Thank for clarification. Where would I put that line, I believe in the init function of the Profiler? And registerFn does not exists in this context, did you meant something else by any chance?

juncraul avatar Feb 17 '19 10:02 juncraul

I meant this... https://github.com/screepers/screeps-profiler/blob/master/screeps-profiler.js#L171-L180. if that is unavailable, then i suppose yall are using a different version. I would recommend including the original if youre having trouble with it. the readme's examples section has an example of it in the very bottom. and you would call it before you profiler.enable();

semperrabbit avatar Feb 17 '19 15:02 semperrabbit

I did not install the screeps-profiler module. I only installed and followed the instructions from screeps-typescript-profiler, didn't expect would need the js variant as well. I thought this would be an alternative to the js variant.

juncraul avatar Feb 17 '19 17:02 juncraul

It seems like it's possible to get the static members from a class, so it seems they could also be picked up dynamically if the decorator is used on the class. https://stackoverflow.com/questions/33069692/getting-a-list-of-statics-on-an-es6-class

Is it intentional to exclude them? If there isn't a desire not include them by default, it could be made conditional.

@profile({includeStatic:true})
class MyClass {
  public static doStuff: void {
    // this would be profiled
  }
}
@profile
class MyClass {
  public static doStuff: void {
    // current behavior, not profiled
  }
}

pyrodogg avatar Nov 10 '19 19:11 pyrodogg

@pyrodogg How hard would that be to add? Pretty much all of my code is static methods which makes this not so useful and I'd really love to be able to use it.

M1kep avatar Nov 18 '19 00:11 M1kep

I'll look at a PR early this week so it can be tested.

pyrodogg avatar Nov 18 '19 05:11 pyrodogg

See the PR #10 You can of course just clone my repo until this PR is approved

ilan-schemoul avatar Oct 24 '22 10:10 ilan-schemoul