WPILibC++ 2023.4.3-108-ge5452e3
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 raw record to the log.
194 *
195 * @param entry Entry index, as returned by Start()
196 * @param data Byte array 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 raw record to the log.
203 *
204 * @param entry Entry index, as returned by Start()
205 * @param data Byte array 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 /**
212 * Appends a boolean record to the log.
213 *
214 * @param entry Entry index, as returned by Start()
215 * @param value Boolean value to record
216 * @param timestamp Time stamp (may be 0 to indicate now)
217 */
218 void AppendBoolean(int entry, bool value, int64_t timestamp);
219
220 /**
221 * Appends an integer record to the log.
222 *
223 * @param entry Entry index, as returned by Start()
224 * @param value Integer value to record
225 * @param timestamp Time stamp (may be 0 to indicate now)
226 */
227 void AppendInteger(int entry, int64_t value, int64_t timestamp);
228
229 /**
230 * Appends a float record to the log.
231 *
232 * @param entry Entry index, as returned by Start()
233 * @param value Float value to record
234 * @param timestamp Time stamp (may be 0 to indicate now)
235 */
236 void AppendFloat(int entry, float value, int64_t timestamp);
237
238 /**
239 * Appends a double record to the log.
240 *
241 * @param entry Entry index, as returned by Start()
242 * @param value Double value to record
243 * @param timestamp Time stamp (may be 0 to indicate now)
244 */
245 void AppendDouble(int entry, double value, int64_t timestamp);
246
247 /**
248 * Appends a string record to the log.
249 *
250 * @param entry Entry index, as returned by Start()
251 * @param value String value to record
252 * @param timestamp Time stamp (may be 0 to indicate now)
253 */
254 void AppendString(int entry, std::string_view value, int64_t timestamp);
255
256 /**
257 * Appends a boolean array record to the log.
258 *
259 * @param entry Entry index, as returned by Start()
260 * @param arr Boolean array to record
261 * @param timestamp Time stamp (may be 0 to indicate now)
262 */
263 void AppendBooleanArray(int entry, std::span<const bool> arr,
264 int64_t timestamp);
265
266 /**
267 * Appends a boolean array record to the log.
268 *
269 * @param entry Entry index, as returned by Start()
270 * @param arr Boolean array to record
271 * @param timestamp Time stamp (may be 0 to indicate now)
272 */
273 void AppendBooleanArray(int entry, std::span<const int> arr,
274 int64_t timestamp);
275
276 /**
277 * Appends a boolean array record to the log.
278 *
279 * @param entry Entry index, as returned by Start()
280 * @param arr Boolean array to record
281 * @param timestamp Time stamp (may be 0 to indicate now)
282 */
283 void AppendBooleanArray(int entry, std::span<const uint8_t> arr,
284 int64_t timestamp);
285
286 /**
287 * Appends an integer array record to the log.
288 *
289 * @param entry Entry index, as returned by Start()
290 * @param arr Integer array to record
291 * @param timestamp Time stamp (may be 0 to indicate now)
292 */
293 void AppendIntegerArray(int entry, std::span<const int64_t> arr,
294 int64_t timestamp);
295
296 /**
297 * Appends a float array record to the log.
298 *
299 * @param entry Entry index, as returned by Start()
300 * @param arr Float array to record
301 * @param timestamp Time stamp (may be 0 to indicate now)
302 */
303 void AppendFloatArray(int entry, std::span<const float> arr,
304 int64_t timestamp);
305
306 /**
307 * Appends a double array record to the log.
308 *
309 * @param entry Entry index, as returned by Start()
310 * @param arr Double array to record
311 * @param timestamp Time stamp (may be 0 to indicate now)
312 */
313 void AppendDoubleArray(int entry, std::span<const double> arr,
314 int64_t timestamp);
315
316 /**
317 * Appends a string array record to the log.
318 *
319 * @param entry Entry index, as returned by Start()
320 * @param arr String array to record
321 * @param timestamp Time stamp (may be 0 to indicate now)
322 */
323 void AppendStringArray(int entry, std::span<const std::string> arr,
324 int64_t timestamp);
325
326 /**
327 * Appends a string array record to the log.
328 *
329 * @param entry Entry index, as returned by Start()
330 * @param arr String array to record
331 * @param timestamp Time stamp (may be 0 to indicate now)
332 */
333 void AppendStringArray(int entry, std::span<const std::string_view> arr,
334 int64_t timestamp);
335
336 private:
337 void WriterThreadMain(std::string_view dir);
338 void WriterThreadMain(
339 std::function<void(std::span<const uint8_t> data)> write);
340
341 // must be called with m_mutex held
342 uint8_t* StartRecord(uint32_t entry, uint64_t timestamp, uint32_t payloadSize,
343 size_t reserveSize);
344 uint8_t* Reserve(size_t size);
345 void AppendImpl(std::span<const uint8_t> data);
346 void AppendStringImpl(std::string_view str);
347
348 wpi::Logger& m_msglog;
349 mutable wpi::mutex m_mutex;
351 bool m_active{true};
352 bool m_doFlush{false};
353 bool m_paused{false};
354 double m_period;
355 std::string m_extraHeader;
356 std::string m_newFilename;
357 class Buffer;
358 std::vector<Buffer> m_free;
359 std::vector<Buffer> m_outgoing;
360 struct EntryInfo {
361 std::string type;
362 int id{0};
363 };
366 int m_lastId = 0;
367 std::thread m_thread;
368};
369
370/**
371 * Log entry base class.
372 */
374 protected:
375 DataLogEntry() = default;
377 std::string_view metadata = {}, int64_t timestamp = 0)
378 : m_log{&log}, m_entry{log.Start(name, type, metadata, timestamp)} {}
379
380 public:
381 DataLogEntry(const DataLogEntry&) = delete;
383
385 rhs.m_log = nullptr;
386 }
388 if (m_log) {
390 }
391 m_log = rhs.m_log;
392 rhs.m_log = nullptr;
393 m_entry = rhs.m_entry;
394 return *this;
395 }
396
397 explicit operator bool() const { return m_log != nullptr; }
398
399 /**
400 * Updates the metadata for the entry.
401 *
402 * @param metadata New metadata for the entry
403 * @param timestamp Time stamp (may be 0 to indicate now)
404 */
405 void SetMetadata(std::string_view metadata, int64_t timestamp = 0) {
406 m_log->SetMetadata(m_entry, metadata, timestamp);
407 }
408
409 /**
410 * Finishes the entry.
411 *
412 * @param timestamp Time stamp (may be 0 to indicate now)
413 */
414 void Finish(int64_t timestamp = 0) { m_log->Finish(m_entry, timestamp); }
415
416 protected:
417 DataLog* m_log = nullptr;
418 int m_entry = 0;
419};
420
421/**
422 * Log arbitrary byte data.
423 */
424class RawLogEntry : public DataLogEntry {
425 public:
426 static constexpr std::string_view kDataType = "raw";
427
428 RawLogEntry() = default;
430 : RawLogEntry{log, name, {}, kDataType, timestamp} {}
432 int64_t timestamp = 0)
433 : RawLogEntry{log, name, metadata, kDataType, timestamp} {}
435 std::string_view type, int64_t timestamp = 0)
436 : DataLogEntry{log, name, type, metadata, timestamp} {}
437
438 /**
439 * Appends a record to the log.
440 *
441 * @param data Data to record
442 * @param timestamp Time stamp (may be 0 to indicate now)
443 */
444 void Append(std::span<const uint8_t> data, int64_t timestamp = 0) {
445 m_log->AppendRaw(m_entry, data, timestamp);
446 }
447};
448
449/**
450 * Log boolean values.
451 */
453 public:
454 static constexpr std::string_view kDataType = "boolean";
455
456 BooleanLogEntry() = default;
458 : BooleanLogEntry{log, name, {}, timestamp} {}
460 std::string_view metadata, int64_t timestamp = 0)
461 : DataLogEntry{log, name, kDataType, 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(bool value, int64_t timestamp = 0) {
470 m_log->AppendBoolean(m_entry, value, timestamp);
471 }
472};
473
474/**
475 * Log integer values.
476 */
478 public:
479 static constexpr std::string_view kDataType = "int64";
480
481 IntegerLogEntry() = default;
483 : IntegerLogEntry{log, name, {}, timestamp} {}
485 std::string_view metadata, int64_t timestamp = 0)
486 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
487
488 /**
489 * Appends a record to the log.
490 *
491 * @param value Value to record
492 * @param timestamp Time stamp (may be 0 to indicate now)
493 */
494 void Append(int64_t value, int64_t timestamp = 0) {
495 m_log->AppendInteger(m_entry, value, timestamp);
496 }
497};
498
499/**
500 * Log float values.
501 */
503 public:
504 static constexpr std::string_view kDataType = "float";
505
506 FloatLogEntry() = default;
508 : FloatLogEntry{log, name, {}, timestamp} {}
510 int64_t timestamp = 0)
511 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
512
513 /**
514 * Appends a record to the log.
515 *
516 * @param value Value to record
517 * @param timestamp Time stamp (may be 0 to indicate now)
518 */
519 void Append(float value, int64_t timestamp = 0) {
520 m_log->AppendFloat(m_entry, value, timestamp);
521 }
522};
523
524/**
525 * Log double values.
526 */
528 public:
529 static constexpr std::string_view kDataType = "double";
530
531 DoubleLogEntry() = default;
533 : DoubleLogEntry{log, name, {}, timestamp} {}
535 int64_t timestamp = 0)
536 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
537
538 /**
539 * Appends a record to the log.
540 *
541 * @param value Value to record
542 * @param timestamp Time stamp (may be 0 to indicate now)
543 */
544 void Append(double value, int64_t timestamp = 0) {
545 m_log->AppendDouble(m_entry, value, timestamp);
546 }
547};
548
549/**
550 * Log string values.
551 */
553 public:
554 static constexpr const char* kDataType = "string";
555
556 StringLogEntry() = default;
558 : StringLogEntry{log, name, {}, kDataType, timestamp} {}
560 int64_t timestamp = 0)
561 : StringLogEntry{log, name, metadata, kDataType, timestamp} {}
563 std::string_view type, int64_t timestamp = 0)
564 : DataLogEntry{log, name, type, metadata, timestamp} {}
565
566 /**
567 * Appends a record to the log.
568 *
569 * @param value Value to record
570 * @param timestamp Time stamp (may be 0 to indicate now)
571 */
572 void Append(std::string_view value, int64_t timestamp = 0) {
573 m_log->AppendString(m_entry, value, timestamp);
574 }
575};
576
577/**
578 * Log array of boolean values.
579 */
581 public:
582 static constexpr const char* kDataType = "boolean[]";
583
586 int64_t timestamp = 0)
587 : BooleanArrayLogEntry{log, name, {}, timestamp} {}
589 std::string_view metadata, int64_t timestamp = 0)
590 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
591
592 /**
593 * Appends a record to the log. For find functions to work, timestamp
594 * must be monotonically increasing.
595 *
596 * @param arr Values to record
597 * @param timestamp Time stamp (may be 0 to indicate now)
598 */
599 void Append(std::span<const bool> arr, int64_t timestamp = 0) {
600 m_log->AppendBooleanArray(m_entry, arr, timestamp);
601 }
602
603 /**
604 * Appends a record to the log.
605 *
606 * @param arr Values to record
607 * @param timestamp Time stamp (may be 0 to indicate now)
608 */
609 void Append(std::initializer_list<bool> arr, int64_t timestamp = 0) {
610 Append(std::span{arr.begin(), arr.end()}, timestamp);
611 }
612
613 /**
614 * Appends a record to the log.
615 *
616 * @param arr Values to record
617 * @param timestamp Time stamp (may be 0 to indicate now)
618 */
619 void Append(std::span<const int> arr, int64_t timestamp = 0) {
620 m_log->AppendBooleanArray(m_entry, arr, timestamp);
621 }
622
623 /**
624 * Appends a record to the log.
625 *
626 * @param arr Values to record
627 * @param timestamp Time stamp (may be 0 to indicate now)
628 */
629 void Append(std::initializer_list<int> arr, int64_t timestamp = 0) {
630 Append(std::span{arr.begin(), arr.end()}, timestamp);
631 }
632
633 /**
634 * Appends a record to the log.
635 *
636 * @param arr Values to record
637 * @param timestamp Time stamp (may be 0 to indicate now)
638 */
639 void Append(std::span<const uint8_t> arr, int64_t timestamp = 0) {
640 m_log->AppendBooleanArray(m_entry, arr, timestamp);
641 }
642};
643
644/**
645 * Log array of integer values.
646 */
648 public:
649 static constexpr const char* kDataType = "int64[]";
650
653 int64_t timestamp = 0)
654 : IntegerArrayLogEntry{log, name, {}, timestamp} {}
656 std::string_view metadata, int64_t timestamp = 0)
657 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
658
659 /**
660 * Appends a record to the log.
661 *
662 * @param arr Values to record
663 * @param timestamp Time stamp (may be 0 to indicate now)
664 */
665 void Append(std::span<const int64_t> arr, int64_t timestamp = 0) {
666 m_log->AppendIntegerArray(m_entry, arr, timestamp);
667 }
668
669 /**
670 * Appends a record to the log.
671 *
672 * @param arr Values to record
673 * @param timestamp Time stamp (may be 0 to indicate now)
674 */
675 void Append(std::initializer_list<int64_t> arr, int64_t timestamp = 0) {
676 Append({arr.begin(), arr.end()}, timestamp);
677 }
678};
679
680/**
681 * Log array of float values.
682 */
684 public:
685 static constexpr const char* kDataType = "float[]";
686
689 : FloatArrayLogEntry{log, name, {}, timestamp} {}
691 std::string_view metadata, int64_t timestamp = 0)
692 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
693
694 /**
695 * Appends a record to the log.
696 *
697 * @param arr Values to record
698 * @param timestamp Time stamp (may be 0 to indicate now)
699 */
700 void Append(std::span<const float> arr, int64_t timestamp = 0) {
701 m_log->AppendFloatArray(m_entry, arr, timestamp);
702 }
703
704 /**
705 * Appends a record to the log.
706 *
707 * @param arr Values to record
708 * @param timestamp Time stamp (may be 0 to indicate now)
709 */
710 void Append(std::initializer_list<float> arr, int64_t timestamp = 0) {
711 Append({arr.begin(), arr.end()}, timestamp);
712 }
713};
714
715/**
716 * Log array of double values.
717 */
719 public:
720 static constexpr const char* kDataType = "double[]";
721
724 int64_t timestamp = 0)
725 : DoubleArrayLogEntry{log, name, {}, timestamp} {}
727 std::string_view metadata, int64_t timestamp = 0)
728 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
729
730 /**
731 * Appends a record to the log.
732 *
733 * @param arr Values to record
734 * @param timestamp Time stamp (may be 0 to indicate now)
735 */
736 void Append(std::span<const double> arr, int64_t timestamp = 0) {
737 m_log->AppendDoubleArray(m_entry, arr, timestamp);
738 }
739
740 /**
741 * Appends a record to the log.
742 *
743 * @param arr Values to record
744 * @param timestamp Time stamp (may be 0 to indicate now)
745 */
746 void Append(std::initializer_list<double> arr, int64_t timestamp = 0) {
747 Append({arr.begin(), arr.end()}, timestamp);
748 }
749};
750
751/**
752 * Log array of string values.
753 */
755 public:
756 static constexpr const char* kDataType = "string[]";
757
760 int64_t timestamp = 0)
761 : StringArrayLogEntry{log, name, {}, timestamp} {}
763 std::string_view metadata, int64_t timestamp = 0)
764 : DataLogEntry{log, name, kDataType, metadata, timestamp} {}
765
766 /**
767 * Appends a record to the log.
768 *
769 * @param arr Values to record
770 * @param timestamp Time stamp (may be 0 to indicate now)
771 */
772 void Append(std::span<const std::string> arr, int64_t timestamp = 0) {
773 m_log->AppendStringArray(m_entry, arr, timestamp);
774 }
775
776 /**
777 * Appends a record to the log.
778 *
779 * @param arr Values to record
780 * @param timestamp Time stamp (may be 0 to indicate now)
781 */
782 void Append(std::span<const std::string_view> arr, int64_t timestamp = 0) {
783 m_log->AppendStringArray(m_entry, arr, timestamp);
784 }
785
786 /**
787 * Appends a record to the log.
788 *
789 * @param arr Values to record
790 * @param timestamp Time stamp (may be 0 to indicate now)
791 */
792 void Append(std::initializer_list<std::string_view> arr,
793 int64_t timestamp = 0) {
794 Append(std::span<const std::string_view>{arr.begin(), arr.end()},
795 timestamp);
796 }
797};
798
799} // 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:580
void Append(std::span< const uint8_t > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:639
void Append(std::initializer_list< bool > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:609
BooleanArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:585
void Append(std::initializer_list< int > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:629
void Append(std::span< const int > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:619
void Append(std::span< const bool > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:599
BooleanArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:588
BooleanArrayLogEntry()=default
Log boolean values.
Definition: DataLog.h:452
BooleanLogEntry()=default
BooleanLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:459
void Append(bool value, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:469
BooleanLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:457
Log entry base class.
Definition: DataLog.h:373
DataLogEntry(DataLogEntry &&rhs)
Definition: DataLog.h:384
DataLogEntry(const DataLogEntry &)=delete
void Finish(int64_t timestamp=0)
Finishes the entry.
Definition: DataLog.h:414
DataLog * m_log
Definition: DataLog.h:417
DataLogEntry(DataLog &log, std::string_view name, std::string_view type, std::string_view metadata={}, int64_t timestamp=0)
Definition: DataLog.h:376
DataLogEntry()=default
DataLogEntry & operator=(const DataLogEntry &)=delete
int m_entry
Definition: DataLog.h:418
DataLogEntry & operator=(DataLogEntry &&rhs)
Definition: DataLog.h:387
void SetMetadata(std::string_view metadata, int64_t timestamp=0)
Updates the metadata for the entry.
Definition: DataLog.h:405
A data log.
Definition: DataLog.h:66
void AppendBooleanArray(int entry, std::span< const bool > arr, int64_t timestamp)
Appends a boolean array record to the log.
void AppendBooleanArray(int entry, std::span< const int > arr, int64_t timestamp)
Appends a boolean array record to the log.
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)
Appends a string array record to the log.
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 raw record to the log.
void AppendIntegerArray(int entry, std::span< const int64_t > arr, int64_t timestamp)
Appends an integer array record to the log.
DataLog(const DataLog &)=delete
void AppendBooleanArray(int entry, std::span< const uint8_t > arr, int64_t timestamp)
Appends a boolean array record to the log.
void AppendDouble(int entry, double value, int64_t timestamp)
Appends a double record to the log.
void AppendFloat(int entry, float value, int64_t timestamp)
Appends a float record to the log.
DataLog & operator=(const DataLog &&)=delete
void AppendFloatArray(int entry, std::span< const float > arr, int64_t timestamp)
Appends a float array record to the log.
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)
Appends a string record to the log.
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)
Appends a string array record to the log.
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 raw 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)
Appends a double array record to the log.
void Resume()
Resumes appending of data records to the log.
void AppendInteger(int entry, int64_t value, int64_t timestamp)
Appends an integer record to the log.
void AppendBoolean(int entry, bool value, int64_t timestamp)
Appends a boolean record to the log.
Log array of double values.
Definition: DataLog.h:718
DoubleArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:723
void Append(std::span< const double > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:736
void Append(std::initializer_list< double > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:746
DoubleArrayLogEntry()=default
DoubleArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:726
Log double values.
Definition: DataLog.h:527
DoubleLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:534
void Append(double value, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:544
DoubleLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:532
DoubleLogEntry()=default
Log array of float values.
Definition: DataLog.h:683
FloatArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:690
void Append(std::span< const float > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:700
void Append(std::initializer_list< float > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:710
FloatArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:688
FloatArrayLogEntry()=default
Log float values.
Definition: DataLog.h:502
FloatLogEntry()=default
FloatLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:507
FloatLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:509
void Append(float value, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:519
Log array of integer values.
Definition: DataLog.h:647
IntegerArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:655
void Append(std::span< const int64_t > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:665
IntegerArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:652
void Append(std::initializer_list< int64_t > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:675
IntegerArrayLogEntry()=default
Log integer values.
Definition: DataLog.h:477
IntegerLogEntry()=default
IntegerLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:484
IntegerLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:482
void Append(int64_t value, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:494
Log arbitrary byte data.
Definition: DataLog.h:424
RawLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:431
RawLogEntry(DataLog &log, std::string_view name, std::string_view metadata, std::string_view type, int64_t timestamp=0)
Definition: DataLog.h:434
static constexpr std::string_view kDataType
Definition: DataLog.h:426
RawLogEntry()=default
void Append(std::span< const uint8_t > data, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:444
RawLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:429
Log array of string values.
Definition: DataLog.h:754
void Append(std::initializer_list< std::string_view > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:792
StringArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:762
void Append(std::span< const std::string > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:772
void Append(std::span< const std::string_view > arr, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:782
StringArrayLogEntry()=default
StringArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:759
Log string values.
Definition: DataLog.h:552
StringLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition: DataLog.h:559
void Append(std::string_view value, int64_t timestamp=0)
Appends a record to the log.
Definition: DataLog.h:572
StringLogEntry(DataLog &log, std::string_view name, std::string_view metadata, std::string_view type, int64_t timestamp=0)
Definition: DataLog.h:562
StringLogEntry()=default
StringLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition: DataLog.h:557
basic_string_view< char > string_view
Definition: core.h:520
type
Definition: core.h:575
FMT_CONSTEXPR auto write(OutputIt out, Char value, const basic_format_specs< Char > &specs, locale_ref loc={}) -> OutputIt
Definition: format.h:1881
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
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
Definition: AprilTagFieldLayout.h:18
::std::mutex mutex
Definition: mutex.h:17
::std::condition_variable condition_variable
Definition: condition_variable.h:16
Definition: format.h:1552