Skip to content

Commit

Permalink
Merge pull request #32 from tiennou/master
Browse files Browse the repository at this point in the history
Consolidate profiler changes
  • Loading branch information
admon84 authored Nov 3, 2024
2 parents 4014ef5 + 841487a commit e7ffe04
Show file tree
Hide file tree
Showing 11 changed files with 4,157 additions and 61 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false

[*.js]
trim_trailing_whitespace = true
insert_final_newline = true
47 changes: 41 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,21 +1,56 @@
{
"extends": "airbnb",
"globals": {
"Game": true,
"ConstructionSite": true,
"Creep": true,
"Deposit": true,
"Flag": true,
"Game": true,
"InterShardMemory": true,
"Memory": true,
"Mineral": true,
"Nuke": true,
"OwnedStructure": true,
"PathFinder": true,
"PowerCreep": true,
"RawMemory": true,
"Resource": true,
"Room": true,
"RoomObject": true,
"RoomPosition": true,
"RoomVisual": true,
"Ruin": true,
"Source": true,
"Spawn": true,
"Store": true,
"Structure": true,
"Flag": true,
"Memory": true,
"StructureContainer": true,
"StructureController": true,
"StructureExtension": true,
"StructureExtractor": true,
"StructureFactory": true,
"StructureInvaderCore": true,
"StructureKeeperLair": true,
"StructureLab": true,
"StructureLink": true,
"StructureNuker": true,
"StructureObserver": true,
"StructurePortal": true,
"StructurePowerBank": true,
"StructurePowerSpawn": true,
"StructureRampart": true,
"StructureRoad": true,
"StructureSpawn": true,
"StructureStorage": true,
"StructureTerminal": true,
"StructureTower": true,
"StructureWall": true,
"Tombstone": true
},
rules: {
"rules": {
"no-console": 0,
"arrow-body-style": 0,
"prefer-rest-params": 0,
"no-use-before-define": 0,
"strict": 0,
"strict": 0
}
}
21 changes: 21 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Node.js CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 10
- run: npm install
- run: npm test
- name: Coveralls GitHub Action
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 10.24.1
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ Game.profiler.profile(ticks, [functionFilter]);
Game.profiler.stream(ticks, [functionFilter]);
Game.profiler.email(ticks, [functionFilter]);
Game.profiler.background([functionFilter]);
Game.profiler.callgrind(ticks, [functionFilter]);

// Output current profile data.
Game.profiler.output([lineCount]);
Game.profiler.downloadCallgrind();

// Reset the profiler, disabling any profiling in the process.
Game.profiler.reset();
Expand All @@ -57,7 +59,11 @@ Game.profiler.restart();

`background` - This will run indefinitely, and will only output data when the `output` console command is run. Very useful for long running profiles with lots of function calls.

`output` - Print a report based on the current tick. The profiler will continue to operate normally. This is currently the only way to get data from the `background` profile.
`callgrind` - Will run for the given number of ticks, and will download a file in Callgrind format which can be viewed in KCachegrind program.

`output` - Print a report based on the current tick. The profiler will continue to operate normally.

`downloadCallgrind` - Download the callgrind report at the current tick. The profiler will continue to operate normally.

`reset` - Stops the profiler and resets its memory. This is currently the only way to stop a `background` profile.

Expand Down Expand Up @@ -123,6 +129,12 @@ Avg: 13.54 Total: 2707.90 Ticks: 200 Est. Bucket (20 limit): 1774

**Note:** Each function recorded here was part of a call stack with `Spawn.work` at the root.

## Example callgrind visualisation

![KCachegrind screenshot](callgrind.jpg)

**Note:** In callgrind format time will be saved in nanoseconds. `1 Screeps CPU unit = 1 ms = 1'000'000 ns`.

## Registering additional code

The profiler automatically registers many of the built in functions in Screeps, but not every player extends the provided prototypes. The profiler supports arbitrary registration of objects and functions as well, but takes a bit more work to setup.
Expand Down
Loading

0 comments on commit e7ffe04

Please sign in to comment.