[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6BXSP2101RPWSHH97YCH6TN":3,"skill-same:01M6BXSP2101RPWSHH97YCH6TN":70},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":42,"linkOnly":43,"markdownContent":44,"markdownBody":45,"frontMatter":46,"refName":47,"commitSha":48,"skillDirectory":49,"forksCount":50,"repositoryHtmlUrl":51,"repositoryHomepageUrl":52,"ownerHtmlUrl":53,"ownerBlogUrl":6,"ownerDescription":54,"updatedAt":55,"install":56,"resources":69},"01M6BXSP2101RPWSHH97YCH6TN","flutter-edge-ai-diagnostics",null,"Use when measuring how much memory an on-device model costs with flutter_edge_ai_diagnostics — MemorySnapshot, anonymousBytes, anonymousPeakBytes, fileBackedBytes, availableBytes, GpuMemoryReading — on Android, iOS, macOS, Linux or Windows, when an app is killed for memory (iOS jetsam, Android lmkd) while loading or running a model, when choosing between model sizes for a device, or when RSS numbers do not add up. Also use when FlutterEdgeAiDiagnostics.memorySnapshot() throws MemoryReadException or UnsupportedError, or a snapshot field is null. For running the model itself, use flutter-edge-ai-inference.","DenisovAV\u002Fflutter_edge_ai","DenisovAV","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F9622910?v=4","01M6BXRH02KTWK364FYEH4AECE","Sasha Denisov","01M6BXRH45KJKJ712H82EV47AS",662,"MIT","https:\u002F\u002Fgithub.com\u002FDenisovAV\u002Fflutter_edge_ai\u002Fblob\u002Fmain\u002Fpackages\u002Fflutter_edge_ai\u002Fskills\u002Fflutter-edge-ai-diagnostics\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41],"edge ai","flutter","flutter edge ai diagnostics","diagnostics","edge","when","for","running","snapshot","with","use","up","loading","do","windows","app","rss","ios","how","android","linux","memory","model","2026-11-10 10:12:30",false,"---\nname: flutter-edge-ai-diagnostics\ndescription: Use when measuring how much memory an on-device model costs with flutter_edge_ai_diagnostics — MemorySnapshot, anonymousBytes, anonymousPeakBytes, fileBackedBytes, availableBytes, GpuMemoryReading — on Android, iOS, macOS, Linux or Windows, when an app is killed for memory (iOS jetsam, Android lmkd) while loading or running a model, when choosing between model sizes for a device, or when RSS numbers do not add up. Also use when FlutterEdgeAiDiagnostics.memorySnapshot() throws MemoryReadException or UnsupportedError, or a snapshot field is null. For running the model itself, use flutter-edge-ai-inference.\n---\n\n# Memory diagnostics\n\n## Rules\n\n1. Depend on `flutter_edge_ai_diagnostics` and import it. It does not depend on `flutter_edge_ai` and reads the process, whichever engine runs in it.\n2. Android, iOS, macOS, Linux and Windows only; not the web, whose memory APIs do not count a model's WASM or GPU memory. Check `FlutterEdgeAiDiagnostics.isSupported` first: elsewhere `memorySnapshot()` and `gpuMemory()` throw `UnsupportedError` instead of returning empty values.\n3. `null` and an exception mean different things. A null field is a value this package does not report on this platform; `MemoryReadException` is a read that should have worked and failed. Do not catch the exception and carry on with zeros.\n4. The fields answer different questions per platform. On iOS `anonymousBytes` is `phys_footprint`, the number jetsam kills on, and `availableBytes` is this app's headroom before that limit. macOS uses the same `phys_footprint` for `anonymousBytes` but has no per-app limit, so there is no kill threshold and `availableBytes` is null. `anonymousPeakBytes` (iOS, macOS and Windows, null on Android and Linux) is the kernel's lifetime high-water mark of that figure (the footprint, or commit on Windows): it is never reset, so read a snapshot before you start and treat it as an upper bound for the operation. On Android there is no per-app limit: `availableBytes` is MemAvailable for the whole device, an optimistic upper bound, and lmkd kills well before it reaches zero. Never use it as an Android kill threshold. Linux reads the same files as Android; its `availableBytes` is machine-wide MemAvailable and ignores a cgroup `memory.max`, so inside a container it overstates what the app may use. On Windows `anonymousBytes` is the commit charge (PagefileUsage = PrivateUsage): private memory the app owns wherever it is, counted when allocated and not when touched, so it reads higher than the resident figure and is not comparable with the other platforms (FunctionGemma 270M on the CPU: +389 to +392 MiB commit against +102 to +105 MiB private working set at load; about three quarters of the commit arrives at load, slightly more than half of the private working set (about 55%) with the first prompt). After a GPU model is closed, commit falls with a delay: on one machine (RTX 3050, FunctionGemma 270M, debug build, #749) it stayed about 360 MiB above its pre-load value for about 2 s and stopped falling by about 8 s, about 65 MiB above it after the first load\u002Fclose cycle in a process and at most about 16 MiB after later cycles; elsewhere, read until it stops falling. `anonymousPeakBytes` is PeakPagefileUsage. `availableBytes` is `ullAvailPhys`, physical memory for the whole machine, not headroom: Windows does not kill for low memory, an allocation fails once commit reaches the commit limit, and that headroom is `ullAvailPageFile`, which this package does not read.\n5. On Android, GPU memory (KGSL, Mali, dmabuf) is mostly outside `anonymousBytes`; on Adreno most of it is counted in `fileBackedBytes` instead (see 6). A model running on the GPU backend looks cheaper in `anonymousBytes` alone than it is. `FlutterEdgeAiDiagnostics.gpuMemory()` (experimental, Adreno only) returns a `GpuMemoryReading`, or null when the device has no reader (always on iOS, macOS, Linux and Windows, and on a phone with no `\u002Fdev\u002Fkgsl-3d0`, a Mali GPU for one; an Adreno process that has not used the GPU yet gets zeros); it is not a `MemorySnapshot` field. Its `inAnonymousBytes` and `inFileBackedBytes` are already inside those two counters; to subtract the second from `fileBackedBytes`, take both back to back while idle and treat the difference as approximate, since two reads taken apart can make it negative. It covers only the GPU memory mapped into the process, and costs 0.2 to 0.4 s on the device tried: the kernel holds the process's `mmap_lock` while it builds `smaps`, so do not call it per frame or per token. It is a reading, not a delta: it includes the app's own rendering (about 6 MiB in a Flutter app), so take one before loading the model and subtract. `gpuMemory()`, `GpuMemoryReading` and `GpuMemorySource` are `@experimental`: using them draws the `experimental_member_use` analyzer warning (add `\u002F\u002F ignore: experimental_member_use` at the call site), and `GpuMemorySource` will gain values, so a `switch` over `reading.source` needs a default case.\n6. On Android and Linux `fileBackedBytes` is `Private_Clean + Shared_Clean`: resident clean pages (mapped files on a CPU backend, and GPU driver buffers on some GPU backends; on Adreno most of a GPU model's memory is a `\u002Fdev\u002Fkgsl-3d0` mapping, mostly clean pages, not the model file). It can also include clean anonymous pages, so a delta is not an exact count of model weights. Reclaimable file pages are not a kill threshold, but are not free: weights read on every token must be read back from storage if dropped, and lmkd can treat that refault thrashing as a reason to kill. On Linux GPU memory is in neither field: on an integrated GPU it is system RAM the snapshot does not show (FunctionGemma 270M: 700 to 835 MiB of Intel `drm-resident-system0`, device mappings 0 MiB). A page swapped out and read back lands in Private_Clean (512 MiB did, on Linux 7.0). On Windows it is `WorkingSetSize − PrivateWorkingSetSize`: the shareable working set, every resident page that is not private (mapped files and DLL pages, and modified shared pages too), so not model weights (a LiteRT-LM CPU model is mapped at load and faulted in by the first prompt; ORT-GenAI's weights land in the private working set instead); it is null on a Windows that does not fill the extended struct, and a private working set above the working set is a `MemoryReadException`. How much of a Windows GPU model's memory the snapshot holds is not measured (part of it may be in `anonymousBytes`), and `gpuMemory()` returns null there. iOS and macOS are null because the package does not read this value there yet.\n7. A snapshot walks kernel state: on Android the `\u002Fproc` reads are asynchronous (they do not block the isolate) but cost about 150 ms on a low-end device, and before Linux 5.10 they stall the process's mmap calls; on Linux about 3.7 ms per resident GiB (1.7 ms idle, 30 ms with 7 GiB resident, one machine); on iOS and macOS they are microsecond Mach calls; on Windows they are two `kernel32` calls, not timed. Take one at a few points — before loading, after loading, during generation — and never faster than about once a second, not on every frame or token.\n8. A pubspec section strips nothing from a release build. Put the package under `dev_dependencies` only when nothing in `lib\u002F` imports it.\n\n## Interpret resident clean pages\n\nGPU backends: on a GPU backend on Adreno, the driver's buffers are mapped through `\u002Fdev\u002Fkgsl-3d0` and are mostly clean pages, so they are counted here too. In one run on the vivo 1933 (Adreno 616, kernel 4.9) a Gemma 4 E2B GPU load raised that mapping from 6 to 981 MiB (988 after one prompt), matching `dumpsys meminfo`'s Gfx dev (989 MiB); about 115 MiB of it was dirty, which is in `anonymousBytes`, and all file mappings together (model, libraries, others) were about 260 MiB (Pss). With a GPU backend `fileBackedBytes` is therefore not a model-file figure: compare with a run of the same app on CPU, or subtract the `inFileBackedBytes` of a `FlutterEdgeAiDiagnostics.gpuMemory()` reading from `fileBackedBytes` (experimental, see rule 5). One device and one run each; other GPU drivers (Mali) were not measured.\n\nThe baseline includes every clean mapped file the process has touched. Take a reading before loading and subtract; shared pages count in full, not proportionally. Singly mapped dirty file pages are in Private_Dirty (inside `anonymousBytes`); Shared_Dirty is in neither field.\n\nClean anonymous pages can appear in Private_Clean, including pages read back from zram and not written since, and MADV_FREE pages. On zram's skip-swapcache path, pages can lose their swap slots and leave SwapPss. Under model-load pressure, cold heap memory can therefore move from `anonymousBytes` into `fileBackedBytes`. Interpret both counters together; neither alone measures all model memory or predicts an Android kill.\n\nWith version 0.2.2 on vivo 1933 (Android 11, kernel 4.9), Gemma 4 E2B `fileBackedBytes` in MiB was 103.6 → 800.5 → 1043.2 → 102.3 on CPU and 102.3 → 1390.3 → 1413.2 → 116.1 on GPU, measured before load, after load, after one prompt, and after close. The actual backend matched the request. `Private_Clean + Shared_Clean − (Rss − Anonymous)` was negative after load and after the prompt on both backends, so this run gave no positive lower bound for clean anonymous pages. It does not establish that none were present.\n\nOn iOS, TASK_VM_INFO has an `external` field; evaluating it is a follow-up. A null `fileBackedBytes` does not imply that iOS lacks such accounting.\n\n## Measure what a model costs\n\n```sh\nflutter pub add flutter_edge_ai flutter_edge_ai_litertlm flutter_edge_ai_diagnostics\n```\n\n```dart\nimport 'package:flutter\u002Ffoundation.dart';\nimport 'package:flutter_edge_ai\u002Fflutter_edge_ai.dart';\nimport 'package:flutter_edge_ai_diagnostics\u002Fflutter_edge_ai_diagnostics.dart';\n\nint? grew(MemorySnapshot before, MemorySnapshot after) {\n  if ((before.anonymousBytes, after.anonymousBytes)\n      case (final int from, final int to)) {\n    return to - from;\n  }\n  return null; \u002F\u002F the platform does not report it\n}\n\nFuture\u003CInferenceModel> loadAndMeasure() async {\n  if (!FlutterEdgeAiDiagnostics.isSupported) {\n    return FlutterEdgeAi.getActiveModel(maxTokens: 1024);\n  }\n  final before = await FlutterEdgeAiDiagnostics.memorySnapshot();\n  final model = await FlutterEdgeAi.getActiveModel(maxTokens: 1024);\n  final loaded = await FlutterEdgeAiDiagnostics.memorySnapshot();\n  debugPrint('model load: anonymousBytes delta ${grew(before, loaded)} bytes, '\n      '${loaded.availableBytes} still available');\n  return model;\n}\n```\n\nSample during generation at most once a second, not on each chunk:\n\n```dart\nFuture\u003CString> answerAndMeasure(InferenceModelSession session) async {\n  final reply = StringBuffer();\n  final sinceLast = Stopwatch()..start();\n  MemorySnapshot? peak;\n  await for (final chunk in session.getResponseAsync()) {\n    reply.write(chunk);\n    if (sinceLast.elapsed >= const Duration(seconds: 1) &&\n        FlutterEdgeAiDiagnostics.isSupported) {\n      sinceLast.reset();\n      final now = await FlutterEdgeAiDiagnostics.memorySnapshot();\n      if ((now.anonymousBytes ?? 0) > (peak?.anonymousBytes ?? 0)) peak = now;\n    }\n  }\n  debugPrint('highest sampled footprint: ${peak?.anonymousBytes}');\n  return reply.toString();\n}\n```\n\n## Null versus an exception\n\n```dart\nFuture\u003Cvoid> report() async {\n  try {\n    final s = await FlutterEdgeAiDiagnostics.memorySnapshot();\n    debugPrint('anonymous ${s.anonymousBytes ?? 'not reported here'}, '\n        'available ${s.availableBytes ?? 'not reported here'}');\n  } on MemoryReadException catch (e) {\n    \u002F\u002F The OS should have answered: a kernel, permission or I\u002FO error.\n    debugPrint('memory read failed: $e');\n    rethrow;\n  }\n}\n```\n\nA field is null in these cases:\n\n- `anonymousBytes` and `fileBackedBytes` on an Android or Linux kernel without `\u002Fproc\u002Fself\u002Fsmaps_rollup`. Mainline Linux added it in 4.14, but vendor kernels may backport it;\n- `fileBackedBytes` on iOS and macOS: this package does not read a corresponding value yet;\n- `availableBytes` always on macOS, which has no per-app limit, and on iOS when `os_proc_available_memory()` returns 0. Apple returns 0 both on the simulator, where no limit applies, and when the limit is already exceeded; the two cannot be told apart;\n- `fileBackedBytes` on a Windows that does not fill PrivateWorkingSetSize (the extended struct);\n- `anonymousPeakBytes` always on Android and Linux, and on an iOS or macOS version whose `task_info` reply predates the field.\n\n`gpuMemory()` returns null on iOS, macOS, Linux and Windows, and on an Android phone with no `\u002Fdev\u002Fkgsl-3d0` (a Mali GPU, for one; `existsSync` tests it, `typeSync` says not found); on an Adreno phone a process that has not used the GPU yet gets a zero reading; a missing or unparseable `\u002Fproc\u002Fself\u002Fsmaps` throws `MemoryReadException`; `outsideSnapshotBytes` is always null in this version.\n\n## Choosing a model for the device\n\nOn iOS, compare the growth you measured for a model with `availableBytes` before loading it: if the model needs more than the headroom, jetsam kills the app during load. Large models also need the memory entitlements listed in flutter-edge-ai-inference. Two of them change what you measure: **Increased Memory Limit** raises the jetsam limit, so `availableBytes` grows; **Extended Virtual Addressing** gives the app more address space to map the model and does not add headroom.\n\nOn Android there is no such number to compare against. Measure on the smallest device you support, and treat `availableBytes` as a best case. Include generation: a model whose weights repeatedly refault from storage can cause thrashing and contribute to an lmkd kill even though its file pages are reclaimable.\n\nOn macOS there is no per-app limit either, and `availableBytes` is null: `anonymousBytes` and `anonymousPeakBytes` say how much the app holds, so compare them with the Mac's physical memory.\n","# Memory diagnostics\n\n## Rules\n\n1. Depend on `flutter_edge_ai_diagnostics` and import it. It does not depend on `flutter_edge_ai` and reads the process, whichever engine runs in it.\n2. Android, iOS, macOS, Linux and Windows only; not the web, whose memory APIs do not count a model's WASM or GPU memory. Check `FlutterEdgeAiDiagnostics.isSupported` first: elsewhere `memorySnapshot()` and `gpuMemory()` throw `UnsupportedError` instead of returning empty values.\n3. `null` and an exception mean different things. A null field is a value this package does not report on this platform; `MemoryReadException` is a read that should have worked and failed. Do not catch the exception and carry on with zeros.\n4. The fields answer different questions per platform. On iOS `anonymousBytes` is `phys_footprint`, the number jetsam kills on, and `availableBytes` is this app's headroom before that limit. macOS uses the same `phys_footprint` for `anonymousBytes` but has no per-app limit, so there is no kill threshold and `availableBytes` is null. `anonymousPeakBytes` (iOS, macOS and Windows, null on Android and Linux) is the kernel's lifetime high-water mark of that figure (the footprint, or commit on Windows): it is never reset, so read a snapshot before you start and treat it as an upper bound for the operation. On Android there is no per-app limit: `availableBytes` is MemAvailable for the whole device, an optimistic upper bound, and lmkd kills well before it reaches zero. Never use it as an Android kill threshold. Linux reads the same files as Android; its `availableBytes` is machine-wide MemAvailable and ignores a cgroup `memory.max`, so inside a container it overstates what the app may use. On Windows `anonymousBytes` is the commit charge (PagefileUsage = PrivateUsage): private memory the app owns wherever it is, counted when allocated and not when touched, so it reads higher than the resident figure and is not comparable with the other platforms (FunctionGemma 270M on the CPU: +389 to +392 MiB commit against +102 to +105 MiB private working set at load; about three quarters of the commit arrives at load, slightly more than half of the private working set (about 55%) with the first prompt). After a GPU model is closed, commit falls with a delay: on one machine (RTX 3050, FunctionGemma 270M, debug build, #749) it stayed about 360 MiB above its pre-load value for about 2 s and stopped falling by about 8 s, about 65 MiB above it after the first load\u002Fclose cycle in a process and at most about 16 MiB after later cycles; elsewhere, read until it stops falling. `anonymousPeakBytes` is PeakPagefileUsage. `availableBytes` is `ullAvailPhys`, physical memory for the whole machine, not headroom: Windows does not kill for low memory, an allocation fails once commit reaches the commit limit, and that headroom is `ullAvailPageFile`, which this package does not read.\n5. On Android, GPU memory (KGSL, Mali, dmabuf) is mostly outside `anonymousBytes`; on Adreno most of it is counted in `fileBackedBytes` instead (see 6). A model running on the GPU backend looks cheaper in `anonymousBytes` alone than it is. `FlutterEdgeAiDiagnostics.gpuMemory()` (experimental, Adreno only) returns a `GpuMemoryReading`, or null when the device has no reader (always on iOS, macOS, Linux and Windows, and on a phone with no `\u002Fdev\u002Fkgsl-3d0`, a Mali GPU for one; an Adreno process that has not used the GPU yet gets zeros); it is not a `MemorySnapshot` field. Its `inAnonymousBytes` and `inFileBackedBytes` are already inside those two counters; to subtract the second from `fileBackedBytes`, take both back to back while idle and treat the difference as approximate, since two reads taken apart can make it negative. It covers only the GPU memory mapped into the process, and costs 0.2 to 0.4 s on the device tried: the kernel holds the process's `mmap_lock` while it builds `smaps`, so do not call it per frame or per token. It is a reading, not a delta: it includes the app's own rendering (about 6 MiB in a Flutter app), so take one before loading the model and subtract. `gpuMemory()`, `GpuMemoryReading` and `GpuMemorySource` are `@experimental`: using them draws the `experimental_member_use` analyzer warning (add `\u002F\u002F ignore: experimental_member_use` at the call site), and `GpuMemorySource` will gain values, so a `switch` over `reading.source` needs a default case.\n6. On Android and Linux `fileBackedBytes` is `Private_Clean + Shared_Clean`: resident clean pages (mapped files on a CPU backend, and GPU driver buffers on some GPU backends; on Adreno most of a GPU model's memory is a `\u002Fdev\u002Fkgsl-3d0` mapping, mostly clean pages, not the model file). It can also include clean anonymous pages, so a delta is not an exact count of model weights. Reclaimable file pages are not a kill threshold, but are not free: weights read on every token must be read back from storage if dropped, and lmkd can treat that refault thrashing as a reason to kill. On Linux GPU memory is in neither field: on an integrated GPU it is system RAM the snapshot does not show (FunctionGemma 270M: 700 to 835 MiB of Intel `drm-resident-system0`, device mappings 0 MiB). A page swapped out and read back lands in Private_Clean (512 MiB did, on Linux 7.0). On Windows it is `WorkingSetSize − PrivateWorkingSetSize`: the shareable working set, every resident page that is not private (mapped files and DLL pages, and modified shared pages too), so not model weights (a LiteRT-LM CPU model is mapped at load and faulted in by the first prompt; ORT-GenAI's weights land in the private working set instead); it is null on a Windows that does not fill the extended struct, and a private working set above the working set is a `MemoryReadException`. How much of a Windows GPU model's memory the snapshot holds is not measured (part of it may be in `anonymousBytes`), and `gpuMemory()` returns null there. iOS and macOS are null because the package does not read this value there yet.\n7. A snapshot walks kernel state: on Android the `\u002Fproc` reads are asynchronous (they do not block the isolate) but cost about 150 ms on a low-end device, and before Linux 5.10 they stall the process's mmap calls; on Linux about 3.7 ms per resident GiB (1.7 ms idle, 30 ms with 7 GiB resident, one machine); on iOS and macOS they are microsecond Mach calls; on Windows they are two `kernel32` calls, not timed. Take one at a few points — before loading, after loading, during generation — and never faster than about once a second, not on every frame or token.\n8. A pubspec section strips nothing from a release build. Put the package under `dev_dependencies` only when nothing in `lib\u002F` imports it.\n\n## Interpret resident clean pages\n\nGPU backends: on a GPU backend on Adreno, the driver's buffers are mapped through `\u002Fdev\u002Fkgsl-3d0` and are mostly clean pages, so they are counted here too. In one run on the vivo 1933 (Adreno 616, kernel 4.9) a Gemma 4 E2B GPU load raised that mapping from 6 to 981 MiB (988 after one prompt), matching `dumpsys meminfo`'s Gfx dev (989 MiB); about 115 MiB of it was dirty, which is in `anonymousBytes`, and all file mappings together (model, libraries, others) were about 260 MiB (Pss). With a GPU backend `fileBackedBytes` is therefore not a model-file figure: compare with a run of the same app on CPU, or subtract the `inFileBackedBytes` of a `FlutterEdgeAiDiagnostics.gpuMemory()` reading from `fileBackedBytes` (experimental, see rule 5). One device and one run each; other GPU drivers (Mali) were not measured.\n\nThe baseline includes every clean mapped file the process has touched. Take a reading before loading and subtract; shared pages count in full, not proportionally. Singly mapped dirty file pages are in Private_Dirty (inside `anonymousBytes`); Shared_Dirty is in neither field.\n\nClean anonymous pages can appear in Private_Clean, including pages read back from zram and not written since, and MADV_FREE pages. On zram's skip-swapcache path, pages can lose their swap slots and leave SwapPss. Under model-load pressure, cold heap memory can therefore move from `anonymousBytes` into `fileBackedBytes`. Interpret both counters together; neither alone measures all model memory or predicts an Android kill.\n\nWith version 0.2.2 on vivo 1933 (Android 11, kernel 4.9), Gemma 4 E2B `fileBackedBytes` in MiB was 103.6 → 800.5 → 1043.2 → 102.3 on CPU and 102.3 → 1390.3 → 1413.2 → 116.1 on GPU, measured before load, after load, after one prompt, and after close. The actual backend matched the request. `Private_Clean + Shared_Clean − (Rss − Anonymous)` was negative after load and after the prompt on both backends, so this run gave no positive lower bound for clean anonymous pages. It does not establish that none were present.\n\nOn iOS, TASK_VM_INFO has an `external` field; evaluating it is a follow-up. A null `fileBackedBytes` does not imply that iOS lacks such accounting.\n\n## Measure what a model costs\n\n```sh\nflutter pub add flutter_edge_ai flutter_edge_ai_litertlm flutter_edge_ai_diagnostics\n```\n\n```dart\nimport 'package:flutter\u002Ffoundation.dart';\nimport 'package:flutter_edge_ai\u002Fflutter_edge_ai.dart';\nimport 'package:flutter_edge_ai_diagnostics\u002Fflutter_edge_ai_diagnostics.dart';\n\nint? grew(MemorySnapshot before, MemorySnapshot after) {\n  if ((before.anonymousBytes, after.anonymousBytes)\n      case (final int from, final int to)) {\n    return to - from;\n  }\n  return null; \u002F\u002F the platform does not report it\n}\n\nFuture\u003CInferenceModel> loadAndMeasure() async {\n  if (!FlutterEdgeAiDiagnostics.isSupported) {\n    return FlutterEdgeAi.getActiveModel(maxTokens: 1024);\n  }\n  final before = await FlutterEdgeAiDiagnostics.memorySnapshot();\n  final model = await FlutterEdgeAi.getActiveModel(maxTokens: 1024);\n  final loaded = await FlutterEdgeAiDiagnostics.memorySnapshot();\n  debugPrint('model load: anonymousBytes delta ${grew(before, loaded)} bytes, '\n      '${loaded.availableBytes} still available');\n  return model;\n}\n```\n\nSample during generation at most once a second, not on each chunk:\n\n```dart\nFuture\u003CString> answerAndMeasure(InferenceModelSession session) async {\n  final reply = StringBuffer();\n  final sinceLast = Stopwatch()..start();\n  MemorySnapshot? peak;\n  await for (final chunk in session.getResponseAsync()) {\n    reply.write(chunk);\n    if (sinceLast.elapsed >= const Duration(seconds: 1) &&\n        FlutterEdgeAiDiagnostics.isSupported) {\n      sinceLast.reset();\n      final now = await FlutterEdgeAiDiagnostics.memorySnapshot();\n      if ((now.anonymousBytes ?? 0) > (peak?.anonymousBytes ?? 0)) peak = now;\n    }\n  }\n  debugPrint('highest sampled footprint: ${peak?.anonymousBytes}');\n  return reply.toString();\n}\n```\n\n## Null versus an exception\n\n```dart\nFuture\u003Cvoid> report() async {\n  try {\n    final s = await FlutterEdgeAiDiagnostics.memorySnapshot();\n    debugPrint('anonymous ${s.anonymousBytes ?? 'not reported here'}, '\n        'available ${s.availableBytes ?? 'not reported here'}');\n  } on MemoryReadException catch (e) {\n    \u002F\u002F The OS should have answered: a kernel, permission or I\u002FO error.\n    debugPrint('memory read failed: $e');\n    rethrow;\n  }\n}\n```\n\nA field is null in these cases:\n\n- `anonymousBytes` and `fileBackedBytes` on an Android or Linux kernel without `\u002Fproc\u002Fself\u002Fsmaps_rollup`. Mainline Linux added it in 4.14, but vendor kernels may backport it;\n- `fileBackedBytes` on iOS and macOS: this package does not read a corresponding value yet;\n- `availableBytes` always on macOS, which has no per-app limit, and on iOS when `os_proc_available_memory()` returns 0. Apple returns 0 both on the simulator, where no limit applies, and when the limit is already exceeded; the two cannot be told apart;\n- `fileBackedBytes` on a Windows that does not fill PrivateWorkingSetSize (the extended struct);\n- `anonymousPeakBytes` always on Android and Linux, and on an iOS or macOS version whose `task_info` reply predates the field.\n\n`gpuMemory()` returns null on iOS, macOS, Linux and Windows, and on an Android phone with no `\u002Fdev\u002Fkgsl-3d0` (a Mali GPU, for one; `existsSync` tests it, `typeSync` says not found); on an Adreno phone a process that has not used the GPU yet gets a zero reading; a missing or unparseable `\u002Fproc\u002Fself\u002Fsmaps` throws `MemoryReadException`; `outsideSnapshotBytes` is always null in this version.\n\n## Choosing a model for the device\n\nOn iOS, compare the growth you measured for a model with `availableBytes` before loading it: if the model needs more than the headroom, jetsam kills the app during load. Large models also need the memory entitlements listed in flutter-edge-ai-inference. Two of them change what you measure: **Increased Memory Limit** raises the jetsam limit, so `availableBytes` grows; **Extended Virtual Addressing** gives the app more address space to map the model and does not add headroom.\n\nOn Android there is no such number to compare against. Measure on the smallest device you support, and treat `availableBytes` as a best case. Include generation: a model whose weights repeatedly refault from storage can cause thrashing and contribute to an lmkd kill even though its file pages are reclaimable.\n\nOn macOS there is no per-app limit either, and `availableBytes` is null: `anonymousBytes` and `anonymousPeakBytes` say how much the app holds, so compare them with the Mac's physical memory.\n",{"name":5,"description":7},"main","723097aedd62adb1c52163fffe85259640c7f4fd","packages\u002Fflutter_edge_ai\u002Fskills\u002Fflutter-edge-ai-diagnostics",180,"https:\u002F\u002Fgithub.com\u002FDenisovAV\u002Fflutter_edge_ai","https:\u002F\u002Fflutteredge.ai","https:\u002F\u002Fgithub.com\u002FDenisovAV","Sasha is Flutter, Dart, Firebase and AI GDE, Co-organizer of Flutter Berlin Community, Expert in On-Device AI","2026-11-14 22:02:12",{"source":8,"skillName":5,"commands":57,"prompt":67,"zipAvailable":68},[58,61,64],{"tool":59,"command":60},"npx","npx skills add DenisovAV\u002Fflutter_edge_ai --skill flutter-edge-ai-diagnostics",{"tool":62,"command":63},"bunx","bunx skills add DenisovAV\u002Fflutter_edge_ai --skill flutter-edge-ai-diagnostics",{"tool":65,"command":66},"pnpm","pnpm dlx skills add DenisovAV\u002Fflutter_edge_ai --skill flutter-edge-ai-diagnostics","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FDenisovAV\u002Fflutter_edge_ai\u002Fblob\u002Fmain\u002Fpackages\u002Fflutter_edge_ai\u002Fskills\u002Fflutter-edge-ai-diagnostics\u002FSKILL.md",true,[],[71,86,97,113,131,144],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":82,"publishedAt":42},"01M6BXTT3TADZ7NN5RY79ZZKDR","send-email","Send an email.","https:\u002F\u002Fgithub.com\u002FDenisovAV\u002Fflutter_edge_ai\u002Fblob\u002Fmain\u002Fpackages\u002Fflutter_edge_ai_agent\u002Fassets\u002Fskills\u002Fsend-email\u002FSKILL.md",[77],{"categoryNo":78,"categoryName":79,"taxonomyType":80,"taxonomyTypeDesc":81},"01JBSEEDCAT000000000000005","邮件与沟通","SCENARIO","使用场景",[83,84,85],"send","send email","email",{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":42},"01M6BXTQPW2BAVZ2SRVTMFF9FA","query-wikipedia","Query summary from Wikipedia for a given topic.","https:\u002F\u002Fgithub.com\u002FDenisovAV\u002Fflutter_edge_ai\u002Fblob\u002Fmain\u002Fpackages\u002Fflutter_edge_ai_agent\u002Fassets\u002Fskills\u002Fquery-wikipedia\u002FSKILL.md",[],[93,94,95,25,96],"wikipedia","query","query wikipedia","summary",{"skillNo":98,"name":99,"nameZh":6,"description":100,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":101,"categories":102,"keywords":108,"publishedAt":42},"01M6BXTN6C4R4FZ5T9GRNY5MFG","qr-code","Generates a QR code for the given url.","https:\u002F\u002Fgithub.com\u002FDenisovAV\u002Fflutter_edge_ai\u002Fblob\u002Fmain\u002Fpackages\u002Fflutter_edge_ai_agent\u002Fassets\u002Fskills\u002Fqr-code\u002FSKILL.md",[103],{"categoryNo":104,"categoryName":105,"taxonomyType":106,"taxonomyTypeDesc":107},"01JBSEEDCAT000000000000030","开发工程师","PROFESSION","适用职业",[109,110,111,25,112],"qr","qr code","code","URL",{"skillNo":114,"name":115,"nameZh":6,"description":116,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":117,"categories":118,"keywords":119,"publishedAt":42},"01M6BXTJXNJNW59BV5JM3V9YZD","kitchen-adventure","Act as a dungeon master for a text-based adventure set in a world where everyone is a sentient kitchen appliance. Trigger when user says \"start kitchen adventure\".","https:\u002F\u002Fgithub.com\u002FDenisovAV\u002Fflutter_edge_ai\u002Fblob\u002Fmain\u002Fpackages\u002Fflutter_edge_ai_agent\u002Fassets\u002Fskills\u002Fkitchen-adventure\u002FSKILL.md",[],[120,24,121,25,122,123,124,125,126,127,128,129,130],"kitchen adventure","dungeon master","trigger","as","act","world","master","user","text","SET","start",{"skillNo":132,"name":133,"nameZh":6,"description":134,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":135,"categories":136,"keywords":137,"publishedAt":42},"01M6BXTGEPGG025VBEQKPJZB8S","interactive-map","Show an interactive map view for the given location.","https:\u002F\u002Fgithub.com\u002FDenisovAV\u002Fflutter_edge_ai\u002Fblob\u002Fmain\u002Fpackages\u002Fflutter_edge_ai_agent\u002Fassets\u002Fskills\u002Finteractive-map\u002FSKILL.md",[],[138,139,140,141,142,143,25],"interactive map","interactive","map","view","show","location",{"skillNo":145,"name":146,"nameZh":6,"description":147,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":148,"categories":149,"keywords":150,"publishedAt":42},"01M6BXTED45RFKX4EYF9BSWC7H","get-current-time","Get the user's current local date, time, and day of the week.","https:\u002F\u002Fgithub.com\u002FDenisovAV\u002Fflutter_edge_ai\u002Fblob\u002Fmain\u002Fpackages\u002Fflutter_edge_ai_agent\u002Fassets\u002Fskills\u002Fget-current-time\u002FSKILL.md",[],[151,152,153,154,127,155],"current time","get current time","time","get","local"]