embedit
CLI line editing for embedded devices
embedit
is a Go module for reading and editing a line of input (similar to readline). The principle design goals are:
- Usable with standard Go and TinyGo
- No dynamic memory allocation (see analysis below)
- For operation on baremetal and embedded systems such as microcontrollers
- Minimal dependencies (no
fmt
, strconv
, or any third-party packages)
- Required to guarantee goals 1 & 2
Much of the original source code was based on golang.org/x/term
by the standard Go authors.
Usage
See examples
for a few different usages. The following gif shows examples/basic
in action.
Heap Profile
The following tools are used to verify no dynamic memory allocation is performed:
- pprof from standard Go
- trace from standard Go
- TinyGo's built-in escape analysis compile-time option (
-print-allocs
)
The last is straight-forward, so only pprof
and trace
are discussed here.
The examples/analysis
demo is used to exercise the package API. Different build tags will configure the individual profiling tools. See the comments in examples/analysis/main.go
for details.
So far, runtime heap allocation can only be eliminated from the package code and its direct dependencies. In standard Go, the runtime itself will perform heap allocation internally to create and manage core goroutines and system threads (e.g., G
s and M
s).
The following graph shows the total heap memory allocated throughout the lifetime of the program.
As you can see, most of the memory is attributed to the internal runtime constructs mentioned above. All remaining allocations are related to the main package of the analysis
example such as the profiler tooling and command-line flag parser. None of these are directly related to the embedit
package itself.