WPILibC++ 2023.4.3
DataLog.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <stdint.h>
8
9#include <functional>
10#include <initializer_list>
11#include <memory>
12#include <span>
13#include <string>
14#include <string_view>
15#include <thread>
16#include <vector>
17
18#include "wpi/DenseMap.h"
19#include "wpi/StringMap.h"
21#include "wpi/mutex.h"
22
23namespace wpi {
24class Logger;
25} // namespace wpi
26
27namespace wpi::log {
28
29namespace impl {
30
35};
36
37} // namespace impl
38
39/**
40 * A data log. The log file is created immediately upon construction with a
41 * temporary filename. The file may be renamed at any time using the
42 * SetFilename() function.
43 *
44 * The lifetime of the data log object must be longer than any data log entry
45 * objects that refer to it.
46 *
47 * The data log is periodically flushed to disk. It can also be explicitly
48 * flushed to disk by using the Flush() function.
49 *
50 * Finish() is needed only to indicate in the log that a particular entry is
51 * no longer being used (it releases the name to ID mapping). Finish() is not
52 * required to be called for data to be flushed to disk; entries in the log
53 * are written as Append() calls are being made. In fact, Finish() does not
54 * need to be called at all; this is helpful to avoid shutdown races where the
55 * DataLog object might be destroyed before other objects. It's often not a
56 * good idea to call Finish() from destructors for this reason.
57 *
58 * DataLog calls are thread safe. DataLog uses a typical multiple-supplier,
59 * single-consumer setup. Writes to the log are atomic, but there is no
60 * guaranteed order in the log when multiple threads are writing to it;
61 * whichever thread grabs the write mutex first will get written first.
62 * For this reason (as well as the fact that timestamps can be set to
63 * arbitrary values), records in the log are not guaranteed to be sorted by
64 * timestamp.
65 */
66class DataLog final {
67 public:
68 /**
69 * Construct a new Data Log. The log will be initially created with a
70 * temporary filename.
71 *
72 * @param dir directory to store the log
73 * @param filename filename to use; if none provided, a random filename is
74 * generated of the form "wpilog_{}.wpilog"
75 * @param period time between automatic flushes to disk, in seconds;
76 * this is a time/storage tradeoff
77 * @param extraHeader extra header data
78 */
79 explicit DataLog(std::string_view dir = "", std::string_view filename = "",
80 double period = 0.25, std::string_view extraHeader = "");
81
82 /**
83 * Construct a new Data Log. The log will be initially created with a
84 * temporary filename.
85 *
86 * @param msglog message logger (will be called from separate thread)
87 * @param dir directory to store the log
88 * @param filename filename to use; if none provided, a random filename is
89 * generated of the form "wpilog_{}.wpilog"
90 * @param period time between automatic flushes to disk, in seconds;
91 * this is a time/storage tradeoff
92 * @param extraHeader extra header data
93 */
94 explicit DataLog(wpi::Logger& msglog, std::string_view dir = "",
95 std::string_view filename = "", double period = 0.25,
96 std::string_view extraHeader = "");
97
98 /**
99 * Construct a new Data Log that passes its output to the provided function
100 * rather than a file. The write function will be called on a separate
101 * background thread and may block. The write function is called with an
102 * empty data array when the thread is terminating.
103 *
104 * @param write write function
105 * @param period time between automatic calls to write, in seconds;
106 * this is a time/storage tradeoff
107 * @param extraHeader extra header data
108 */
109 explicit DataLog(std::function<void(std::span<const uint8_t> data)> write,
110 double period = 0.25, std::string_view extraHeader = "");
111
112 /**
113 * Construct a new Data Log that passes its output to the provided function
114 * rather than a file. The write function will be called on a separate
115 * background thread and may block. The write function is called with an
116 * empty data array when the thread is terminating.
117 *
118 * @param msglog message logger (will be called from separate thread)
119 * @param write write function
120 * @param period time between automatic calls to write, in seconds;
121 * this is a time/storage tradeoff
122 * @param extraHeader extra header data
123 */
124 explicit DataLog(wpi::Logger& msglog,
125 std::function<void(std::span<const uint8_t> data)> write,
126 double period = 0.25, std::string_view extraHeader = "");
127
129 DataLog(const DataLog&) = delete;
130 DataLog& operator=(const DataLog&) = delete;
131 DataLog(DataLog&&) = delete;
132 DataLog& operator=(const DataLog&&) = delete;
133
134 /**
135 * Change log filename.
136 *
137 * @param filename filename
138 */
140
141 /**
142 * Explicitly flushes the log data to disk.
143 */
144 void Flush();
145
146 /**
147 * Pauses appending of data records to the log. While paused, no data records
148 * are saved (e.g. AppendX is a no-op). Has no effect on entry starts /
149 * finishes / metadata changes.
150 */
151 void Pause();
152
153 /**
154 * Resumes appending of data records to the log.
155 */
156 void Resume();
157
158 /**
159 * Start an entry. Duplicate names are allowed (with the same type), and
160 * result in the same index being returned (Start/Finish are reference
161 * counted). A duplicate name with a different type will result in an error
162 * message being printed to the console and 0 being returned (which will be
163 * ignored by the Append functions).
164 *
165 * @param name Name
166 * @param type Data type
167 * @param metadata Initial metadata (e.g. data properties)
168 * @param timestamp Time stamp (may be 0 to indicate now)
169 *
170 * @return Entry index
171 */
173 std::string_view metadata = {}, int64_t timestamp = 0);
174
175 /**
176 * Finish an entry.
177 *
178 * @param entry Entry index
179 * @param timestamp Time stamp (may be 0 to indicate now)
180 */
181 void Finish(int entry, int64_t timestamp = 0);
182
183 /**
184 * Updates the metadata for an entry.
185 *
186 * @param entry Entry index
187 * @param metadata New metadata for the entry
188 * @param timestamp Time stamp (may be 0 to indicate now)
189 */
190 void SetMetadata(int entry, std::string_view metadata, int64_t timestamp = 0);
191
192 /**
193 * Appends a record to the log.
194 *
195 * @param entry Entry index, as returned by Start()
196 * @param data Data to record
197 * @param timestamp Time stamp (may be 0 to indicate now)
198 */
199 void AppendRaw(int entry, std::span<const uint8_t> data, int64_t timestamp);
200
201 /**
202 * Appends a record to the log.
203 *
204 * @param entry Entry index, as returned by Start()
205 * @param data Data to record
206 * @param timestamp Time stamp (may be 0 to indicate now)
207 */
208 void AppendRaw2(int entry, std::span<const std::span<const uint8_t>> data,
209 int64_t timestamp);
210
211 void AppendBoolean(int entry, bool value, int64_t timestamp);
212 void AppendInteger(int entry, int64_t value, int64_t timestamp);
213 void AppendFloat(int entry, float value, int64_t timestamp);
214 void AppendDouble(int entry, double value, int64_t timestamp);
215 void AppendString(int entry, std::string_view value, int64_t timestamp);
216 void AppendBooleanArray(int entry, std::span<const bool> arr,
217 int64_t timestamp);
218 void AppendBooleanArray(int entry, std::span<const int> arr,
219 int64_t timestamp);
220 void AppendBooleanArray(int entry, std::span<const uint8_t> arr,
221 int64_t timestamp);
222 void AppendIntegerArray(int entry, std::span<const int64_t> arr,
223 int64_t timestamp);
224 void AppendFloatArray(int entry, std::span<const float> arr,
225 int64_t timestamp);
226 void AppendDoubleArray(int entry, std::span<const double> arr,
227 int64_t timestamp);
228 void AppendStringArray(int entry, std::span<const std::string> arr,
229 int64_t timestamp);
230 void AppendStringArray(int entry, std::span<const std::string_view> arr,
231 int64_t timestamp);
232
233 private:
234 void WriterThreadMain(std::string_view dir);
235 void WriterThreadMain(
236 std::function<void(std::span<const uint8_t> data)> write);
237
238 // must be called with m_mutex held
239 uint8_t* StartRecord(uint32_t entry, uint64_t timestamp, uint32_t payloadSize,
240 size_t reserveSize);
241 uint8_t* Reserve(size_t size);
242 void AppendImpl(std::span<const uint8_t> data);
243 void AppendStringImpl(std::string_view str);
244
245 wpi::Logger& m_msglog;
246 mutable wpi::mutex m_mutex;
248 bool m_active{true};
249 bool m_doFlush{false};
250 bool m_paused{false};
251 double m_period;
252 std::string m_extraHeader;
253 std::string m_newFilename;
254 class Buffer;
255 std::vector<Buffer> m_free;
256 std::vector<Buffer> m_outgoing;
257 struct EntryInfo {
258 std::string type;
259 int id{0};
260 };
263 int m_lastId = 0;
264 std::thread m_thread;
265};
266
267/**
268 * Log entry base class.
269 */
271 protected:
272 DataLogEntry() = default;
274 std::string_view metadata = {}, int64_t timestamp = 0)
275 : m_log{&log}, m_entry{log.Start(name, type, metadata, timestamp)} {}
276
277 public:
278 DataLogEntry(const DataLogEntry&) = delete;
280
282 rhs.m_log = nullptr;
283 }
285 if (m_log) {
287 }
288 m_log = rhs.m_log;
289 rhs.m_log = nullptr;
290 m_entry = rhs.m_entry;
291 return *this;
292 }
293
294 explicit operator bool() const { return m_log != nullptr; }
295
296 /**
297 * Updates the metadata for the entry.
298 *
299 * @param metadata New metadata for the entry
300 * @param timestamp Time stamp (may be 0 to indicate now)
301 */
302 void SetMetadata(std::string_view metadata, int64_t timestamp = 0) {
303 m_log->SetMetadata(m_entry, metadata, timestamp);
304 }
305
306 /**
307 * Finishes the entry.
308 *
309 * @param timestamp Time stamp (may be 0 to indicate now)
310 */
311 void Finish(int64_t timestamp = 0) { m_log->Finish(m_entry, timestamp); }
312
313 protected:
314 DataLog* m_log = nullptr;
315 int m_entry = 0;
316};
317
318/**
319 * Log arbitrary byte data.
320 */
321class RawLogEntry : public DataLogEntry {
322 public:
323 static constexpr std::string_view kDataType = "raw";
324
325 RawLogEntry() = default;
327 : RawLogEntry{log, name, {}, kDataType, timestamp} {}
329 int64_t timestamp = 0)
330 : RawLogEntry{log, name, metadata, kDataType, timestamp} {}
332 std::string_view type, int64_t timestamp = 0)
333 : DataLogEntry{log, name, type, metadata, timestamp} {}
334
335 /**
336 * Appends a record to the log.
337 *
338 * @param data Data to record
339 * @param timestamp Time stamp (may be 0 to indicate now)
340 */
341 void Append(std::span<const uint8_t> data, int64_t timestamp = 0) {
342 m_log->AppendRaw(m_entry, data, timestamp);
343 }
344};
345
346/**
347 * Log boolean values.
348 */
350 public:
351 static constexpr std::string_view kDataType = "boolean";
352
353 BooleanLogEntry() = default;
355 : BooleanLogEntry{log, name, {}, timestamp} {}
357 std::string_view metadata, int64_t timestamp = 0)
358 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
359
360 /**
361 * Appends a record to the log.
362 *
363 * @param value Value to record
364 * @param timestamp Time stamp (may be 0 to indicate now)
365 */
366 void Append(bool value, int64_t timestamp = 0) {
367 m_log->AppendBoolean(m_entry, value, timestamp);
368 }
369};
370
371/**
372 * Log integer values.
373 */
375 public:
376 static constexpr std::string_view kDataType = "int64";
377
378 IntegerLogEntry() = default;
380 : IntegerLogEntry{log, name, {}, timestamp} {}
382 std::string_view metadata, int64_t timestamp = 0)
383 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
384
385 /**
386 * Appends a record to the log.
387 *
388 * @param value Value to record
389 * @param timestamp Time stamp (may be 0 to indicate now)
390 */
391 void Append(int64_t value, int64_t timestamp = 0) {
392 m_log->AppendInteger(m_entry, value, timestamp);
393 }
394};
395
396/**
397 * Log float values.
398 */
400 public:
401 static constexpr std::string_view kDataType = "float";
402
403 FloatLogEntry() = default;
405 : FloatLogEntry{log, name, {}, timestamp} {}
407 int64_t timestamp = 0)
408 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
409
410 /**
411 * Appends a record to the log.
412 *
413 * @param value Value to record
414 * @param timestamp Time stamp (may be 0 to indicate now)
415 */
416 void Append(float value, int64_t timestamp = 0) {
417 m_log->AppendFloat(m_entry, value, timestamp);
418 }
419};
420
421/**
422 * Log double values.
423 */
425 public:
426 static constexpr std::string_view kDataType = "double";
427
428 DoubleLogEntry() = default;
430 : DoubleLogEntry{log, name, {}, timestamp} {}
432 int64_t timestamp = 0)
433 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
434
435 /**
436 * Appends a record to the log.
437 *
438 * @param value Value to record
439 * @param timestamp Time stamp (may be 0 to indicate now)
440 */
441 void Append(double value, int64_t timestamp = 0) {
442 m_log->AppendDouble(m_entry, value, timestamp);
443 }
444};
445
446/**
447 * Log string values.
448 */
450 public:
451 static constexpr const char* kDataType = "string";
452
453 StringLogEntry() = default;
455 : StringLogEntry{log, name, {}, kDataType, timestamp} {}
457 int64_t timestamp = 0)
458 : StringLogEntry{log, name, metadata, kDataType, timestamp} {}
460 std::string_view type, int64_t timestamp = 0)
461 : DataLogEntry{log, name, type, metadata, timestamp} {}
462
463 /**
464 * Appends a record to the log.
465 *
466 * @param value Value to record
467 * @param timestamp Time stamp (may be 0 to indicate now)
468 */
469 void Append(std::string_view value, int64_t timestamp = 0) {
470 m_log->AppendString(m_entry, value, timestamp);
471 }
472};
473
474/**
475 * Log array of boolean values.
476 */
478 public:
479 static constexpr const char* kDataType = "boolean[]";
480
483 int64_t timestamp = 0)
484 : BooleanArrayLogEntry{log, name, {}, timestamp} {}
486 std::string_view metadata, int64_t timestamp = 0)
487 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
488
489 /**
490 * Appends a record to the log. For find functions to work, timestamp
491 * must be monotonically increasing.
492 *
493 * @param arr Values to record
494 * @param timestamp Time stamp (may be 0 to indicate now)
495 */
496 void Append(std::span<const bool> arr, int64_t timestamp = 0) {
497 m_log->AppendBooleanArray(m_entry, arr, timestamp);
498 }
499
500 /**
501 * Appends a record to the log.
502 *
503 * @param arr Values to record
504 * @param timestamp Time stamp (may be 0 to indicate now)
505 */
506 void Append(std::initializer_list<bool> arr, int64_t timestamp = 0) {
507 Append(std::span{arr.begin(), arr.end()}, timestamp);
508 }
509
510 /**
511 * Appends a record to the log.
512 *
513 * @param arr Values to record
514 * @param timestamp Time stamp (may be 0 to indicate now)
515 */
516 void Append(std::span<const int> arr, int64_t timestamp = 0) {
517 m_log->AppendBooleanArray(m_entry, arr, timestamp);
518 }
519
520 /**
521 * Appends a record to the log.
522 *
523 * @param arr Values to record
524 * @param timestamp Time stamp (may be 0 to indicate now)
525 */
526 void Append(std::initializer_list<int> arr, int64_t timestamp = 0) {
527 Append(std::span{arr.begin(), arr.end()}, timestamp);
528 }
529
530 /**
531 * Appends a record to the log.
532 *
533 * @param arr Values to record
534 * @param timestamp Time stamp (may be 0 to indicate now)
535 */
536 void Append(std::span<const uint8_t> arr, int64_t timestamp = 0) {
537 m_log->AppendBooleanArray(m_entry, arr, timestamp);
538 }
539};
540
541/**
542 * Log array of integer values.
543 */
545 public:
546 static constexpr const char* kDataType = "int64[]";
547
550 int64_t timestamp = 0)
551 : IntegerArrayLogEntry{log, name, {}, timestamp} {}
553 std::string_view metadata, int64_t timestamp = 0)
554 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
555
556 /**
557 * Appends a record to the log.
558 *
559 * @param arr Values to record
560 * @param timestamp Time stamp (may be 0 to indicate now)
561 */
562 void Append(std::span<const int64_t> arr, int64_t timestamp = 0) {
563 m_log->AppendIntegerArray(m_entry, arr, timestamp);
564 }
565
566 /**
567 * Appends a record to the log.
568 *
569 * @param arr Values to record
570 * @param timestamp Time stamp (may be 0 to indicate now)
571 */
572 void Append(std::initializer_list<int64_t> arr, int64_t timestamp = 0) {
573 Append({arr.begin(), arr.end()}, timestamp);
574 }
575};
576
577/**
578 * Log array of float values.
579 */
581 public:
582 static constexpr const char* kDataType = "float[]";
583
586 : FloatArrayLogEntry{log, name, {}, timestamp} {}
588 std::string_view metadata, int64_t timestamp = 0)
589 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
590
591 /**
592 * Appends a record to the log.
593 *
594 * @param arr Values to record
595 * @param timestamp Time stamp (may be 0 to indicate now)
596 */
597 void Append(std::span<const float> arr, int64_t timestamp = 0) {
598 m_log->AppendFloatArray(m_entry, arr, timestamp);
599 }
600
601 /**
602 * Appends a record to the log.
603 *
604 * @param arr Values to record
605 * @param timestamp Time stamp (may be 0 to indicate now)
606 */
607 void Append(std::initializer_list<float> arr, int64_t timestamp = 0) {
608 Append({arr.begin(), arr.end()}, timestamp);
609 }
610};
611
612/**
613 * Log array of double values.
614 */
616 public:
617 static constexpr const char* kDataType = "double[]";
618
621 int64_t timestamp = 0)
622 : DoubleArrayLogEntry{log, name, {}, timestamp} {}
624 std::string_view metadata, int64_t timestamp = 0)
625 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
626
627 /**
628 * Appends a record to the log.
629 *
630 * @param arr Values to record
631 * @param timestamp Time stamp (may be 0 to indicate now)
632 */
633 void Append(std::span<const double> arr, int64_t timestamp = 0) {
634 m_log->AppendDoubleArray(m_entry, arr, timestamp);
635 }
636
637 /**
638 * Appends a record to the log.
639 *
640 * @param arr Values to record
641 * @param timestamp Time stamp (may be 0 to indicate now)
642 */
643 void Append(std::initializer_list<double> arr, int64_t timestamp = 0) {
644 Append({arr.begin(), arr.end()}, timestamp);
645 }
646};
647
648/**
649 * Log array of string values.
650 */
652 public:
653 static constexpr const char* kDataType = "string[]";
654
657 int64_t timestamp = 0)
658 : StringArrayLogEntry{log, name, {}, timestamp} {}
660 std::string_view metadata, int64_t timestamp = 0)
661 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
662
663 /**
664 * Appends a record to the log.
665 *
666 * @param arr Values to record
667 * @param timestamp Time stamp (may be 0 to indicate now)
668 */
669 void Append(std::span<const std::string> arr, int64_t timestamp = 0) {
670 m_log->AppendStringArray(m_entry, arr, timestamp);
671 }
672
673 /**
674 * Appends a record to the log.
675 *
676 * @param arr Values to record
677 * @param timestamp Time stamp (may be 0 to indicate now)
678 */
679 void Append(std::span<const std::string_view> arr, int64_t timestamp = 0) {
680 m_log->AppendStringArray(m_entry, arr, timestamp);
681 }
682
683 /**
684 * Appends a record to the log.
685 *
686 * @param arr Values to record
687 * @param timestamp Time stamp (may be 0 to indicate now)
688 */
689 void Append(std::initializer_list<std::string_view> arr,
690 int64_t timestamp = 0) {
691 Append(std::span<const std::string_view>{arr.begin(), arr.end()},
692 timestamp);
693 }
694};
695
696} // namespace wpi::log
This file defines the DenseMap class.
This file defines the StringMap class.
Definition: core.h:1240
Definition: Logger.h:27
Log array of boolean values.
Definition: DataLog.h:477
void Append(std::span< const uint8_t > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:536
void Append(std::initializer_list< bool > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:506
BooleanArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:482
void Append(std::initializer_list< int > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:526
void Append(std::span< const int > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:516
void Append(std::span< const bool > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:496
BooleanArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:485
BooleanArrayLogEntry()=default
Log boolean values.
Definition: DataLog.h:349
BooleanLogEntry()=default
BooleanLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:356
void Append(bool value, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:366
BooleanLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:354
Log entry base class.
Definition: DataLog.h:270
DataLogEntry(DataLogEntry &&rhs)
Definition: DataLog.h:281
DataLogEntry(const DataLogEntry &)=delete
void Finish(int64_t timestamp=0)
Finishes the entry.
Definition: DataLog.h:311
DataLog * m_log
Definition: DataLog.h:314
DataLogEntry(DataLog &log, std::string_view name, std::string_view type, std::string_view metadata={}, int64_t timestamp=0)
Definition: DataLog.h:273
DataLogEntry()=default
DataLogEntry & operator=(const DataLogEntry &)=delete
int m_entry
Definition: DataLog.h:315
DataLogEntry & operator=(DataLogEntry &&rhs)
Definition: DataLog.h:284
void SetMetadata(std::string_view metadata, int64_t timestamp=0)
Updates the metadata for the entry.
Definition: DataLog.h:302
A data log.
Definition: DataLog.h:66
void AppendBooleanArray(int entry, std::span< const bool > arr, int64_t timestamp)
void AppendBooleanArray(int entry, std::span< const int > arr, int64_t timestamp)
void SetMetadata(int entry, std::string_view metadata, int64_t timestamp=0)
Updates the metadata for an entry.
void AppendStringArray(int entry, std::span< const std::string > arr, int64_t timestamp)
int Start(std::string_view name, std::string_view type, std::string_view metadata={}, int64_t timestamp=0)
Start an entry.
DataLog & operator=(const DataLog &)=delete
DataLog(std::string_view dir="", std::string_view filename="", double period=0.25, std::string_view extraHeader="")
Construct a new Data Log.
void Flush()
Explicitly flushes the log data to disk.
void AppendRaw(int entry, std::span< const uint8_t > data, int64_t timestamp)
Appends a record to the log.
void AppendIntegerArray(int entry, std::span< const int64_t > arr, int64_t timestamp)
DataLog(const DataLog &)=delete
void AppendBooleanArray(int entry, std::span< const uint8_t > arr, int64_t timestamp)
void AppendDouble(int entry, double value, int64_t timestamp)
void AppendFloat(int entry, float value, int64_t timestamp)
DataLog & operator=(const DataLog &&)=delete
void AppendFloatArray(int entry, std::span< const float > arr, int64_t timestamp)
DataLog(std::function< void(std::span< const uint8_t > data)> write, double period=0.25, std::string_view extraHeader="")
Construct a new Data Log that passes its output to the provided function rather than a file.
void AppendString(int entry, std::string_view value, int64_t timestamp)
DataLog(wpi::Logger &msglog, std::string_view dir="", std::string_view filename="", double period=0.25, std::string_view extraHeader="")
Construct a new Data Log.
DataLog(DataLog &&)=delete
void Pause()
Pauses appending of data records to the log.
void AppendStringArray(int entry, std::span< const std::string_view > arr, int64_t timestamp)
void SetFilename(std::string_view filename)
Change log filename.
DataLog(wpi::Logger &msglog, std::function< void(std::span< const uint8_t > data)> write, double period=0.25, std::string_view extraHeader="")
Construct a new Data Log that passes its output to the provided function rather than a file.
void AppendRaw2(int entry, std::span< const std::span< const uint8_t > > data, int64_t timestamp)
Appends a record to the log.
void Finish(int entry, int64_t timestamp=0)
Finish an entry.
void AppendDoubleArray(int entry, std::span< const double > arr, int64_t timestamp)
void Resume()
Resumes appending of data records to the log.
void AppendInteger(int entry, int64_t value, int64_t timestamp)
void AppendBoolean(int entry, bool value, int64_t timestamp)
Log array of double values.
Definition: DataLog.h:615
DoubleArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:620
void Append(std::span< const double > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:633
void Append(std::initializer_list< double > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:643
DoubleArrayLogEntry()=default
DoubleArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:623
Log double values.
Definition: DataLog.h:424
DoubleLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:431
void Append(double value, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:441
DoubleLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:429
DoubleLogEntry()=default
Log array of float values.
Definition: DataLog.h:580
FloatArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:587
void Append(std::span< const float > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:597
void Append(std::initializer_list< float > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:607
FloatArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:585
FloatArrayLogEntry()=default
Log float values.
Definition: DataLog.h:399
FloatLogEntry()=default
FloatLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:404
FloatLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:406
void Append(float value, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:416
Log array of integer values.
Definition: DataLog.h:544
IntegerArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:552
void Append(std::span< const int64_t > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:562
IntegerArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:549
void Append(std::initializer_list< int64_t > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:572
IntegerArrayLogEntry()=default
Log integer values.
Definition: DataLog.h:374
IntegerLogEntry()=default
IntegerLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:381
IntegerLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:379
void Append(int64_t value, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:391
Log arbitrary byte data.
Definition: DataLog.h:321
RawLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:328
RawLogEntry(DataLog &log, std::string_view name, std::string_view metadata, std::string_view type, int64_t timestamp=0)
Definition: DataLog.h:331
static constexpr std::string_view kDataType
Definition: DataLog.h:323
RawLogEntry()=default
void Append(std::span< const uint8_t > data, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:341
RawLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:326
Log array of string values.
Definition: DataLog.h:651
void Append(std::initializer_list< std::string_view > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:689
StringArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:659
void Append(std::span< const std::string > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:669
void Append(std::span< const std::string_view > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:679
StringArrayLogEntry()=default
StringArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:656
Log string values.
Definition: DataLog.h:449
StringLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:456
void Append(std::string_view value, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:469
StringLogEntry(DataLog &log, std::string_view name, std::string_view metadata, std::string_view type, int64_t timestamp=0)
Definition: DataLog.h:459
StringLogEntry()=default
StringLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:454
basic_string_view< char > string_view
Definition: core.h:520
type
Definition: core.h:575
dimensionless::scalar_t log(const ScalarUnit x) noexcept
Compute natural logarithm.
Definition: math.h:349
EIGEN_CONSTEXPR Index size(const T &x)
Definition: Meta.h:479
::uint64_t uint64_t
Definition: Meta.h:58
::uint32_t uint32_t
Definition: Meta.h:56
::int64_t int64_t
Definition: Meta.h:59
::uint8_t uint8_t
Definition: Meta.h:52
auto write(OutputIt out, const std::tm &time, const std::locale &loc, char format, char modifier=0) -> OutputIt
Definition: chrono.h:426
ControlRecordType
Definition: DataLog.h:31
@ kControlFinish
Definition: DataLog.h:33
@ kControlStart
Definition: DataLog.h:32
@ kControlSetMetadata
Definition: DataLog.h:34
Definition: ntcore_cpp.h:30
/file This file defines the SmallVector class.
Definition: AprilTagFieldLayout.h:18
::std::mutex mutex
Definition: mutex.h:17
::std::condition_variable condition_variable
Definition: condition_variable.h:16
Definition: format.h:1544