memtrace 0.3.56 → 0.3.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/install.js +96 -3
- package/package.json +6 -4
package/install.js
CHANGED
|
@@ -9,6 +9,16 @@ const { platformBinary, spawnOptionsForPlatform } = require("./lib/spawn-helper"
|
|
|
9
9
|
const { installToFs } = require("./lib/claude-integration");
|
|
10
10
|
|
|
11
11
|
// ── Platform binary resolution (preserved from legacy) ───────────────────────
|
|
12
|
+
//
|
|
13
|
+
// Two parallel package families on x86_64:
|
|
14
|
+
// • default — bundles MS prebuilt libonnxruntime (AVX2 baseline)
|
|
15
|
+
// • `*-noavx2` — bundles a from-source build with AVX/AVX2/AVX-512
|
|
16
|
+
// codegen disabled, for Ivy Bridge / Xeon E5 v2 etc.
|
|
17
|
+
// Apple Silicon and Linux ARM don't need the split (no AVX in the ISA).
|
|
18
|
+
//
|
|
19
|
+
// The choice is made at install time by `hasAvx2()`. Users can force the
|
|
20
|
+
// no-AVX2 variant via `MEMTRACE_FORCE_NOAVX2=1` (handy for testing or
|
|
21
|
+
// when CPU detection is unreliable in containerised envs).
|
|
12
22
|
|
|
13
23
|
const PLATFORM_MAP = {
|
|
14
24
|
"darwin-arm64": "@memtrace/darwin-arm64",
|
|
@@ -18,13 +28,94 @@ const PLATFORM_MAP = {
|
|
|
18
28
|
"win32-x64": "@memtrace/win32-x64",
|
|
19
29
|
};
|
|
20
30
|
|
|
31
|
+
const NOAVX2_PLATFORM_MAP = {
|
|
32
|
+
"linux-x64": "@memtrace/linux-x64-noavx2",
|
|
33
|
+
"win32-x64": "@memtrace/win32-x64-noavx2",
|
|
34
|
+
};
|
|
35
|
+
|
|
21
36
|
function getPlatformKey() {
|
|
22
37
|
return `${os.platform()}-${os.arch()}`;
|
|
23
38
|
}
|
|
24
39
|
|
|
40
|
+
// Best-effort runtime AVX2 check. Returns `true` (AVX2 present) when we
|
|
41
|
+
// can't tell — the AVX2 path is the common case and the runtime gate in
|
|
42
|
+
// the binary catches the wrong choice with a clean error if we guess
|
|
43
|
+
// wrong. This is install-time best-effort; the actual bullet-proof check
|
|
44
|
+
// happens at process start.
|
|
45
|
+
function hasAvx2() {
|
|
46
|
+
if (process.env.MEMTRACE_FORCE_NOAVX2 === "1") {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (process.env.MEMTRACE_FORCE_AVX2 === "1") {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
const arch = os.arch();
|
|
53
|
+
// Only x86_64 CPUs have AVX as a concept. ARM hosts skip the check.
|
|
54
|
+
if (arch !== "x64") {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
const platform = os.platform();
|
|
58
|
+
try {
|
|
59
|
+
if (platform === "linux") {
|
|
60
|
+
const cpuinfo = fs.readFileSync("/proc/cpuinfo", "utf8");
|
|
61
|
+
// `flags` line on Intel, `Features` on some emulators.
|
|
62
|
+
return /\b(avx2)\b/.test(cpuinfo);
|
|
63
|
+
}
|
|
64
|
+
if (platform === "win32") {
|
|
65
|
+
// PowerShell exposes ProcessorFeaturePresent via the kernel32 API
|
|
66
|
+
// through the PROCESSOR_FEATURE enum. PF_AVX2_INSTRUCTIONS_AVAILABLE
|
|
67
|
+
// is feature ID 40. A fresh PS process is ~300 ms — fine for an
|
|
68
|
+
// install-time hook that only runs once.
|
|
69
|
+
const result = spawnSync(
|
|
70
|
+
"powershell",
|
|
71
|
+
[
|
|
72
|
+
"-NoProfile",
|
|
73
|
+
"-NonInteractive",
|
|
74
|
+
"-Command",
|
|
75
|
+
"[System.Reflection.Assembly]::Load('mscorlib') | Out-Null; " +
|
|
76
|
+
"Add-Type -MemberDefinition '[DllImport(\"kernel32\")] " +
|
|
77
|
+
"public static extern bool IsProcessorFeaturePresent(uint f);' " +
|
|
78
|
+
"-Name PF -Namespace Memtrace; " +
|
|
79
|
+
"[Memtrace.PF]::IsProcessorFeaturePresent(40)",
|
|
80
|
+
],
|
|
81
|
+
{ encoding: "utf8", timeout: 5000 }
|
|
82
|
+
);
|
|
83
|
+
const out = (result.stdout || "").trim().toLowerCase();
|
|
84
|
+
if (out === "true") return true;
|
|
85
|
+
if (out === "false") return false;
|
|
86
|
+
return true; // ambiguous → assume AVX2
|
|
87
|
+
}
|
|
88
|
+
if (platform === "darwin") {
|
|
89
|
+
// sysctl exposes CPU feature leaves directly. macOS x86_64 was only
|
|
90
|
+
// ever shipped on Sandy Bridge → Coffee Lake; AVX2 lands in Haswell
|
|
91
|
+
// (mid-2013), which lines up with the 2013+ Mac Pro and every Mac
|
|
92
|
+
// Apple sold from late 2013 onward. We probe explicitly anyway in
|
|
93
|
+
// case someone is running on a Hackintosh with an older CPU.
|
|
94
|
+
const result = spawnSync("sysctl", ["-n", "machdep.cpu.leaf7_features"], {
|
|
95
|
+
encoding: "utf8",
|
|
96
|
+
timeout: 2000,
|
|
97
|
+
});
|
|
98
|
+
const out = (result.stdout || "").toUpperCase();
|
|
99
|
+
return /AVX2/.test(out);
|
|
100
|
+
}
|
|
101
|
+
} catch (_) {
|
|
102
|
+
// Detection failed (locked-down container, missing /proc, sysctl
|
|
103
|
+
// gone, etc.). Default to the AVX2 path — the runtime gate will
|
|
104
|
+
// catch a wrong guess with a clean error.
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function platformPackageName(key) {
|
|
110
|
+
if (!hasAvx2() && Object.prototype.hasOwnProperty.call(NOAVX2_PLATFORM_MAP, key)) {
|
|
111
|
+
return NOAVX2_PLATFORM_MAP[key];
|
|
112
|
+
}
|
|
113
|
+
return PLATFORM_MAP[key];
|
|
114
|
+
}
|
|
115
|
+
|
|
25
116
|
function getBinaryPath() {
|
|
26
117
|
const key = getPlatformKey();
|
|
27
|
-
const pkg =
|
|
118
|
+
const pkg = platformPackageName(key);
|
|
28
119
|
if (!pkg) {
|
|
29
120
|
throw new Error(
|
|
30
121
|
`Memtrace does not support platform: ${key}\n` +
|
|
@@ -42,7 +133,7 @@ function getBinaryPath() {
|
|
|
42
133
|
return require.resolve(`${pkg}/bin/${binaryName}`);
|
|
43
134
|
} catch {
|
|
44
135
|
throw new Error(
|
|
45
|
-
`Could not find memtrace binary for ${key}.\n` +
|
|
136
|
+
`Could not find memtrace binary for ${key} (package ${pkg}).\n` +
|
|
46
137
|
`Try reinstalling: npm install -g memtrace`
|
|
47
138
|
);
|
|
48
139
|
}
|
|
@@ -82,7 +173,7 @@ function getPinnedPlatformVersion(packageJson, platformPackage) {
|
|
|
82
173
|
// versioned name comes from the same map the runtime resolver uses.
|
|
83
174
|
function selfHealPlatformPackage() {
|
|
84
175
|
const key = getPlatformKey();
|
|
85
|
-
const pkg =
|
|
176
|
+
const pkg = platformPackageName(key);
|
|
86
177
|
if (!pkg) return false; // unsupported platform — getBinaryPath will surface it later
|
|
87
178
|
try {
|
|
88
179
|
require.resolve(`${pkg}/package.json`);
|
|
@@ -210,4 +301,6 @@ module.exports = {
|
|
|
210
301
|
buildSelfHealEnv,
|
|
211
302
|
buildSelfHealInstallArgs,
|
|
212
303
|
getPinnedPlatformVersion,
|
|
304
|
+
hasAvx2,
|
|
305
|
+
platformPackageName,
|
|
213
306
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "memtrace",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.70",
|
|
4
4
|
"description": "Code intelligence graph — MCP server + AI agent skills + visualization UI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -39,9 +39,11 @@
|
|
|
39
39
|
"fs-extra": "^11.0.0"
|
|
40
40
|
},
|
|
41
41
|
"optionalDependencies": {
|
|
42
|
-
"@memtrace/darwin-arm64": "0.3.
|
|
43
|
-
"@memtrace/linux-x64": "0.3.
|
|
44
|
-
"@memtrace/win32-x64": "0.3.
|
|
42
|
+
"@memtrace/darwin-arm64": "0.3.70",
|
|
43
|
+
"@memtrace/linux-x64": "0.3.70",
|
|
44
|
+
"@memtrace/win32-x64": "0.3.70",
|
|
45
|
+
"@memtrace/linux-x64-noavx2": "0.3.70",
|
|
46
|
+
"@memtrace/win32-x64-noavx2": "0.3.70"
|
|
45
47
|
},
|
|
46
48
|
"engines": {
|
|
47
49
|
"node": ">=18"
|