Skip to content

Commit ac618fc

Browse files
legendecasnodejs-github-bot
authored andcommitted
tools: add perfetto updater
PR-URL: #62397 Refs: nodejs/diagnostics#654 Refs: https://issues.chromium.org/issues/457135433 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent ec45b95 commit ac618fc

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

doc/contributing/maintaining/maintaining-dependencies.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This a list of all the dependencies:
2828
* [ngtcp2][]
2929
* [npm][]
3030
* [openssl][]
31+
* [perfetto][]
3132
* [postject][]
3233
* [simdjson][]
3334
* [sqlite][]
@@ -353,6 +354,11 @@ the main openssl/openssl releases with the addition of APIs to support
353354
the QUIC protocol.
354355
See [maintaining-openssl][] for more information.
355356

357+
### perfetto
358+
359+
The [perfetto](https://github.com/google/perfetto) dependency is used to
360+
generate performance traces for Node.js and V8.
361+
356362
### postject
357363

358364
The [postject](https://github.com/nodejs/postject) dependency is used for the
@@ -427,6 +433,7 @@ according to [RFC 8878](https://datatracker.ietf.org/doc/html/rfc8878).
427433
[ngtcp2]: #ngtcp2
428434
[npm]: #npm
429435
[openssl]: #openssl
436+
[perfetto]: #perfetto
430437
[postject]: #postject
431438
[simdjson]: #simdjson
432439
[sqlite]: #sqlite
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/sh
2+
set -e
3+
# Shell script to update perfetto in the source tree to specific version
4+
5+
BASE_DIR=$(cd "$(dirname "$0")/../.." && pwd)
6+
DEPS_DIR="$BASE_DIR/deps"
7+
8+
[ -z "$NODE" ] && NODE="$BASE_DIR/out/Release/node"
9+
[ -x "$NODE" ] || NODE=$(command -v node)
10+
11+
# shellcheck disable=SC1091
12+
. "$BASE_DIR/tools/dep_updaters/utils.sh"
13+
14+
NEW_VERSION="$("$NODE" --input-type=module <<'EOF'
15+
const res = await fetch('https://api.github.com/repos/google/perfetto/releases/latest',
16+
process.env.GITHUB_TOKEN && {
17+
headers: {
18+
"Authorization": `Bearer ${process.env.GITHUB_TOKEN}`
19+
},
20+
});
21+
if (!res.ok) throw new Error(`FetchError: ${res.status} ${res.statusText}`, { cause: res });
22+
const { tag_name } = await res.json();
23+
console.log(tag_name.replace('v', ''));
24+
EOF
25+
)"
26+
27+
CURRENT_VERSION=$(cat ./deps/perfetto/VERSION)
28+
29+
# This function exit with 0 if new version and current version are the same
30+
compare_dependency_version "perfetto" "$NEW_VERSION" "$CURRENT_VERSION"
31+
32+
echo "Making temporary workspace"
33+
34+
WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp')
35+
36+
cleanup () {
37+
EXIT_CODE=$?
38+
[ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE"
39+
exit $EXIT_CODE
40+
}
41+
42+
trap cleanup INT TERM EXIT
43+
44+
PERFETTO_REF="v$NEW_VERSION"
45+
PERFETTO_SDK_ZIP="perfetto-cpp-sdk-src.zip"
46+
47+
cd "$WORKSPACE"
48+
49+
echo "Fetching perfetto sdk archive"
50+
curl -sL -o "$PERFETTO_SDK_ZIP" "https://github.com/google/perfetto/releases/download/$PERFETTO_REF/$PERFETTO_SDK_ZIP"
51+
52+
echo "Unpacking archive"
53+
mkdir -p perfetto/sdk
54+
unzip -d perfetto/sdk "$PERFETTO_SDK_ZIP"
55+
rm "$PERFETTO_SDK_ZIP"
56+
echo "$NEW_VERSION" > perfetto/VERSION
57+
curl -sL -o "perfetto/LICENSE" "https://raw.githubusercontent.com/google/perfetto/refs/tags/$PERFETTO_REF/LICENSE"
58+
59+
# Remove C API headers. Only keep C++ API headers.
60+
rm perfetto/sdk/perfetto_c.h perfetto/sdk/perfetto_c.cc
61+
62+
echo "Copying existing gyp files"
63+
cp "$DEPS_DIR/perfetto/perfetto.gyp" "$WORKSPACE/perfetto"
64+
65+
echo "Copying existing GN files"
66+
cp "$DEPS_DIR/perfetto/"*.gn "$DEPS_DIR/perfetto/"*.gni "$WORKSPACE/perfetto"
67+
68+
echo "Replacing existing perfetto"
69+
rm -rf "$DEPS_DIR/perfetto"
70+
mv "$WORKSPACE/perfetto" "$DEPS_DIR/"
71+
72+
# Update the version number on maintaining-dependencies.md
73+
# and print the new version as the last line of the script as we need
74+
# to add it to $GITHUB_ENV variable
75+
finalize_version_update "perfetto" "$NEW_VERSION"

0 commit comments

Comments
 (0)