DataLog
- class wpilog.DataLog
Bases:
pybind11_objectA data log for high-speed writing of data values.
The lifetime of the data log object must be longer than any data log entry objects that refer to it.
Finish() is needed only to indicate in the log that a particular entry is no longer being used (it releases the name to ID mapping). Finish() is not required to be called for data to be flushed to disk; entries in the log are written as Append() calls are being made. In fact, Finish() does not need to be called at all; this is helpful to avoid shutdown races where the DataLog object might be destroyed before other objects. It’s often not a good idea to call Finish() from destructors for this reason.
DataLog calls are thread safe. DataLog uses a typical multiple-supplier, single-consumer setup. Writes to the log are atomic, but there is no guaranteed order in the log when multiple threads are writing to it; whichever thread grabs the write mutex first will get written first. For this reason (as well as the fact that timestamps can be set to arbitrary values), records in the log are not guaranteed to be sorted by timestamp.
- addSchema(*args, **kwargs)
Overloaded function.
addSchema(self: wpilog._wpilog.DataLog, name: str, type: str, schema: Buffer, timestamp: typing.SupportsInt | typing.SupportsIndex = 0) -> None
Registers a data schema. Data schemas provide information for how a certain data type string can be decoded. The type string of a data schema indicates the type of the schema itself (e.g. “protobuf” for protobuf schemas, “struct” for struct schemas, etc). In the data log, schemas are saved just like normal records, with the name being generated from the provided name: “/.schema/<name>”. Duplicate calls to this function with the same name are silently ignored.
- Parameters:
name – Name (the string passed as the data type for records using this schema)
type – Type of schema (e.g. “protobuf”, “struct”, etc)
schema – Schema data
timestamp – Time stamp (may be 0 to indicate now)
addSchema(self: wpilog._wpilog.DataLog, name: str, type: str, schema: str, timestamp: typing.SupportsInt | typing.SupportsIndex = 0) -> None
Registers a data schema. Data schemas provide information for how a certain data type string can be decoded. The type string of a data schema indicates the type of the schema itself (e.g. “protobuf” for protobuf schemas, “struct” for struct schemas, etc). In the data log, schemas are saved just like normal records, with the name being generated from the provided name: “/.schema/<name>”. Duplicate calls to this function with the same name are silently ignored.
- Parameters:
name – Name (the string passed as the data type for records using this schema)
type – Type of schema (e.g. “protobuf”, “struct”, etc)
schema – Schema data
timestamp – Time stamp (may be 0 to indicate now)
- addStructSchema(type: type, timestamp: SupportsInt | SupportsIndex = 0) None
Registers a struct schema. Duplicate calls to this function with the same name are silently ignored.
@tparam T struct serializable type
- Parameters:
type – optional struct type info
timestamp – Time stamp (0 to indicate now)
- appendBoolean(entry: SupportsInt | SupportsIndex, value: bool, timestamp: SupportsInt | SupportsIndex) None
Appends a boolean record to the log.
- Parameters:
entry – Entry index, as returned by Start()
value – Boolean value to record
timestamp – Time stamp (may be 0 to indicate now)
- appendBooleanArray(entry: SupportsInt | SupportsIndex, arr: List[bool], timestamp: SupportsInt | SupportsIndex) None
Appends a boolean array record to the log.
- Parameters:
entry – Entry index, as returned by Start()
arr – Boolean array to record
timestamp – Time stamp (may be 0 to indicate now)
- appendDouble(entry: SupportsInt | SupportsIndex, value: SupportsFloat | SupportsIndex, timestamp: SupportsInt | SupportsIndex) None
Appends a double record to the log.
- Parameters:
entry – Entry index, as returned by Start()
value – Double value to record
timestamp – Time stamp (may be 0 to indicate now)
- appendDoubleArray(entry: SupportsInt | SupportsIndex, arr: List[SupportsFloat | SupportsIndex], timestamp: SupportsInt | SupportsIndex) None
Appends a double array record to the log.
- Parameters:
entry – Entry index, as returned by Start()
arr – Double array to record
timestamp – Time stamp (may be 0 to indicate now)
- appendFloat(entry: SupportsInt | SupportsIndex, value: SupportsFloat | SupportsIndex, timestamp: SupportsInt | SupportsIndex) None
Appends a float record to the log.
- Parameters:
entry – Entry index, as returned by Start()
value – Float value to record
timestamp – Time stamp (may be 0 to indicate now)
- appendFloatArray(entry: SupportsInt | SupportsIndex, arr: List[SupportsFloat | SupportsIndex], timestamp: SupportsInt | SupportsIndex) None
Appends a float array record to the log.
- Parameters:
entry – Entry index, as returned by Start()
arr – Float array to record
timestamp – Time stamp (may be 0 to indicate now)
- appendInteger(entry: SupportsInt | SupportsIndex, value: SupportsInt | SupportsIndex, timestamp: SupportsInt | SupportsIndex) None
Appends an integer record to the log.
- Parameters:
entry – Entry index, as returned by Start()
value – Integer value to record
timestamp – Time stamp (may be 0 to indicate now)
- appendIntegerArray(entry: SupportsInt | SupportsIndex, arr: List[SupportsInt | SupportsIndex], timestamp: SupportsInt | SupportsIndex) None
Appends an integer array record to the log.
- Parameters:
entry – Entry index, as returned by Start()
arr – Integer array to record
timestamp – Time stamp (may be 0 to indicate now)
- appendRaw(entry: SupportsInt | SupportsIndex, data: Buffer, timestamp: SupportsInt | SupportsIndex) None
Appends a raw record to the log.
- Parameters:
entry – Entry index, as returned by Start()
data – Byte array to record
timestamp – Time stamp (may be 0 to indicate now)
- appendRaw2(entry: SupportsInt | SupportsIndex, data: List[Buffer], timestamp: SupportsInt | SupportsIndex) None
Appends a raw record to the log.
- Parameters:
entry – Entry index, as returned by Start()
data – Byte array to record
timestamp – Time stamp (may be 0 to indicate now)
- appendString(entry: SupportsInt | SupportsIndex, value: str, timestamp: SupportsInt | SupportsIndex) None
Appends a string record to the log.
- Parameters:
entry – Entry index, as returned by Start()
value – String value to record
timestamp – Time stamp (may be 0 to indicate now)
- appendStringArray(entry: SupportsInt | SupportsIndex, arr: List[str], timestamp: SupportsInt | SupportsIndex) None
Appends a string array record to the log.
- Parameters:
entry – Entry index, as returned by Start()
arr – String array to record
timestamp – Time stamp (may be 0 to indicate now)
- finish(entry: SupportsInt | SupportsIndex, timestamp: SupportsInt | SupportsIndex = 0) None
Finish an entry.
- Parameters:
entry – Entry index
timestamp – Time stamp (may be 0 to indicate now)
- flush() None
Explicitly flushes the log data to disk.
- hasSchema(name: str) bool
Returns whether there is a data schema already registered with the given name.
- Parameters:
name – Name (the string passed as the data type for records using this schema)
- Returns:
True if schema already registered
- pause() None
Pauses appending of data records to the log. While paused, no data records are saved (e.g. AppendX is a no-op). Has no effect on entry starts / finishes / metadata changes.
- resume() None
Resumes appending of data records to the log.
- setMetadata(entry: SupportsInt | SupportsIndex, metadata: str, timestamp: SupportsInt | SupportsIndex = 0) None
Updates the metadata for an entry.
- Parameters:
entry – Entry index
metadata – New metadata for the entry
timestamp – Time stamp (may be 0 to indicate now)
- start(name: str, type: str, metadata: str = '', timestamp: SupportsInt | SupportsIndex = 0) int
Start an entry. Duplicate names are allowed (with the same type), and result in the same index being returned (Start/Finish are reference counted). A duplicate name with a different type will result in an error message being printed to the console and 0 being returned (which will be ignored by the Append functions).
- Parameters:
name – Name
type – Data type
metadata – Initial metadata (e.g. data properties)
timestamp – Time stamp (may be 0 to indicate now)
- Returns:
Entry index
- stop() None
Stops appending start/metadata/schema records to the log.