Browse Source

PerformanceTest now creates named profile dumps

Jorrit Rouwe 3 years ago
parent
commit
2e13314a26
3 changed files with 32 additions and 17 deletions
  1. 23 10
      Jolt/Core/Profiler.cpp
  2. 8 6
      Jolt/Core/Profiler.h
  3. 1 1
      PerformanceTest/PerformanceTest.cpp

+ 23 - 10
Jolt/Core/Profiler.cpp

@@ -35,9 +35,10 @@ void Profiler::NextFrame()
 		t->mCurrentSample = 0;
 		t->mCurrentSample = 0;
 }
 }
 
 
-void Profiler::Dump()
+void Profiler::Dump(string inTag)
 {
 {
 	mDump = true;
 	mDump = true;
+	mDumpTag = inTag;
 }
 }
 
 
 void Profiler::AddThread(ProfileThread *inThread)										
 void Profiler::AddThread(ProfileThread *inThread)										
@@ -133,9 +134,21 @@ void Profiler::DumpInternal()
 			s->mEndCycle -= min_cycle;
 			s->mEndCycle -= min_cycle;
 		}
 		}
 
 
-	// Next sequence number
-	static int number = 0;
-	++number;
+	// Determine tag of this profile
+	string tag;
+	if (mDumpTag.empty())
+	{
+		// Next sequence number
+		static int number = 0;
+		++number;
+		tag = ConvertToString(number);
+	}
+	else
+	{
+		// Take provided tag
+		tag = mDumpTag;
+		mDumpTag.clear();
+	}
 
 
 	// Aggregate data across threads
 	// Aggregate data across threads
 	Aggregators aggregators;
 	Aggregators aggregators;
@@ -145,10 +158,10 @@ void Profiler::DumpInternal()
 			sAggregate(0, Color::sGetDistinctColor(0).GetUInt32(), s, end, aggregators, key_to_aggregators);
 			sAggregate(0, Color::sGetDistinctColor(0).GetUInt32(), s, end, aggregators, key_to_aggregators);
 
 
 	// Dump as list
 	// Dump as list
-	DumpList(number, aggregators);
+	DumpList(tag, aggregators);
 
 
 	// Dump as chart
 	// Dump as chart
-	DumpChart(number, threads, key_to_aggregators, aggregators);
+	DumpChart(tag, threads, key_to_aggregators, aggregators);
 }
 }
 
 
 static string sHTMLEncode(string inString)
 static string sHTMLEncode(string inString)
@@ -159,11 +172,11 @@ static string sHTMLEncode(string inString)
 	return str;
 	return str;
 }
 }
 
 
-void Profiler::DumpList(int inNumber, const Aggregators &inAggregators)
+void Profiler::DumpList(string inTag, const Aggregators &inAggregators)
 {
 {
 	// Open file
 	// Open file
 	ofstream f;
 	ofstream f;
-	f.open(StringFormat("profile_list_%d.html", inNumber).c_str(), ofstream::out | ofstream::trunc);
+	f.open(StringFormat("profile_list_%s.html", inTag.c_str()).c_str(), ofstream::out | ofstream::trunc);
 	if (!f.is_open()) 
 	if (!f.is_open()) 
 		return;
 		return;
 
 
@@ -239,11 +252,11 @@ void Profiler::DumpList(int inNumber, const Aggregators &inAggregators)
 	f << R"(</tbody></table></body></html>)";
 	f << R"(</tbody></table></body></html>)";
 }
 }
 
 
