Report infrastructure for collecting data in GT
Some problems in a GT image only show while they happen: a slow UI, a process that hangs, many garbage collections, memory that grows. A report captures such a moment as plain data, so that it can be looked at later, possibly in another image than the one where it happened.
The infrastructure keeps four things apart, because they change for different reasons: what is recorded (the report), how and when it is recorded (the recorder), where it is kept (the store), and how it is found and read again (the metadata). Recording reports is on GT reports available for data collection, analysing them on Analysing stored GT reports. The classes are in GToolkit-Utility-SpaceTally, GToolkit-Utility-GarbageCollectAnalysis and GToolkit-Utility-Basic.
| Piece | Classes | Responsibility | Why it is separate |
|---|---|---|---|
| Report |
GtProcessesReport
, GtMessageTallyReport
, GtGarbageCollectsReport
, GtSpaceTallyReport
|
the recorded data, its image data and its report uid; writes its own files (#selector
) and reads itself back (#selector
)
|
a report is a plain object: create it, inspect it, and only then decide whether to store it |
| Image data |
GtReportImageData
|
the GT, GT VM, Pharo VM and Pharo image versions | every report says which image it came from, without identifying the user or the machine |
| Recorder |
GtReportRecorder
and its subclasses
|
how one kind of report is recorded: #selector
(the time-sensitive part) and #selector
(the slow part)
|
the same report can be recorded with other settings or other image data |
| Recording |
GtReportRecording
|
one background run of a recorder into a store; announces its start and end (GtReportRecordingStarted
, GtReportRecordingEnded
); holds the report and the entry, or the error
|
recording must not block the UI, and a Message Tally must see what the UI does |
| Store |
GtReportsStore
: GtReportsLocalStore
, GtReportsCompositeStore
, GtNoReportsStore
|
where reports go: the folder layout, the storage id, writing text and bytes (#selector
, #selector
)
|
a report does not know where it is kept |
| Entry |
GtReportsStoreEntry
with GtReportsStoreDataFile
and GtReportsStoreMetadataFile
|
one stored copy: its folder, the files written (size and write time) and the metadata | shows what was written, without keeping the contents in memory |
| Metadata |
GtReportMetadata
, GtReportFileDescription
|
meta.json: report type, class and alias, report uid, storage id, machine name, image data, files with their sizes, format version
|
reports can be found, grouped and sized without reading their data |
| Reading back |
GtStoredReportFiles
and the report's class-side #selector
|
turns a stored folder back into the report object | an analysis works on the same objects that were recorded |
Recording. #selector
on a recorder starts a recording (#selector
). The recording runs #selector
at the recording priority, above the UI (#selector
); then it lowers its own priority to background and runs #selector
and #selector
(#selector
). #selector
does the same synchronously, without storing.
Storing. #selector
on a report asks the store to store it (#selector
): the store creates an entry with a new storage id (#selector
), the report writes its files into the entry (#selector
), and the entry writes meta.json last (#selector
). Every write goes through the entry, which records the file with the number of bytes the store read back from the written file (#selector
). A composite store creates one entry per store with the same storage id (#selector
), so every store gets the same folder name.
Reading back. GtStoredReportFiles
#selector
reads meta.json; #selector
takes the report class from the metadata (#selector
) and asks it for #selector
. The folder layout and the content of meta.json are described under
Where reports are stored
on GT reports available for data collection.
- No common report superclass. Reports have little in common beyond a small protocol:
#selector,#selector,#selector,#selector,#selectorand the class-side#selector. Each report implements it, so a new report does not have to fit a hierarchy. - Recording in two steps.
#selectormust be quick and runs high, so that a busy UI does not delay it; completing and storing are slow and run at background priority, so that the UI stays usable meanwhile (#selector). Only one Message Tally can run at a time. meta.jsonis written last (#selector). A folder without it is an interrupted write, never a report.- Report type first in the layout (
#selector). Most questions start from a kind of report. A store that keeps the reports of several machines can add a machine level to the layout; it gets the machine name for every report (#selector). Ids and date folders are in UTC, so that images in different time zones sort together. - No identifying data in GT.
GtReportImageDataholds only versions and an empty machine name (#selector); a subclass can add more where that is wanted, and a recorder decides which image data its reports get (#selector). - Two ids. The storage id names one stored copy (
#selector). The report uid is aUUIDgiven in the report's#selectorand kept by every copy, so copies can be recognised and analysed once. - Class name plus alias. The metadata names the report class (
#selector), to read the report back, and its#selectoras a stable alias (#selector), to read it back after the class is renamed. - Nothing large in memory. Entries keep where and how much was written, not what (
GtReportsStoreFile); the sizes come from the written files. - The format version is a label. Every
meta.jsoncarries#selector(#selector); no code branches on it yet. When the format changes, read the version from the plain JSON first and pick a reader for it, becauseLeJsonV4reads the file into the current class before the version is known.
- Write the report class, without a superclass, following
GtProcessesReport:
- slots for the data, plus imageData and reportUid; in #selector
set imageData := GtReportImageData new (GtReportImageData
) and reportUid := UUID new;
- #selector
answers the folder name, lowercase with dashes;
- #selector
writes the files: #selector
for most reports, #selector
for text, #selector
for large object graphs, #selector
for several files of one kind;
- the class-side #selector
reads them back (#selector
, #selector
, #selector
, #selector
);
- the class-side #selector
gives a stable name; run LeJsonV4
#selector
after adding it or after changing slots. The JSON reader sets every written slot through a setter of the same name, so each one needs a setter (e.g. #selector
); a class-side leJsonV4AttributeMapping leaves out slots that must not be written (like the live tally of GtMessageTallyReport>>#leJsonV4AttributeMapping
);
- #selector
answers aStore store: self; add #selector
and a summary view, so that the report is useful in the inspector before it is stored.
- Write a recorder only when recording needs settings or must run in the background: subclass
GtReportRecorderand implement#selector, plus#selectorfor slow work (e.g.GtMessageTallyReportRecorder). - Check it with examples that store the report in a memory store (
GtReportsLocalStore#selectorwithFileSystem memory root / 'gt-reports') and read it back (seeGtReportsStoreExamplesandGtStoredReportFilesExamples). - Document it: add a section to GT reports available for data collection, with one sentence on what the report shows, a snippet that creates it and one that stores it.
The smallest report, as a sketch (accessors and views left out):
Object << #GtExampleDataReport
slots: { #values . #imageData . #reportUid };
package: 'GToolkit-Utility-SpaceTally'
GtExampleDataReport >> initialize
super initialize.
values := #().
imageData := GtReportImageData new.
reportUid := UUID new
GtExampleDataReport >> reportType
^ 'example-data'
GtExampleDataReport >> writeFilesTo: anEntry
anEntry writeJsonOf: self
GtExampleDataReport >> storeIn: aStore
^ aStore store: self
GtExampleDataReport class >> leJsonV4Name
^ #gtExampleDataReport
GtExampleDataReport class >> fromStoredFiles: aStoredReportFiles
^ aStoredReportFiles readJson
A store decides where reports go, for example a remote file service. Subclass GtReportsStore
and implement:
#selector: the root of the layout, any object that answers/like a file reference;#selectorand#selector: write the text or bytes and answer the number of bytes written, read back from the written file (as#selectordoes), because that number goes into the metadata;#selector: a short name shown in the entries and recordings;- optionally
#selectorand#selector, to add a machine level to the layout.
The entries, file objects, metadata and composite stores then work without changes.