1 #ifndef CPPAD_CG_JOB_TIMER_INCLUDED 2 #define CPPAD_CG_JOB_TIMER_INCLUDED 33 std::string _actionEnd;
36 inline JobType(
const std::string& action,
37 const std::string& actionEnd) :
39 _actionEnd(actionEnd) {
42 inline const std::string& getActionName()
const {
46 inline void setActionName(
const std::string& action) {
50 inline const std::string& getActionEndName()
const {
54 inline void setActionEndName(
const std::string& actionEnd) {
55 _actionEnd = actionEnd;
69 static const JobType LOOP_DETECTION;
71 static const JobType SOURCE_FOR_MODEL;
72 static const JobType SOURCE_GENERATION;
73 static const JobType COMPILING_FOR_MODEL;
75 static const JobType COMPILING_DYNAMIC_LIBRARY;
76 static const JobType DYNAMIC_MODEL_LIBRARY;
77 static const JobType STATIC_MODEL_LIBRARY;
78 static const JobType ASSEMBLE_STATIC_LIBRARY;
79 static const JobType JIT_MODEL_LIBRARY;
134 std::chrono::steady_clock::time_point _beginTime;
142 const std::string& name) :
145 _beginTime(std::chrono::steady_clock::now()),
149 inline const JobType& getType()
const {
153 inline const std::string& name()
const {
157 inline std::chrono::steady_clock::time_point beginTime()
const {
161 inline virtual ~
Job() {
172 using duration = std::chrono::steady_clock::duration;
174 virtual void jobStarted(
const std::vector<Job>& job) = 0;
176 virtual void jobEndended(
const std::vector<Job>& job,
177 duration elapsed) = 0;
194 std::vector<Job> _jobs;
198 size_t _maxLineWidth;
206 std::ostringstream _os;
214 std::string _actionEnd;
218 std::set<JobListener*> _listeners;
227 inline bool isVerbose()
const {
231 inline void setVerbose(
bool verbose) {
235 inline size_t getMaxLineWidth()
const {
236 return _maxLineWidth;
239 inline void setMaxLineWidth(
size_t width) {
240 _maxLineWidth = width;
253 _listeners.insert(&l);
257 return _listeners.erase(&l) > 0;
260 inline void startingJob(
const std::string& jobName,
262 const std::string& prefix =
"") {
264 _jobs.push_back(
Job(type, jobName));
269 Job& job = _jobs.back();
272 if (_jobs.size() > 1) {
273 Job& parent = _jobs[_jobs.size() - 2];
274 if (!parent._nestedJobs) {
275 parent._nestedJobs =
true;
278 indent = _indent * (_jobs.size() - 1);
282 if (indent > 0) _os << std::string(indent,
' ');
283 if (!prefix.empty()) _os << prefix <<
" ";
284 _os << type.getActionName() <<
" " << job.name() <<
" ...";
286 char f = std::cout.fill();
287 std::cout << std::setw(_maxLineWidth) << std::setfill(
'.') << std::left << _os.str();
294 l->jobStarted(_jobs);
298 inline void finishedJob() {
299 using namespace std::chrono;
301 CPPADCG_ASSERT_UNKNOWN(_jobs.size() > 0);
303 Job& job = _jobs.back();
305 std::chrono::steady_clock::duration elapsed = steady_clock::now() - job.beginTime();
310 if (job._nestedJobs) {
313 _os << std::string(_indent * (_jobs.size() - 1),
' ');
314 _os << job.getType().getActionEndName() <<
" " << job.name() <<
" ...";
316 char f = std::cout.fill();
317 std::cout << std::setw(_maxLineWidth) << std::setfill(
'.') << std::left << _os.str();
321 std::cout <<
" done [" << std::fixed << std::setprecision(3) << duration<float>(elapsed).count() <<
"]" << std::endl;
326 l->jobEndended(_jobs, elapsed);
size_t getJobCount() const