@lensmcp/memory-tracker 1.18.14 → 1.19.0
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/lib/context.js +1 -1
- package/lib/detectors.js +1 -1
- package/lib/emit.js +1 -1
- package/lib/owners.js +1 -1
- package/lib/track-container.js +1 -1
- package/package.json +2 -2
package/lib/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var t=(e,n)=>a(e,"name",{value:n,configurable:!0});var c=Object.defineProperty,r=t((e,n)=>c(e,"name",{value:n,configurable:!0}),"t");let s=r(()=>{},"contextGetter"),o;const l={leakItemThreshold:50,staleGenerationBytesThreshold:1024*1024,settleMs:1e3};export function configureMemoryTracker(e){return o={sessionId:e.sessionId,sink:e.sink,leakItemThreshold:e.leakItemThreshold??l.leakItemThreshold,staleGenerationBytesThreshold:e.staleGenerationBytesThreshold??l.staleGenerationBytesThreshold,settleMs:e.settleMs??l.settleMs},e.contextGetter&&(s=e.contextGetter),o}t(configureMemoryTracker,"configureMemoryTracker"),r(configureMemoryTracker,"configureMemoryTracker");export function activeMemoryOptions(){return o}t(activeMemoryOptions,"activeMemoryOptions"),r(activeMemoryOptions,"activeMemoryOptions");export function currentMemoryContext(){return s()}t(currentMemoryContext,"currentMemoryContext"),r(currentMemoryContext,"currentMemoryContext");export function resetMemoryTracker(){o=void 0,s=r(()=>{},"contextGetter")}t(resetMemoryTracker,"resetMemoryTracker"),r(resetMemoryTracker,"resetMemoryTracker");
|
package/lib/detectors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var s=Object.defineProperty;var n=(t
|
|
1
|
+
"use strict";var s=Object.defineProperty;var n=(e,t)=>s(e,"name",{value:t,configurable:!0});var l=Object.defineProperty,r=n((e,t)=>l(e,"name",{value:t,configurable:!0}),"n");import{activeMemoryOptions as i}from"./context.js";import{clearFlowStart as c,flowGrowth as d,markFlowStart as w}from"./owners.js";import{emitRetention as u,emitStaleGeneration as f}from"./emit.js";export function onFlowStart(e){w(e)}n(onFlowStart,"onFlowStart"),r(onFlowStart,"onFlowStart");export function onFlowSettled(e){const t=i();if(!t)return[];const a=[];for(const o of d(e))o.growth>=t.leakItemThreshold&&o.endCount>=o.growth&&(u({options:t,ownerId:o.owner.ownerId,flowId:e,startCount:o.startCount,endCount:o.endCount,growth:o.growth}),a.push(o.owner.ownerId));return c(e),a}n(onFlowSettled,"onFlowSettled"),r(onFlowSettled,"onFlowSettled");export function checkStaleGeneration(e){const t=i();return t&&e.retainedBytes>t.staleGenerationBytesThreshold?(f({options:t,logicalId:e.logicalId,instanceId:e.instanceId,generation:e.generation,retainedBytes:e.retainedBytes}),!0):!1}n(checkStaleGeneration,"checkStaleGeneration"),r(checkStaleGeneration,"checkStaleGeneration");
|
package/lib/emit.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var m=Object.defineProperty;var n=(t,e)=>m(t,"name",{value:e,configurable:!0});var I=Object.defineProperty,o=n((t,e)=>I(t,"name",{value:e,configurable:!0}),"n");let d=0;function r(t){return d=(d+1)%16777215,`${t}-${d.toString(36)}`}n(r,"d"),o(r,"memId");function a(t,e){return{sessionId:e?.sessionId??t.sessionId,...e?.flowId?{flowId:e.flowId}:{},...e?.requestId?{requestId:e.requestId}:{},...e?.originNodeId?{originNodeId:e.originNodeId}:{}}}n(a,"r"),o(a,"baseContext");export function emitMutation(t){const{options:e}=t,i={id:r("memmut"),sessionId:t.context?.sessionId??e.sessionId,timestamp:t.timestamp??s(),source:"memory",category:"memory",severity:"debug",context:a(e,t.context),fingerprint:`memory-mutation:${t.ownerId}:${t.operation}`,title:`${t.operation} ${t.ownerId}`,raw:{kind:"memory-mutation",mutation:{ownerNodeId:t.ownerId,operation:t.operation,beforeCount:t.beforeCount,afterCount:t.afterCount,estimatedDeltaBytes:t.estimatedDeltaBytes,keyPreview:t.keyPreview}}};e.sink(i)}n(emitMutation,"emitMutation"),o(emitMutation,"emitMutation");export function emitRetention(t){const{options:e}=t,i={id:r("memret"),sessionId:t.context?.sessionId??e.sessionId,timestamp:t.timestamp??s(),source:"memory",category:"memory",severity:"warning",context:{...a(e,t.context),flowId:t.flowId},fingerprint:`memory-retention:${t.ownerId}`,title:`Suspected leak: ${t.ownerId} grew by ${t.growth} and did not shrink`,raw:{kind:"memory-retention",retention:{ownerId:t.ownerId,flowId:t.flowId,startCount:t.startCount,endCount:t.endCount,growth:t.growth}}};e.sink(i)}n(emitRetention,"emitRetention"),o(emitRetention,"emitRetention");export function emitStaleGeneration(t){const{options:e}=t,i={id:r("memstale"),sessionId:e.sessionId,timestamp:t.timestamp??s(),source:"memory",category:"memory",severity:"warning",context:{sessionId:e.sessionId},fingerprint:`memory-stale-generation:${t.logicalId}`,title:`Stale generation retained: ${t.logicalId} gen ${t.generation} holds ${t.retainedBytes} bytes`,raw:{kind:"singleton-stale-generation",staleGeneration:{logicalId:t.logicalId,instanceId:t.instanceId,generation:t.generation,retainedBytes:t.retainedBytes}}};e.sink(i)}n(emitStaleGeneration,"emitStaleGeneration"),o(emitStaleGeneration,"emitStaleGeneration");function s(){return Date.now()}n(s,"s"),o(s,"nowMs");
|
package/lib/owners.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.defineProperty;var o=(e,t)=>l(e,"name",{value:t,configurable:!0});var w=Object.defineProperty,r=o((e,t)=>w(e,"name",{value:t,configurable:!0}),"o");const a=new Map;export function ownerKey(e,t){return`${e}::${t}`}o(ownerKey,"ownerKey"),r(ownerKey,"ownerKey");export function ensureOwner(e){const t=ownerKey(e.ownerInstanceId,e.fieldName);let n=a.get(t);return n||(n={ownerId:t,ownerInstanceId:e.ownerInstanceId,containerKind:e.containerKind,fieldName:e.fieldName,itemCount:0,estimatedBytes:0,startCount:0,flowStartCounts:new Map,flowDeltas:new Map},a.set(t,n)),n}o(ensureOwner,"ensureOwner"),r(ensureOwner,"ensureOwner");export function recordCount(e,t,n){e.itemCount=t,e.estimatedBytes=n}o(recordCount,"recordCount"),r(recordCount,"recordCount");export function markFlowStart(e){for(const t of a.values())t.flowStartCounts.has(e)||t.flowStartCounts.set(e,t.itemCount)}o(markFlowStart,"markFlowStart"),r(markFlowStart,"markFlowStart");export function recordFlowDelta(e,t,n){e.flowDeltas.set(t,(e.flowDeltas.get(t)??0)+n)}o(recordFlowDelta,"recordFlowDelta"),r(recordFlowDelta,"recordFlowDelta");export function flowGrowth(e){const t=[];for(const n of a.values()){const s=n.flowDeltas.get(e);s!==void 0&&t.push({owner:n,startCount:n.flowStartCounts.get(e)??0,endCount:n.itemCount,growth:s})}return t}o(flowGrowth,"flowGrowth"),r(flowGrowth,"flowGrowth");export function clearFlowStart(e){for(const t of a.values())t.flowStartCounts.delete(e),t.flowDeltas.delete(e)}o(clearFlowStart,"clearFlowStart"),r(clearFlowStart,"clearFlowStart");export function allOwners(){return[...a.values()].map(e=>({ownerId:e.ownerId,ownerInstanceId:e.ownerInstanceId,containerKind:e.containerKind,fieldName:e.fieldName,itemCount:e.itemCount,estimatedBytes:e.estimatedBytes,growthSinceStart:e.itemCount-e.startCount}))}o(allOwners,"allOwners"),r(allOwners,"allOwners");export function getOwner(e){return a.get(e)}o(getOwner,"getOwner"),r(getOwner,"getOwner");export function resetOwners(){a.clear()}o(resetOwners,"resetOwners"),r(resetOwners,"resetOwners");
|
package/lib/track-container.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var z=Object.defineProperty;var s=(t,e)=>z(t,"name",{value:e,configurable:!0});var A=Object.defineProperty,f=s((t,e)=>A(t,"name",{value:e,configurable:!0}),"s");import{activeMemoryOptions as g,currentMemoryContext as v}from"./context.js";import{ensureOwner as b,recordCount as h,recordFlowDelta as C}from"./owners.js";import{emitMutation as k}from"./emit.js";const I=Symbol.for("@lensmcp/memory-tracker/patched"),p=64;export function trackContainer(t){const{container:e}=t;if(!e||typeof e!="object"||e[I])return;let a;if(e instanceof Map)a="Map",w(t,e);else if(e instanceof Set)a="Set",M(t,e);else if(Array.isArray(e))a="Array",S(t,e);else return;e[I]=!0;const o=m(e),c=b({ownerInstanceId:t.ownerInstanceId,fieldName:t.fieldName,containerKind:a});h(c,o,o*p)}s(trackContainer,"trackContainer"),f(trackContainer,"trackContainer");function m(t){return t instanceof Map||t instanceof Set?t.size:Array.isArray(t)?t.length:0}s(m,"w"),f(m,"sizeOf");function d(t,e,a,o,c){const r=g();if(!r)return;const n=m(t.container),i=b({ownerInstanceId:t.ownerInstanceId,fieldName:t.fieldName,containerKind:e});h(i,n,n*p);const l=v(),y=l?.requestId??l?.flowId;y&&C(i,y,n-o),k({options:r,ownerId:i.ownerId,operation:a,beforeCount:o,afterCount:n,estimatedDeltaBytes:(n-o)*p,keyPreview:c,context:l})}s(d,"d"),f(d,"afterMutation");function w(t,e){const a=e.set.bind(e),o=e.delete.bind(e),c=e.clear.bind(e);e.set=(r,n)=>{const i=e.size,l=a(r,n);return d(t,"Map","set",i,u(r)),l},e.delete=r=>{const n=e.size,i=o(r);return d(t,"Map","delete",n,u(r)),i},e.clear=()=>{const r=e.size;c(),d(t,"Map","clear",r)}}s(w,"m"),f(w,"patchMap");function M(t,e){const a=e.add.bind(e),o=e.delete.bind(e),c=e.clear.bind(e);e.add=r=>{const n=e.size,i=a(r);return d(t,"Set","add",n,u(r)),i},e.delete=r=>{const n=e.size,i=o(r);return d(t,"Set","delete",n,u(r)),i},e.clear=()=>{const r=e.size;c(),d(t,"Set","clear",r)}}s(M,"C"),f(M,"patchSet");function S(t,e){const a=e.push.bind(e),o=e.splice.bind(e);e.push=(...c)=>{const r=e.length,n=a(...c);return d(t,"Array","push",r),n},e.splice=((c,r,...n)=>{const i=e.length,l=r===void 0?o(c):o(c,r,...n);return d(t,"Array",n.length>0?"push":"delete",i),l})}s(S,"D"),f(S,"patchArray");function u(t){if(typeof t=="string")return t.slice(0,40);if(typeof t=="number"||typeof t=="boolean")return String(t)}s(u,"u"),f(u,"previewKey");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lensmcp/memory-tracker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.19.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lensmcp/protocol-types": "1.
|
|
17
|
+
"@lensmcp/protocol-types": "1.19.0",
|
|
18
18
|
"tslib": "^2.3.0"
|
|
19
19
|
},
|
|
20
20
|
"license": "Apache-2.0",
|