Class DataLog
- All Implemented Interfaces:
AutoCloseable
public final class DataLog extends Object implements AutoCloseable
The data log is periodically flushed to disk. It can also be explicitly flushed to disk by using the flush() function.
The finish() function is needed only to indicate in the log that a particular entry is no longer being used (it releases the name to ID mapping). The finish() function 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.
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.
-
Constructor Summary
Constructors Constructor Description DataLog()
Construct a new Data Log.DataLog(String dir)
Construct a new Data Log.DataLog(String dir, String filename)
Construct a new Data Log.DataLog(String dir, String filename, double period)
Construct a new Data Log.DataLog(String dir, String filename, double period, String extraHeader)
Construct a new Data Log. -
Method Summary
Modifier and Type Method Description void
appendBoolean(int entry, boolean value, long timestamp)
void
appendBooleanArray(int entry, boolean[] arr, long timestamp)
void
appendDouble(int entry, double value, long timestamp)
void
appendDoubleArray(int entry, double[] arr, long timestamp)
void
appendFloat(int entry, float value, long timestamp)
void
appendFloatArray(int entry, float[] arr, long timestamp)
void
appendInteger(int entry, long value, long timestamp)
void
appendIntegerArray(int entry, long[] arr, long timestamp)
void
appendRaw(int entry, byte[] data, long timestamp)
Appends a record to the log.void
appendString(int entry, String value, long timestamp)
void
appendStringArray(int entry, String[] arr, long timestamp)
void
close()
void
finish(int entry)
Finish an entry.void
finish(int entry, long timestamp)
Finish an entry.void
flush()
Explicitly flushes the log data to disk.long
getImpl()
void
pause()
Pauses appending of data records to the log.void
resume()
Resumes appending of data records to the log.void
setFilename(String filename)
Change log filename.void
setMetadata(int entry, String metadata)
Updates the metadata for an entry.void
setMetadata(int entry, String metadata, long timestamp)
Updates the metadata for an entry.int
start(String name, String type)
Start an entry.int
start(String name, String type, String metadata)
Start an entry.int
start(String name, String type, String metadata, long timestamp)
Start an entry.
-
Constructor Details
-
DataLog
Construct a new Data Log. The log will be initially created with a temporary filename.- Parameters:
dir
- directory to store the logfilename
- filename to use; if none provided, a random filename is generated of the form "wpilog_{}.wpilog"period
- time between automatic flushes to disk, in seconds; this is a time/storage tradeoffextraHeader
- extra header data
-
DataLog
Construct a new Data Log. The log will be initially created with a temporary filename.- Parameters:
dir
- directory to store the logfilename
- filename to use; if none provided, a random filename is generated of the form "wpilog_{}.wpilog"period
- time between automatic flushes to disk, in seconds; this is a time/storage tradeoff
-
DataLog
Construct a new Data Log. The log will be initially created with a temporary filename.- Parameters:
dir
- directory to store the logfilename
- filename to use; if none provided, a random filename is generated of the form "wpilog_{}.wpilog"
-
DataLog
Construct a new Data Log. The log will be initially created with a temporary filename.- Parameters:
dir
- directory to store the log
-
DataLog
public DataLog()Construct a new Data Log. The log will be initially created with a temporary filename.
-
-
Method Details
-
setFilename
Change log filename.- Parameters:
filename
- filename
-
flush
Explicitly flushes the log data to disk. -
pause
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
Resumes appending of data records to the log. -
start
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
- Nametype
- Data typemetadata
- Initial metadata (e.g. data properties)timestamp
- Time stamp (0 to indicate now)- Returns:
- Entry index
-
start
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
- Nametype
- Data typemetadata
- Initial metadata (e.g. data properties)- Returns:
- Entry index
-
start
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
- Nametype
- Data type- Returns:
- Entry index
-
finish
Finish an entry.- Parameters:
entry
- Entry indextimestamp
- Time stamp (0 to indicate now)
-
finish
Finish an entry.- Parameters:
entry
- Entry index
-
setMetadata
Updates the metadata for an entry.- Parameters:
entry
- Entry indexmetadata
- New metadata for the entrytimestamp
- Time stamp (0 to indicate now)
-
setMetadata
Updates the metadata for an entry.- Parameters:
entry
- Entry indexmetadata
- New metadata for the entry
-
appendRaw
Appends a record to the log.- Parameters:
entry
- Entry index, as returned by Start()data
- Data to recordtimestamp
- Time stamp (0 to indicate now)
-
close
- Specified by:
close
in interfaceAutoCloseable
-
appendBoolean
-
appendInteger
-
appendFloat
-
appendDouble
-
appendString
-
appendBooleanArray
-
appendIntegerArray
-
appendFloatArray
-
appendDoubleArray
-
appendStringArray
-
getImpl
-