Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static functions not displaied #6

Open
juncraul opened this issue Feb 17, 2019 · 8 comments
Open

Static functions not displaied #6

juncraul opened this issue Feb 17, 2019 · 8 comments

Comments

@juncraul
Copy link

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.

@semperrabbit
Copy link
Member

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');

@juncraul
Copy link
Author

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?

@semperrabbit
Copy link
Member

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();

@juncraul
Copy link
Author

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.

@pyrodogg
Copy link
Member

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
  }
}

@M1kep
Copy link

M1kep commented Nov 18, 2019

@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.

@pyrodogg
Copy link
Member

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

@ilan-schemoul
Copy link

ilan-schemoul commented Oct 24, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants