The entry monitor
The source src/modules/system/monitor built with the setting DRAWING_THROUGH_MODULE=true. The text after this paragraph is the comment of that source.
A system tool: the memory of the machine and the processes that run, as a picture that changes twice per second. It needs the grant to inspect the machine.
It is also a service: processes(), counts() and count() give the same facts as tables of records (exports.odin).
What it is for. It shows what the machine does now, from the reports of the kernel and not from a process that counts for itself. Three metric cards at the top: the memory in use, of all and reserved; the processor time of all the processes, the processes and the processors; the kernel entries, the interrupts and the waits of the locks of the kernel. Under them, three graph cards of the last minute (the memory in use, the processor time of all the processes, the kernel entries in one second), each with its value now and its peak. Last, the table of the processes: one row for each process with its pages and its share of the processor in the last half second. A gauge takes the color of its intensity step: the color of what it measures, the warning color from 60 %, and the color of a measure near its limit from 85 %. A disk process shows its nickname, with the hash prefix of its file faded under it, from the disk process page of the root service; the log has one line for each one: "monitor: the disk process visitor, hash prefix 5f0c…, the file 5f0c…, from the root service". The export processes() gives the whole hash of the file in the field hash.
Start: the bar of the desktop, or start("monitor") in the console. The log has "monitor: ok" after the first picture. From the console, connect("monitor"), then monitor.processes() or monitor.count("free pages").
Grants, as the root service gives them:
- Inspect: the machine with the right Inspect, for the system report and the report of each process. With no such grant, the window says "no grant to inspect the machine" and the log has the same line.
- Serve: its exports, for the console and for the host through the remote service.
With the right Inspect the root service also maps the disk process page, read-only: no handle and no right to act.
What it does not prove: the share of a process is its processor time over the elapsed time of one processor, so a process with several threads on several processors shows 100% at most.
monitor module with an entry
- Hash
3b40c400484cf80c009c6f6594e0e45dd93a41bc8be48d6e65e2d8534f94b17c- Size
235731 bytes- Exports
5- Imports
1- Imported by
0- License
- MIT
A system tool: the memory of the machine and the processes that run, as a picture that changes twice per second
| Fact | Value |
|---|---|
| Kind | Modules with an entry |
| Source | src/modules/system/monitor |
| Boot image | yes: in the boot image, 235731 bytes in this build |
| Build settings |
|
| Imports | |
| Imported by | none |
Neighbours
What it imports, at its left, and what imports it, at its right: the part of the module graph that touches it.
Exports
| Export | What it does |
|---|---|
processes() -> Table(Process) | gives one row for each process that runs, from the reports of the kernel: its slot, its name, its state, the stop cause of a stopped process and the stop outcome of a process that stopped itself, its resident pages (the mapped pages with a page frame) and its mapped pages, its handles, threads, processor time in milliseconds, kernel entries, the time of its start in microseconds, and the hash of the file of a disk process |
counts() -> Table(Count) | gives one row for each count of the machine that the kernel reports: the time, the pages, the free pages, the reserved pages, the memory objects, the processes, the processors, the kernel entries, the interrupts, the page faults of a first use, and the takes and the waits of the locks of the kernel, the scheduling strategy (its number, and its name as the unit) and its changes |
count(name: Text) -> Integer | gives one count of the machine by its name, as counts() names it: count("free pages") |
counts_named(names: Table(Count_Name, Read), details: Table(Error_Record, Append)) -> Table(Count) | gives the counts of the machine that a table of names names, in the order of the table: many counts in one call |
served() -> Served | gives what the monitor did as a service: the calls that it executed, the connections that it has now, and the pictures of its window |
entry() | The entry of the monitor: it opens its window and its service, then draws a picture of the machine every 500 ms and runs the calls between two pictures |
processes
processes() -> ()
processes gives one row for each process that runs, from the reports of the kernel: its slot, its name, its state, the stop cause of a stopped process and the stop outcome of a process that stopped itself, its resident pages (the mapped pages with a page frame) and its mapped pages, its handles, threads, processor time in milliseconds, kernel entries, the time of its start in microseconds, and the hash of the file of a disk process.
The monitor asks the kernel for the report of each process slot, and skips a slot with no process. A stopped process that its parent has not closed yet has a row, with the state stopped.
A process that the root service started from a disk has its nickname as its name, and the whole hash of its module file in hash: 64 hexadecimal digits, from the disk process page that the root service writes, as the window of the monitor shows them. Each other process has an empty hash, also a process with the name of a disk process.
- result: a table of
Processrows that the call fills. A table shorter than the count gets the first rows only; the result still counts every process.
The result is the count of processes, or a negative number with an error record:
No_Grant(-1): the caller does not act for the principal. A process sees no other process, so only the console and the host through the remote service get rows.Refused(-2): the kernel refused the system report to the monitor; the record holds its status. This comes when the grant Inspect of the monitor was revoked.
Example, in the console after connect("monitor"): monitor.processes(), or where(monitor.processes(), threads = 2) to keep the rows of a column value, or where(monitor.processes(), cause = "a fault") for the processes that a fault stopped, or where(monitor.processes(), outcome = "failed") for the processes that stopped and said that their work failed, or columns(where(monitor.processes(), name = "visitor"), name, hash) for the file of a disk process.
- none
()- When it fails
- a negative result, and the error record
src/modules/system/monitor/exports.odin:121
counts
counts() -> ()
counts gives one row for each count of the machine that the kernel reports: the time, the pages, the free pages, the reserved pages, the memory objects, the processes, the processors, the kernel entries, the interrupts, the page faults of a first use, and the takes and the waits of the locks of the kernel, the scheduling strategy (its number, and its name as the unit) and its changes.
Each row is a Count: a name, a value and a unit ("free pages", 12345, "pages"). The names are the names that count and counts_named take. The counts of the locks add the takes and the waits of every kind of lock. The count "processes" counts the slots in use, stopped processes included.
- result: a table of
Countrows; the call fills at most its length.
The result is the count of rows, or a negative number with an error record:
No_Grant(-1): the caller does not act for the principal.Refused(-2): the kernel refused the system report; the record holds its status.
- none
()- When it fails
- a negative result, and the error record
src/modules/system/monitor/exports.odin:191
count
count(name: ) ->
count gives one count of the machine by its name, as counts() names it: count("free pages").
It reads all the counts, as counts does, and gives the value of one of them: a caller that needs one number needs no table.
- name: the name of a count, as the first column of
counts()gives it, 23 bytes at most. The match is exact.
The result is the value of the count, or a negative number with an error record:
No_Grant(-1): the caller does not act for the principal.Refused(-2): the kernel refused the system report.Absent(-3): no count has this name, or the name is longer than 23 bytes.
Example: monitor.count("kernel entries").
name:
- When it fails
- a negative result, and the error record
src/modules/system/monitor/exports.odin:219
counts_named
counts_named(names: (, Read), details: (, Append)) -> ()
counts_named gives the counts of the machine that a table of names names, in the order of the table: many counts in one call.
It is the form of count for several names: one call, one read of the reports, and the values of one moment.
- names: a table of
Count_Namerows, each a name ascounts()gives it. - details: a table of error details, or none. With a table, the call checks every row and appends one
Absentdetail for each row that names no count, in the order of the rows. With no table, it stops at the first such row. - result: a table of
Countrows, in the order of the names; row n answers name n.
The result is the count of names, or a negative number with an error record:
No_Grant(-1): the caller does not act for the principal.Refused(-2): the kernel refused the system report.Absent(-3): a name names no count. The value found of the record is the number of its row, from 1; with a table of details, the record is the first of them.
names: (, Read)details: (, Append)
()- When it fails
- a negative result, and the error record
src/modules/system/monitor/exports.odin:260
served
served() ->
served gives what the monitor did as a service: the calls that it executed, the connections that it has now, and the pictures of its window.
These are facts of the monitor itself, not of other processes: each caller sees them, with no grant to act for the principal. The test of the calls from the host reads calls before and after a call over a link that loses datagrams: the count grows by one, so the call ran one time.
- result: one
Servedrecord:calls,callers,pictures.
It never fails.
entry
entry()
The entry of the monitor: it opens its window and its service, then draws a picture of the machine every 500 ms and runs the calls between two pictures.
With no window it stops with Failed. Each turn of the loop:
- 1. asks the kernel for the system report, then the report of each process slot that is in use;
- 2. draws the surfaces of the cards and one row for each process, adds the values of the sample to the sample history of each graph, then draws the metric cards and the graphs; the first picture writes "monitor: ok";
- 3. waits until the next picture, and runs each call of a caller as it comes: a caller never waits for a picture.
The monitor never stops by itself.
- Form
- The entry of the module: one parameter, an address, fixed by the contract.
src/modules/system/monitor/main.odin:617
Read from the source of the module, as the build reads it to describe the exports (tools/modustool/build/describe.odin).
What the root service gives it
| What | Value | As the root service says |
|---|---|---|
| Grants | It serves processes() and counts() to a caller that acts for the principal. It starts at its first connection, so the table of the processes needs no start of its own, in each start policy, the rescue included. | |
| Other terms of its start grant set | on_demand = true | |
| Budget that it asks for |
| The least budget of 2048 pages, in which it ran before it stated its window, less that window at the scale 1 (650 pages): its module, its stack, its tables and its glyph memory. The tool counts the window at the largest scale. See: Module contract: The budget that a module asks for |
The start grant set is read from start_grant_sets in src/modules/system/root/start_grant_sets.odin. The stated budget is read from the constant MODULE_BUDGET of the source of the module (its line); the build adds the counted parts and writes the sum in the module (tools/modustool/build/budget_count.odin); the root service accepts it up to the largest budget of a process, and adds the limits of processor time and of log records (src/modules/system/root/budgets.odin).
Table wire form
A wire form of the module contract: one word of a call. Records of one description that follow each other (a table).
Process record of a module
A record of the module monitor: 256 bytes, aligned on 8 bytes, 0 bytes of padding.
sloti6408 bytesnameText(32)832 bytesstateText(8)408 bytescauseText(40)4840 bytesoutcomeText(24)8824 bytesresidenti641128 bytesmappedi641208 byteshandlesi641288 bytes
and 8 more
Error_Record record of a module
A record of the module monitor: 56 bytes, aligned on 8 bytes, 0 bytes of padding.
kindi6408 bytesuniti6488 bytesoperationi64168 bytesargumenti64248 bytesvaluei64328 byteslimiti64408 bytesfoundi64488 bytes
Count record of a module
A record of the module monitor: 48 bytes, aligned on 8 bytes, 0 bytes of padding.
nameText(24)024 bytesvaluei64248 bytesunitText(16)3216 bytes
Text wire form
A wire form of the module contract: one word of a call. The address of a slice record {address, count} of UTF-8 bytes.
Integer wire form
A wire form of the module contract: one word of a call. A signed integer of 64 bits, in a register.
Count_Name record of a module
A record of the module monitor: 24 bytes, aligned on 1 bytes, 0 bytes of padding.
nameText(24)024 bytes
Served record of a module
A record of the module monitor: 24 bytes, aligned on 8 bytes, 0 bytes of padding.
callsi6408 bytescallersi6488 bytespicturesi64168 bytes
Error_Record struct
A struct of the package errors: 56 bytes, aligned on 8 bytes, 0 bytes of padding. The error record: what a call that failed says about why, as seven integers.
kindi6408 bytesuniti6488 bytesoperationi64168 bytesargumenti64248 bytesvaluei64328 byteslimiti64408 bytesfoundi64488 bytes
processes procedure of the package monitor
processes :: proc "c" (result: ^[]Process, error: ^errors.) -> i64
processes gives one row for each process that runs, from the reports of the kernel: its slot, its name, its state, the stop cause of a stopped process and the stop outcome of a process that stopped itself, its resident pages (the mapped pages with a page frame) and its mapped pages, its handles, threads, processor time in milliseconds, kernel entries, the time of its start in microseconds, and the hash of the file of a disk process.
Count type of the package monitor
Count :: struct {...}
One row for each count of the machine: counts().
Count_Name type of the package monitor
Count_Name :: struct {...}
The name of one count: a row of the table of counts_named().
