File indexing completed on 2024-04-28 15:34:47
0001 /* -*- C++ -*- 0002 This file is part of ThreadWeaver. 0003 0004 SPDX-FileCopyrightText: 2005-2013 Mirko Boehm <mirko@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "src/thread.h" 0010 0011 #include "JobLoggingDecorator.h" 0012 0013 using namespace ThreadWeaver; 0014 0015 JobLoggingDecorator::JobLoggingDecorator(const JobPointer &job, JobLoggingDecoratorCollector *collector) 0016 : IdDecorator(job.data(), false) 0017 , collector_(collector) 0018 { 0019 Q_ASSERT(collector); 0020 } 0021 0022 void JobLoggingDecorator::run(JobPointer self, Thread *thread) 0023 { 0024 data_.start = collector_->time(); 0025 if (thread) { 0026 data_.threadId = thread->id(); 0027 } else { 0028 data_.threadId = -1; 0029 } 0030 IdDecorator::run(self, thread); 0031 data_.end = collector_->time(); 0032 collector_->storeJobData(data_); 0033 } 0034 0035 JobLoggingDecoratorCollector::JobLoggingDecoratorCollector() 0036 { 0037 elapsed_.start(); 0038 start_ = QDateTime::currentDateTime(); 0039 } 0040 0041 void JobLoggingDecoratorCollector::storeJobData(const JobLoggingDecorator::JobData &data) 0042 { 0043 QMutexLocker m(&mutex_); 0044 jobData_.append(data); 0045 } 0046 0047 qint64 JobLoggingDecoratorCollector::time() 0048 { 0049 return elapsed_.nsecsElapsed(); 0050 }