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

suppport class static method for profiling #10

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions Profiler/Profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ export function init(): Profiler {
delete Memory.profiler.start;
return "Profiler stopped";
},

toString() {
return "Profiler.start() - Starts the profiler\n" +
"Profiler.stop() - Stops/Pauses the profiler\n" +
"Profiler.status() - Returns whether is profiler is currently running or not\n" +
"Profiler.output() - Pretty-prints the collected profiler data to the console\n" +
this.status();
},
return "Profiler.start() - Starts the profiler\n" +
"Profiler.stop() - Stops/Pauses the profiler\n" +
"Profiler.status() - Returns whether is profiler is currently running or not\n" +
"Profiler.output() - Pretty-prints the collected profiler data to the console\n" +
this.status();
},
};

return cli;
Expand Down Expand Up @@ -105,11 +105,23 @@ export function profile(
const ctor = target as any;
if (!ctor.prototype) { return; }

const standardClassProps = Object.getOwnPropertyNames(class _ { });

const isOwnStaticMember = (propName: string) => (
!standardClassProps.includes(propName)
);

const staticMembers = Object.getOwnPropertyNames(ctor).filter(isOwnStaticMember);

const className = ctor.name;

staticMembers.forEach((k) => {
wrapFunction(ctor, k, className);
});

Reflect.ownKeys(ctor.prototype).forEach((k) => {
wrapFunction(ctor.prototype, k, className);
});

}

function isEnabled(): boolean {
Expand Down Expand Up @@ -141,7 +153,6 @@ function outputProfilerData() {
totalTicks += Game.time - Memory.profiler.start;
}

///////
// Process data
let totalCpu = 0; // running count of average total CPU use per tick
let calls: number;
Expand Down Expand Up @@ -205,3 +216,4 @@ function outputProfilerData() {
// }
// });
// }