-void Profiler::DumpChart(int inNumber, const Threads &inThreads, const KeyToAggregator &inKeyToAggregators, const Aggregators &inAggregators)
+void Profiler::DumpChart(string inTag, const Threads &inThreads, const KeyToAggregator &inKeyToAggregators, const Aggregators &inAggregators)
 {
 {
 	// Open file
 	// Open file
 	ofstream f;
 	ofstream f;
-	f.open(StringFormat("profile_chart_%d.html", inNumber).c_str(), ofstream::out | ofstream::trunc);
+	f.open(StringFormat("profile_chart_%s.html", inTag.c_str()).c_str(), ofstream::out | ofstream::trunc);
 	if (!f.is_open()) 
 	if (!f.is_open()) 
 		return;
 		return;
 
 

+ 8 - 6
Jolt/Core/Profiler.h

@@ -38,7 +38,7 @@ private:
 #define JPH_PROFILE_THREAD_START(name)			
 #define JPH_PROFILE_THREAD_START(name)			
 #define JPH_PROFILE_THREAD_END()				
 #define JPH_PROFILE_THREAD_END()				
 #define JPH_PROFILE_NEXTFRAME()			
 #define JPH_PROFILE_NEXTFRAME()			
-#define JPH_PROFILE_DUMP()				
+#define JPH_PROFILE_DUMP(...)				
 								
 								
 // Scope profiling measurement
 // Scope profiling measurement
 #define JPH_PROFILE_TAG2(line)		profile##line
 #define JPH_PROFILE_TAG2(line)		profile##line
@@ -73,7 +73,8 @@ public:
 	void						NextFrame();
 	void						NextFrame();
 
 
 	/// Dump profiling statistics at the start of the next frame
 	/// Dump profiling statistics at the start of the next frame
-	void						Dump();
+	/// @param inTag If not empty, this overrides the auto incrementing number in the filename of the dump file
+	void						Dump(string inTag = string());
 
 
 	/// Add a thread to be instrumented
 	/// Add a thread to be instrumented
 	void						AddThread(ProfileThread *inThread);
 	void						AddThread(ProfileThread *inThread);
@@ -136,12 +137,13 @@ private:
 
 
 	/// Dump profiling statistics
 	/// Dump profiling statistics
 	void						DumpInternal();
 	void						DumpInternal();
-	void						DumpList(int inNumber, const Aggregators &inAggregators);
-	void						DumpChart(int inNumber, const Threads &inThreads, const KeyToAggregator &inKeyToAggregators, const Aggregators &inAggregators);
+	void						DumpList(string inTag, const Aggregators &inAggregators);
+	void						DumpChart(string inTag, const Threads &inThreads, const KeyToAggregator &inKeyToAggregators, const Aggregators &inAggregators);
 
 
 	mutex						mLock;																///< Lock that protects mThreads
 	mutex						mLock;																///< Lock that protects mThreads
 	vector<ProfileThread *>		mThreads;															///< List of all active threads
 	vector<ProfileThread *>		mThreads;															///< List of all active threads
 	bool						mDump = false;														///< When true, the samples are dumped next frame
 	bool						mDump = false;														///< When true, the samples are dumped next frame
+	string						mDumpTag;															///< When not empty, this overrides the auto incrementing number of the dump filename
 };							
 };							
 
 
 // Class that contains the information of a single scoped measurement
 // Class that contains the information of a single scoped measurement
@@ -214,7 +216,7 @@ private:
 #define JPH_PROFILE_NEXTFRAME()			Profiler::sInstance.NextFrame()
 #define JPH_PROFILE_NEXTFRAME()			Profiler::sInstance.NextFrame()
 
 
 /// Dump profiling info
 /// Dump profiling info
-#define JPH_PROFILE_DUMP()				Profiler::sInstance.Dump()
+#define JPH_PROFILE_DUMP(...)			Profiler::sInstance.Dump(__VA_ARGS__)
 
 
 #else
 #else
 
 
@@ -227,6 +229,6 @@ private:
 #define JPH_PROFILE(...)
 #define JPH_PROFILE(...)
 #define JPH_PROFILE_FUNCTION()
 #define JPH_PROFILE_FUNCTION()
 #define JPH_PROFILE_NEXTFRAME()
 #define JPH_PROFILE_NEXTFRAME()
-#define JPH_PROFILE_DUMP()
+#define JPH_PROFILE_DUMP(...)
 
 
 #endif
 #endif

+ 1 - 1
PerformanceTest/PerformanceTest.cpp

@@ -226,7 +226,7 @@ int main(int argc, char** argv)
 				// Dump profile information every 100 iterations
 				// Dump profile information every 100 iterations
 				if (iterations % 100 == 0)
 				if (iterations % 100 == 0)
 				{
 				{
-					JPH_PROFILE_DUMP();
+					JPH_PROFILE_DUMP(ToLower(motion_quality_str) + "_th" + ConvertToString(num_threads + 1) + "_it" + ConvertToString(iterations));
 				}
 				}
 			}
 			}