HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_UniversalLogInMemorySink.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_UniversalLogInMemorySink.h ( FS Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UT_UniversalLogInMemorySink__
13 #define __UT_UniversalLogInMemorySink__
14 
15 #include "UT_API.h"
16 #include "UT_Lock.h"
17 #include "UT_SharedPtr.h"
18 #include "UT_UniversalLogEntry.h"
19 #include "UT_UniversalLogSink.h"
20 #include <SYS/SYS_Types.h>
21 #include <SYS/SYS_AtomicInt.h>
22 
23 class UT_StringRef;
24 
25 /// This class is a universal log sync which stores all log entries in memory.
26 /// A maximum memory use threshold can be set, and excess messages are
27 /// automatically deleted.
29 {
30 public:
32  ~UT_UniversalLogInMemorySink() override;
33 
34  /// Returns the number of log entries currently in memory. An entry may
35  /// become "inactive" (i.e. flushed from memory) when this sink reaches
36  /// its maximum log count, or if someone steals our log entries.
37  exint activeLogCount();
38  /// Returns the number of log entries we have ever seen. It can be useful
39  /// to have this monotonically increasing number to look for changes and
40  /// insulate from the automated (or manual) purging of log entries.
41  exint allTimeLogCount();
42  /// Returns a copy of the active log entry at a specific index. If the
43  /// index is out of range, an empty log entry is returned.
44  UT_UniversalLogEntry activeLogEntry(exint active_idx);
45  /// Returns a copy of the log entry at a specific all-time index. If the
46  /// index is out of range, or is no longer active, an empty log entry is
47  /// returned.
48  UT_UniversalLogEntry allTimeLogEntry(exint all_time_idx);
49  /// Steals all current log entries into the supplied array. This object
50  /// will no longer have any record of these log entries after this call.
51  void stealLogEntries(UT_UniversalLogEntryArray &log);
52 
53 protected:
54  /// This override stores the log messages in memory.
55  void doLog(const UT_UniversalLogEntry &entry) override;
56 
57  /// Grab messages from the inbound log entries and add them to the
58  /// inspectable log entries. This function also enforces the maximum
59  /// total message size.
60  ///
61  /// NOTE: myDataLock MUST be locked before calling this method.
62  void adoptInboundLogEntries();
63 
64  /// The inbound message queue is where events get logged, but messages
65  /// on this queue cannot be inspected. We never want the addition of
66  /// new messages to be blocked by some (potentially slow) inspection of
67  /// the current set of messages.
71  /// These log entries are the ones that have been collected from the
72  /// inbound queue. And filtering and sorting happens during this
73  /// transition.
78  /// A counter that is increased any time a message is added.
80 };
81 
82 UT_API bool
84 UT_API bool
85 UTisDefaultLogSource(const UT_StringRef &source_name);
87 UTgetDefaultLogInMemorySink(bool create_from_env, bool force_create);
88 
89 #endif
90 
UT_API bool UTisDefaultLogSource(const UT_StringRef &source_name)
UT_API const UT_SharedPtr< UT_UniversalLogInMemorySink > & UTgetDefaultLogInMemorySink(bool create_from_env, bool force_create)
UT_API bool UThasAnyDefaultLogSources()
int64 exint
Definition: SYS_Types.h:125
#define UT_API
Definition: UT_API.h:14
UT_UniversalLogEntryArray myLogEntries
SYS_AtomicCounter myAllTimeLogCount
A counter that is increased any time a message is added.
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
virtual void doLog(const UT_UniversalLogEntry &entry)=0
UT_UniversalLogEntryArray myInboundLogEntries
OIIO_FORCEINLINE T log(const T &v)
Definition: simd.h:7688
Simple object to hold the data associated with a single log entry event.