VRS
A file format for sensor data.
Loading...
Searching...
No Matches
ProgressLogger.h
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <string>
20
21namespace vrs {
22
23using std::string;
24
32 public:
33 static constexpr double kDefaultUpdateDelay = 2;
38 explicit ProgressLogger(bool detailedProgress = false, double updateDelay = kDefaultUpdateDelay);
39 virtual ~ProgressLogger();
40
44 virtual void setStepCount(int stepCount);
47 virtual void setDetailedProgress(bool detailedProgress);
50 bool getDetailedProgress() const {
51 return detailedProgress_;
52 }
53
59 virtual bool logNewStep(const string& stepName, size_t progress = 0, size_t maxProgress = 100);
60
67 bool logProgress(const string& stepName, size_t progress = 0, size_t maxProgress = 100) {
68 return logProgress(stepName, progress, maxProgress, false);
69 }
72 bool logProgress(const string& stepName, int64_t progress, int64_t maxProgress) {
73 return logProgress(
74 stepName, static_cast<size_t>(progress), static_cast<size_t>(maxProgress), false);
75 }
76
81 virtual bool logStatus(const string& stepName, int status = 0);
82
88 virtual bool logDuration(const string& operationName, double duration, int precision = 1);
89
90 protected:
96 virtual bool
97 logProgress(const string& stepName, size_t progress, size_t maxProgress, bool newStep);
101 virtual void logMessage(const string& message);
105 virtual void logErrorMessage(const string& message);
109 virtual void updateStep(size_t progress = 0, size_t maxProgress = 100);
111 virtual void updateNextProgressTime();
116 virtual bool shouldKeepGoing();
117
118 protected:
119 bool detailedProgress_;
120 double updateDelay_;
121 int stepNumber_;
122 int stepCount_;
123 double nextProgressTime_;
124};
125
128 public:
129 ~SilentLogger() override;
130 bool logProgress(const string&, size_t = 0, size_t = 100, bool = false) override {
131 return true;
132 }
133 bool logStatus(const string&, int = 0) override {
134 return true;
135 }
136 bool logDuration(const string& /*operationName*/, double /*duration*/, int /*precision*/ = 1)
137 override {
138 return true;
139 }
140};
141
142} // namespace vrs
ProgressLogger class to be notified of some process' progress.
Definition ProgressLogger.h:31
virtual bool logDuration(const string &operationName, double duration, int precision=1)
Definition ProgressLogger.cpp:93
virtual bool shouldKeepGoing()
Definition ProgressLogger.cpp:56
virtual void setDetailedProgress(bool detailedProgress)
Definition ProgressLogger.cpp:45
bool logProgress(const string &stepName, size_t progress=0, size_t maxProgress=100)
Definition ProgressLogger.h:67
virtual void setStepCount(int stepCount)
Definition ProgressLogger.cpp:39
bool logProgress(const string &stepName, int64_t progress, int64_t maxProgress)
Definition ProgressLogger.h:72
virtual bool logStatus(const string &stepName, int status=0)
Definition ProgressLogger.cpp:81
virtual void updateNextProgressTime()
Callback to schedule the time of the next text update.
Definition ProgressLogger.cpp:103
virtual void logMessage(const string &message)
Definition ProgressLogger.cpp:107
virtual bool logNewStep(const string &stepName, size_t progress=0, size_t maxProgress=100)
Definition ProgressLogger.cpp:49
virtual void logErrorMessage(const string &message)
Definition ProgressLogger.cpp:111
bool getDetailedProgress() const
Definition ProgressLogger.h:50
virtual void updateStep(size_t progress=0, size_t maxProgress=100)
Definition ProgressLogger.cpp:115
Progress logger to ignore all progress notifications.
Definition ProgressLogger.h:127
bool logDuration(const string &, double, int=1) override
Definition ProgressLogger.h:136
bool logStatus(const string &, int=0) override
Definition ProgressLogger.h:133
bool logProgress(const string &, size_t=0, size_t=100, bool=false) override
Definition ProgressLogger.h:130
Definition AsyncDiskFileChunk.hpp:49