diff options
author | Tim Barron <tjbarron@google.com> | 2022-08-11 17:05:22 -0700 |
---|---|---|
committer | Tim Barron <tjbarron@google.com> | 2022-08-11 17:05:22 -0700 |
commit | 87267cbc5531600072a283ba0c9500c3fcac87af (patch) | |
tree | 2ec5c19afb1f4d5ee229d0619c25b2f2819ccea0 /icing/util/clock.h | |
parent | 7c93c404e1fb4ed5e35326245ebc820ed774c6b2 (diff) | |
download | icing-87267cbc5531600072a283ba0c9500c3fcac87af.tar.gz |
Sync from upstream.
Descriptions:
======================================================================
Implement new version of ResultState and ResultStateManager to 1)
enforce a page byte size limit and 2) improve handling of pagination
when we encounter deleted documents.
======================================================================
Fix bugs in IcingDynamicTrie::Delete.
======================================================================
Implement IcingDynamicTrie::IsBranchingTerm.
======================================================================
Change Icing default logging level to INFO
======================================================================
Refactor KeyMapper class to be an interface.
======================================================================
Improve NamespaceChecker logic to improve Suggest latency.
======================================================================
Change icing native log tag to "AppSearchIcing"
======================================================================
Implement Index Compaction rather than rebuilding index during
Compaction.
======================================================================
Implement reverse iterator for IcingDynamicTrie
======================================================================
Avoid adding unnecessary branch points during index compaction
======================================================================
Invalidate expired result states when adding to/retrieving from
ResultStateManager.
======================================================================
Add new methods (MutableView, MutableArrayView, Append, Allocate) to
FileBackedVector
======================================================================
Create and implement PersistentHashMap class.
======================================================================
Implement RFC822 Tokenizer
======================================================================
Remove uses of StringPrintf in ICING_LOG statements
======================================================================
Properly set query latency when an error is encountered or results are
empty.
======================================================================
Bug: 146903474
Bug: 152934343
Bug: 193919210
Bug: 193453081
Bug: 231368517
Bug: 235395538
Bug: 236412165
Change-Id: I8aa278cebb12b25b39deb0ef584c0f198952659d
Diffstat (limited to 'icing/util/clock.h')
-rw-r--r-- | icing/util/clock.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/icing/util/clock.h b/icing/util/clock.h index 2bb7818..9e57854 100644 --- a/icing/util/clock.h +++ b/icing/util/clock.h @@ -16,6 +16,7 @@ #define ICING_UTIL_CLOCK_H_ #include <cstdint> +#include <functional> #include <memory> namespace icing { @@ -69,6 +70,32 @@ class Clock { virtual std::unique_ptr<Timer> GetNewTimer() const; }; +// A convenient RAII timer class that receives a callback. Upon destruction, the +// callback will be called with the elapsed milliseconds or nanoseconds passed +// as a parameter, depending on which Unit was passed in the constructor. +class ScopedTimer { + public: + enum class Unit { kMillisecond, kNanosecond }; + + ScopedTimer(std::unique_ptr<Timer> timer, + std::function<void(int64_t)> callback, + Unit unit = Unit::kMillisecond) + : timer_(std::move(timer)), callback_(std::move(callback)), unit_(unit) {} + + ~ScopedTimer() { + if (unit_ == Unit::kMillisecond) { + callback_(timer_->GetElapsedMilliseconds()); + } else { + callback_(timer_->GetElapsedNanoseconds()); + } + } + + private: + std::unique_ptr<Timer> timer_; + std::function<void(int64_t)> callback_; + Unit unit_; +}; + } // namespace lib } // namespace icing |