-
-
Notifications
You must be signed in to change notification settings - Fork 90
library: Add Memory Monitor entry #508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using Gtk 4.0; | ||
| using Adw 1; | ||
|
|
||
| Adw.StatusPage { | ||
| title: _("Memory Monitor"); | ||
| description: _("Monitor system memory"); | ||
|
|
||
| LinkButton { | ||
| label: "API Reference"; | ||
| uri: "https://docs.gtk.org/gio/iface.MemoryMonitor.html"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import Gio from "gi://Gio"; | ||
|
|
||
| const memory_monitor = Gio.MemoryMonitor.dup_default(); | ||
|
|
||
| const cache = new Map(); | ||
| cache.set("a", 1); | ||
| cache.set("b", 2); | ||
| cache.set("c", 3); | ||
|
|
||
| memory_monitor.connect("low-memory-warning", (monitor, level) => { | ||
| // Use inequalities for checking as new levels may be added in the future | ||
| if (level >= Gio.MemoryMonitorWarningLevel.LOW) { | ||
| // Processes should free up unneeded resources | ||
| console.log("Warning Level: Low"); | ||
| drop_caches(); | ||
| } else if (level >= Gio.MemoryMonitorWarningLevel.MEDIUM) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This example is great overall! One comment: this should perhaps be a separate
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually wait, now that I think about it, won't it behave in a completely oppositive manner? For all levels |
||
| // Processes should try harder to free up unneeded resources | ||
| console.log("Warning Level: Medium"); | ||
| } else if (level >= Gio.MemoryMonitorWarningLevel.CRITICAL) { | ||
| // system will start terminating processes to reclaim memory | ||
| console.log("Warning Level: Critical"); | ||
| } | ||
| }); | ||
|
|
||
| function drop_caches() { | ||
| cache.clear(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "category": "platform", | ||
| "description": "Monitor system memory", | ||
| "panels": ["code", "preview"], | ||
| "autorun": true | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.