Commit 88d5d83f authored by David Wiesner's avatar David Wiesner
Browse files

ADD: Measuring waiting time until lock is acquired.

parent 7f3e2abb
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -65,6 +65,11 @@ std::string GetSceneTypeStr(const scene_type &sceneType)

lock_handle SceneLocks::checkAndLock(CustomLock* newLock)
{
#ifdef MITOGEN_DEBUG_MULTITHREADING
	// get start time
	const report_clock::time_point startTime = report_clock::now();	
#endif	
				
	bool lockAcquired = false;

	std::unique_lock<std::mutex> listSearchLock(listSearchLock_st);
@@ -125,8 +130,17 @@ lock_handle SceneLocks::checkAndLock(CustomLock* newLock)
			// *** Lock acquired ***
			listOfCustomLocks.push_back(newLock);
			lockAcquired = true;
			
#ifdef MITOGEN_DEBUG_MULTITHREADING
			newLock->printLockInfo();
			// get current time
			const report_clock::time_point currentTime = report_clock::now();	
			
			// get elapsed time
			const report_clock::duration timeToAcquireLock = currentTime - startTime;
			const std::chrono::milliseconds timeToAcquireLock_ms =
				std::chrono::duration_cast<std::chrono::milliseconds>(timeToAcquireLock);
			
			newLock->printLockInfo(timeToAcquireLock_ms);
#endif
#ifdef GTGEN_WITH_LOCKVISUALIZATION
			// save visualization
+21 −33
Original line number Diff line number Diff line
@@ -101,7 +101,14 @@ public:
	size_t getToTimePoint() const
	{ return toTimePoint; }
	
	virtual void printLockInfo() const = 0;
	// wrapper for printLockInfo
	void printLockInfo() const
	{
		const std::chrono::milliseconds timeToAcquireLock(0);
		printLockInfo(timeToAcquireLock);
	}
	
	virtual void printLockInfo(const std::chrono::milliseconds timeToAcquireLock) const = 0;
	
protected:
	
@@ -132,21 +139,13 @@ public:
	lock_type getLockType() const
	{ return timePoint_lock; }
	
	void printLockInfo() const
	{
		if (fromTimePoint == toTimePoint)
	void printLockInfo(const std::chrono::milliseconds timeToAcquireLock) const
	{
			REPORT("TIME lock, timePoint "
				<< fromTimePoint
		REPORT("TIME lock"
			<< ", waiting time: " << timeToAcquireLock.count() << "ms"
			<< ", timePoint: " << fromTimePoint << "-" << toTimePoint
			<< ", sceneType: " << GetSceneTypeStr(sceneType));
	}
		else
		{
			REPORT("TIME lock, timePoint "
				<< fromTimePoint << "-" << toTimePoint
				<< ", sceneType: " << GetSceneTypeStr(sceneType));
		}
	}
};


@@ -199,27 +198,16 @@ public:
	size_t getCellID() const
	{ return cellID; }
	
	void printLockInfo() const
	{
		if (fromTimePoint == toTimePoint)
	void printLockInfo(const std::chrono::milliseconds timeToAcquireLock) const
	{
		REPORT("SPHERE lock"
				<< ", timePoint " << fromTimePoint 
			<< ", waiting time: " << timeToAcquireLock.count() << "ms"
			<< ", timePoint: " << fromTimePoint << "-" << toTimePoint
			<< ", sceneType: " << GetSceneTypeStr(sceneType)
			<< ", centre: [" << sphereCentre.x << ", "
			<< sphereCentre.y << ", " << sphereCentre.z
			<< "], radius: " << sphereRadius);		
	}
		else
		{
			REPORT("SPHERE lock"
				<< ", timePoint " << fromTimePoint << "-" << toTimePoint
				<< ", sceneType: " << GetSceneTypeStr(sceneType)
				<< ", centre: [" << sphereCentre.x << ", "
				<< sphereCentre.y << ", " << sphereCentre.z
				<< "], radius: " << sphereRadius);		
		}
	}
	
private: