Skip to content

Commit

Permalink
fix(getCpuStatsByProcess): fix regex for CPU stats (#181)
Browse files Browse the repository at this point in the history
* fix(getCpuStatsByProcess): fix regex for CPU stats

* chore: fix ci for forked repo

---------

Co-authored-by: almouro <contact@almouro.com>
  • Loading branch information
Lokizjj29 and Almouro committed Dec 23, 2023
1 parent 9382ca5 commit b4d5de6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
# This actually doesn't work from a forked repo so ignoring for now
# with:
# ref: ${{ github.event.pull_request.head.ref }}
- name: Use Node.js
uses: actions/setup-node@v3
with:
Expand All @@ -25,9 +26,10 @@ jobs:
run: yarn
- name: Run tests
run: yarn test
- name: Push yarn.lock update
run: |
git config --global user.email "bam.flashlight@gmail.com"
git config --global user.name "flashlight-bot"
git add yarn.lock && git diff --staged --quiet || git commit -m "chore: update yarn.lock"
git push
# This actually doesn't work from a forked repo so ignoring for now
# - name: Push yarn.lock update
# run: |
# git config --global user.email "bam.flashlight@gmail.com"
# git config --global user.name "flashlight-bot"
# git add yarn.lock && git diff --staged --quiet || git commit -m "chore: update yarn.lock"
# git push
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,22 @@ describe("getCpuStatsByProcess", () => {
]
`);
});

it("handles AWCN Worker(M)1 process name", () => {
expect(
processOutput(
`16360 (AWCN Worker(M)1) S 372 372 0 0 -1 1077936192 70 0 3 0 0 0 0 0 20 0 35 0 58748 16236625920 43973 18446744073709551615 1 1 0 0 0 0 4608 1 1073775868 0 0 0 -1 2 0 0 0 0 0 0 0 0 0 0 0 0 0`,
"1234"
)
).toMatchInlineSnapshot(`
[
{
"cpuNumber": "2",
"processId": "16360",
"processName": "AWCN Worker(M)1",
"totalCpuTime": 0,
},
]
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const processOutput = (output: string, pid: string): ProcessStat[] => {
.split(/\r\n|\n|\r/)
.filter(Boolean)
.map((stats) => {
const match = stats.match(/^(\d+) \(([^)]*)\) (.*)/);
const match = stats.match(/^(\d+) \((.*)\) (.*)/);
if (!match) {
throw new Error(`Invalid line: ${stats}`);
}
Expand Down

0 comments on commit b4d5de6

Please sign in to comment.