Skip to content

Commit

Permalink
Merge pull request #3556 from SOZ-Faut-etre-Sub/feat/profiler-scope
Browse files Browse the repository at this point in the history
feat(profiler): add scope for profiler so we can have more information when profiling
  • Loading branch information
joelwurtz authored May 1, 2023
2 parents ee51a6f + f7ee7c9 commit a530fe3
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 20 deletions.
2 changes: 1 addition & 1 deletion resources/[soz]/soz-core/src/client/hud/hud.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class HudProvider {
public isCinematicCameraActive = false;

@Tick()
public async tick(): Promise<void> {
public async disableHudLoop(): Promise<void> {
// Basic components hide
HideHudComponentThisFrame(HudComponent.WantedStars);
HideHudComponentThisFrame(HudComponent.Cash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class LSMCDeathProvider {
private IsDead = false;

@Tick(10)
public async loop() {
public async deathLoop() {
if (this.playerService.isLoggedIn()) {
const playerPed = PlayerPedId();
if (IsEntityDead(playerPed)) {
Expand Down Expand Up @@ -265,7 +265,7 @@ export class LSMCDeathProvider {
}

@Tick(TickInterval.EVERY_FRAME)
public async controlLoop() {
public async controlDeathLoop() {
if (!this.IsDead) {
await wait(1000);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class TaxiProvider {
}

@Tick(2000)
public loop() {
public checkTaxiMissionService() {
this.taxiMissionService.update();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { Tick, TickInterval } from '../../core/decorators/tick';
import { ClientEvent } from '../../shared/event';
import { VehicleClass } from '../../shared/vehicle/vehicle';

const ALLOWED_AIR_CONTROL: VehicleClass[] = [
VehicleClass.Helicopters,
VehicleClass.Motorcycles,
VehicleClass.Cycles,
VehicleClass.Boats,
VehicleClass.Planes,
VehicleClass.Military,
];
const ALLOWED_AIR_CONTROL: Partial<Record<VehicleClass, true>> = {
[VehicleClass.Helicopters]: true,
[VehicleClass.Motorcycles]: true,
[VehicleClass.Cycles]: true,
[VehicleClass.Boats]: true,
[VehicleClass.Planes]: true,
[VehicleClass.Military]: true,
};

@Provider()
export class VehicleAirProvider {
Expand Down Expand Up @@ -69,7 +69,7 @@ export class VehicleAirProvider {

const vehicleClass = GetVehicleClass(vehicle);

if (ALLOWED_AIR_CONTROL.includes(vehicleClass)) {
if (ALLOWED_AIR_CONTROL[vehicleClass]) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class WeaponHolsterProvider {
}

@Tick(5)
public async loop() {
public async checkWeaponLoop() {
const ped = PlayerPedId();
const player = this.playerService.getPlayer();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { EventMetadata } from '../decorators/event';
import { Injectable } from '../decorators/injectable';
import { Inject, Injectable } from '../decorators/injectable';
import { Middleware, MiddlewareFactory } from './middleware';
import { ProfilerMiddlewareFactory } from './profiler.middleware';

@Injectable()
export class ChainMiddlewareEventClientFactory implements MiddlewareFactory {
@Inject(ProfilerMiddlewareFactory)
private profilerMiddlewareFactory: ProfilerMiddlewareFactory;

create(event: EventMetadata, next: Middleware): Middleware {
return next;
return this.profilerMiddlewareFactory.create(event, next);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Inject, Injectable } from '../decorators/injectable';
import { LogMiddlewareFactory } from './log.middleware';
import { MetricMiddlewareFactory } from './metric.middleware';
import { Middleware, MiddlewareFactory } from './middleware';
import { ProfilerMiddlewareFactory } from './profiler.middleware';
import { SourceMiddlewareFactory } from './source.middleware';

@Injectable()
Expand All @@ -16,10 +17,16 @@ export class ChainMiddlewareEventServerFactory implements MiddlewareFactory {
@Inject(SourceMiddlewareFactory)
private sourceMiddlewareFactory: SourceMiddlewareFactory;

@Inject(ProfilerMiddlewareFactory)
private profilerMiddlewareFactory: ProfilerMiddlewareFactory;

create(event: EventMetadata, next: Middleware): Middleware {
return this.logMiddlewareFactory.create(
event,
this.metricMiddlewareFactory.create(event, this.sourceMiddlewareFactory.create(event, next))
this.metricMiddlewareFactory.create(
event,
this.profilerMiddlewareFactory.create(event, this.sourceMiddlewareFactory.create(event, next))
)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Injectable } from '../decorators/injectable';
import { Inject, Injectable } from '../decorators/injectable';
import { TickMetadata } from '../decorators/tick';
import { Middleware, MiddlewareTickFactory } from './middleware';
import { ProfilerTickMiddlewareFactory } from './profiler.middleware';

@Injectable()
export class ChainMiddlewareTickClientFactory implements MiddlewareTickFactory {
@Inject(ProfilerTickMiddlewareFactory)
private profilerTickMiddlewareFactory: ProfilerTickMiddlewareFactory;

create(tick: TickMetadata, next: Middleware): Middleware {
return next;
return this.profilerTickMiddlewareFactory.create(tick, next);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import { Inject, Injectable } from '../decorators/injectable';
import { TickMetadata } from '../decorators/tick';
import { MetricTickMiddlewareFactory } from './metric.tick.middleware';
import { Middleware, MiddlewareTickFactory } from './middleware';
import { ProfilerTickMiddlewareFactory } from './profiler.middleware';

@Injectable()
export class ChainMiddlewareTickServerFactory implements MiddlewareTickFactory {
@Inject(MetricTickMiddlewareFactory)
private metricMiddlewareFactory: MetricTickMiddlewareFactory;

@Inject(ProfilerTickMiddlewareFactory)
private profilerTickMiddlewareFactory: ProfilerTickMiddlewareFactory;

create(tick: TickMetadata, next: Middleware): Middleware {
return this.metricMiddlewareFactory.create(tick, next);
return this.metricMiddlewareFactory.create(tick, this.profilerTickMiddlewareFactory.create(tick, next));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { EventMetadata } from '../decorators/event';
import { Injectable } from '../decorators/injectable';
import { TickMetadata } from '../decorators/tick';
import { Middleware, MiddlewareFactory, MiddlewareTickFactory } from './middleware';

@Injectable()
export class ProfilerMiddlewareFactory implements MiddlewareFactory {
public create(event: EventMetadata, next: Middleware): Middleware {
return async (...args): Promise<void> => {
ProfilerEnterScope(`[soz-core] event: ${event.name}`);

const promise = next(...args);

ProfilerExitScope();

return await promise;
};
}
}

@Injectable()
export class ProfilerTickMiddlewareFactory implements MiddlewareTickFactory {
public create(tick: TickMetadata, next: Middleware): Middleware {
return async (...args): Promise<void> => {
ProfilerEnterScope(`[soz-core] tick: ${tick.name} (${tick.interval}ms)`);

const promise = next(...args);

ProfilerExitScope();

return await promise;
};
}
}

0 comments on commit a530fe3

Please sign in to comment.