diskio

package
v0.186.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package diskio says which of the daemon's work read its disk.

The footprint's disk reads are one counter for the whole process (procstat.SelfDiskIO): the doctor could say the daemon read 4 GB in an hour but not what read it, and the slow-query log names only the statements that took long, which was not where most of it went (the owner's daemon, 2026-11-21). This package splits that counter by source.

The split is by what was running when the bytes were read. Every statement the store runs, and every read the transcript tailers and the other file readers make, is an operation with a source name; at each operation's start and end the process counter is read once, and what it moved since the last reading goes to the operations in flight in that interval, in equal shares — to "unattributed" when none was. The shares add up to the process counter, so nothing is invented and nothing is lost, but two sources running at once split what either of them read: a source is exact when it runs alone and an even split of an overlap otherwise. Reads made by code with no operation around it while another operation runs land on that operation, which is why the list carries "unattributed": when it is large, something that reads is not counted.

File readers also count the bytes they asked for (logical): a re-read of a file the OS still holds costs the disk nothing, so a source with high logical and low disk bytes is re-reading, not hurting yet.

The cost is one counter read (a single system call) and a mutex per operation boundary; nothing is written anywhere.

Index

Constants

View Source
const Unattributed = "unattributed"

Unattributed is the source of reads made while no operation was running.

Variables

This section is empty.

Functions

func Begin

func Begin(name string) (end func())

Begin starts an operation of source name; the function it returns ends it and must be called exactly once.

func OpenSQL

func OpenSQL(name, driverName, dsn string) (*sql.DB, error)

OpenSQL is sql.Open(driverName, dsn) with every query and statement an operation of source name: for the other programs' databases the daemon reads (Cursor's, OpenCode's, Hermes's, Codex's), each one source. The daemon's own database counts per asking function instead (internal/store/slowlog.go).

func ReadFile

func ReadFile(name, path string) ([]byte, error)

ReadFile is os.ReadFile as one operation of source name.

func Reader

func Reader(name string, r io.Reader) io.Reader

Reader wraps r so that each Read is an operation of source name and the bytes it returns count as that source's logical bytes.

func Snapshot

func Snapshot() map[string]Source

Snapshot is every source's totals since the process started, by name.

func Sort

func Sort(s []Source)

Sort orders sources by disk bytes, then logical bytes, then name.

Types

type File

type File struct {
	*os.File
	// contains filtered or unexported fields
}

File is an open file whose reads are operations of one source.

func Open

func Open(name, path string) (*File, error)

Open is os.Open with every read of the file an operation of source name.

func (*File) Read

func (f *File) Read(p []byte) (int, error)

func (*File) ReadAt

func (f *File) ReadAt(p []byte, off int64) (int, error)

ReadAt is counted as Read is.

func (*File) WriteTo

func (f *File) WriteTo(w io.Writer) (int64, error)

WriteTo goes through Read, so io.Copy from a File is counted: the *os.File one it would otherwise promote copies without calling Read.

type Source

type Source struct {
	Name string `json:"source"`
	// ReadBytes is the share of the process's storage reads made while this
	// source's operations ran.
	ReadBytes uint64 `json:"read_bytes"`
	// LogicalBytes is what a file reader asked for, page cache hits
	// included; 0 for a source that is not a file reader.
	LogicalBytes uint64 `json:"logical_bytes,omitempty"`
	// Ops is how many operations ran.
	Ops uint64 `json:"ops"`
}

Source is one source's running totals since the process started.

func Delta

func Delta(before, after map[string]Source) []Source

Delta is one source's totals between two snapshots.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL