( processes, tracked, options = DEFAULTS, )
| 144 | } |
| 145 | |
| 146 | export function discoverTrackedProcesses( |
| 147 | processes, |
| 148 | tracked, |
| 149 | options = DEFAULTS, |
| 150 | ) { |
| 151 | const nextTracked = new Map(tracked); |
| 152 | const capMain = findCapMainProcess(processes, options.appCommandPrefix); |
| 153 | |
| 154 | if (!capMain) { |
| 155 | throw new Error( |
| 156 | `No running Cap process found for ${options.appCommandPrefix}`, |
| 157 | ); |
| 158 | } |
| 159 | |
| 160 | for (const processInfo of processes) { |
| 161 | const classification = classifyProcess( |
| 162 | processInfo.command, |
| 163 | options.appCommandPrefix, |
| 164 | ); |
| 165 | |
| 166 | if (!classification) continue; |
| 167 | |
| 168 | const isAlreadyTracked = nextTracked.has(processInfo.pid); |
| 169 | const isLongLivedCapWebKit = |
| 170 | classification.group === "cap" && |
| 171 | classification.kind.startsWith("webkit-") && |
| 172 | Math.abs(processInfo.etimes - capMain.etimes) <= |
| 173 | options.initialWebKitWindowSeconds; |
| 174 | const isFreshCapWebKit = |
| 175 | classification.group === "cap" && |
| 176 | classification.kind.startsWith("webkit-") && |
| 177 | processInfo.etimes <= options.newWebKitWindowSeconds; |
| 178 | const shouldTrack = |
| 179 | classification.kind === "cap-main" || |
| 180 | classification.kind === "cap-crash" || |
| 181 | classification.group === "system" || |
| 182 | classification.group === "media" || |
| 183 | isLongLivedCapWebKit || |
| 184 | isFreshCapWebKit; |
| 185 | |
| 186 | if (!shouldTrack) continue; |
| 187 | |
| 188 | nextTracked.set(processInfo.pid, { |
| 189 | ...processInfo, |
| 190 | ...classification, |
| 191 | isNew: !isAlreadyTracked, |
| 192 | }); |
| 193 | } |
| 194 | |
| 195 | return nextTracked; |
| 196 | } |
| 197 | |
| 198 | export function buildSample(processes, tracked, options = DEFAULTS) { |
| 199 | const discoveredTracked = discoverTrackedProcesses( |
no test coverage detected