Commits

muntoo committed f4d9666

Added NXPROFILER_COUNT and NXPROFILER_EMPTYCOUNT.

  • Participants
  • Parent commits 684056c

Comments (0)

Files changed (3)

File NxProfiler-Demo.nxc

 */
 
 
+#define PROFILER_ENABLE
+
+
 #include "NxProfiler.nxc"
 #include "strreverse.nxc"
 #include "itoa.nxc"
 
 task main()
 {
-	NxProfiler_Start();
+	NxProfiler_Start(NXPROFILER_DEFAULT);
 
 
-	// 1000 characters
-	string sz = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
+	// 100 characters
+	string sz = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
+	// Large string crashes strreverse(), when using profiler?
 
 	NxProfiler_Begin(0);
 
 		NxProfiler_Begin(1);
 
 		sz = strreverse(sz);
-
+		
 		NxProfiler_End(1);
 	}
 
 	NxProfiler_End(0);
 
-	NxProfiler_Stop("NxProfiler-Demo.prf");
+
+	NxProfiler_Stop("NxProfiler-Demo.prf", NXPROFILER_DEFAULT);
 }

File NxProfiler-Demo.prf

Binary file modified.

File NxProfiler.nxc

 	#define NXPROFILER_FILE_FORMAT_HTH	0x00000001 // Flags, Sizes, Total, History
 
 
-	#define NXPROFILER_DEFAULT	0x01
-	#define NXPROFILER_TOTAL	0x01
-	#define NXPROFILER_HISTORY	0x02
-	// #define NXPROFILER_?????	0x04
+	#define NXPROFILER_DEFAULT		0x07
+	#define NXPROFILER_COUNT		0x01
+	#define NXPROFILER_EMPTYCOUNT	0x02
+	#define NXPROFILER_TOTAL		0x04
+	#define NXPROFILER_HISTORY		0x08
 
 
 	#ifdef PROFILER_ENABLE
 	unsigned long NxProfile_file_format = NXPROFILER_FILE_FORMAT_HTH;
 
 
-	unsigned long NxProfiler_flags = NXPROFILER_TOTAL;
+	unsigned long NxProfiler_flags = NXPROFILER_DEFAULT;
 
 
 	unsigned long NxProfiler_ids = 0;
 	unsigned long NxProfiler_timer[];
 	unsigned int NxProfiler_timer_len = 0;
 
+	unsigned long NxProfiler_count[];
+	unsigned int NxProfiler_count_len = 0;
+	
+	unsigned long NxProfiler_emptycount[];
+	unsigned int NxProfiler_emptycount_len = 0;
+	
 	unsigned long NxProfiler_total[];
 	unsigned int NxProfiler_total_len = 0;
 
 	unsigned int NxProfiler_history_len_d2[];
 
 
-	void NxProfiler_Start(unsigned long flags = NXPROFILER_TOTAL,
+	void NxProfiler_Start(unsigned long flags = NXPROFILER_DEFAULT,
 						  unsigned int prealloc = 0)
 	{
 		NxProfiler_flags = flags;
 		NxProfiler_timer_len = prealloc;
 		ArrayInit(NxProfiler_timer, 0, NxProfiler_timer_len);
 
+		if(NxProfiler_flags & NXPROFILER_COUNT)
+		{
+			NxProfiler_count_len = prealloc;
+			ArrayInit(NxProfiler_count, 0, NxProfiler_count_len);
+		}
+		
+		if(NxProfiler_flags & NXPROFILER_EMPTYCOUNT)
+		{
+			NxProfiler_emptycount_len = prealloc;
+			ArrayInit(NxProfiler_emptycount, 0, NxProfiler_emptycount_len);
+		}
+		
 		if(NxProfiler_flags & NXPROFILER_TOTAL)
 		{
 			NxProfiler_total_len = prealloc;
 
 
 	void NxProfiler_Stop(string fname = "NxProfiler.prf",
-						 unsigned long flags = NxProfiler_flags)
+						 unsigned long flags = 0)
 	{
+		if(flags == 0)
+		{
+			flags = NxProfiler_flags;
+		}
+
+
 		byte handle;
 		unsigned int fsize = 8; // sizeof(NxProfile_file_format) + sizeof(NxProfiler_flags)
 		unsigned int length = 4;
 
 
+		if(NxProfiler_flags & NXPROFILER_COUNT)
+		{
+			fsize += 2 +							// sizeof(NxProfiler_count_len)
+					 (NxProfiler_count_len * 4);	// sizeof(NxProfiler_count)
+
+		}
+		
+		if(NxProfiler_flags & NXPROFILER_EMPTYCOUNT)
+		{
+			fsize += 2 +							// sizeof(NxProfiler_count_len)
+					 (NxProfiler_emptycount_len * 4);	// sizeof(NxProfiler_count)
+
+		}
+		
 		if(NxProfiler_flags & NXPROFILER_TOTAL)
 		{
 			fsize += 2 +							// sizeof(NxProfiler_total_len)
 					 (NxProfiler_total_len * 4);	// sizeof(NxProfiler_total)
 
 		}
-
+		
 		if(NxProfiler_flags & NXPROFILER_HISTORY)
 		{
 			fsize += 2 +								// sizeof(NxProfiler_history_len_d1)
 		Write(handle, NxProfile_file_format);
 		Write(handle, NxProfiler_flags);
 
-
+		
+		if(NxProfiler_flags & NXPROFILER_COUNT)
+		{
+			Write(handle, NxProfiler_count_len);
+		}
+		
+		if(NxProfiler_flags & NXPROFILER_EMPTYCOUNT)
+		{
+			Write(handle, NxProfiler_emptycount_len);
+		}
+		
 		if(NxProfiler_flags & NXPROFILER_TOTAL)
 		{
 			Write(handle, NxProfiler_total_len);
 			}
 		}
 
-
+		if(NxProfiler_flags & NXPROFILER_COUNT)
+		{
+			for(unsigned int i = 0; i < NxProfiler_count_len; ++i)
+			{
+				unsigned long ulval = NxProfiler_count[i];
+				Write(handle, ulval);
+			}
+		}
+		
+		if(NxProfiler_flags & NXPROFILER_EMPTYCOUNT)
+		{
+			for(unsigned int i = 0; i < NxProfiler_emptycount_len; ++i)
+			{
+				unsigned long ulval = NxProfiler_emptycount[i];
+				Write(handle, ulval);
+			}
+		}
+		
 		if(NxProfiler_flags & NXPROFILER_TOTAL)
 		{
 			for(unsigned int i = 0; i < NxProfiler_total_len; ++i)
 			PUSH(unsigned long, NxProfiler_timer, buf)
 			NxProfiler_timer_len += buf_len;
 
-
+		
+			if(NxProfiler_flags & NXPROFILER_COUNT)
+			{
+				PUSH(unsigned long, NxProfiler_count, buf)
+				NxProfiler_count_len += buf_len;
+			}
+			
+			if(NxProfiler_flags & NXPROFILER_EMPTYCOUNT)
+			{
+				PUSH(unsigned long, NxProfiler_emptycount, buf)
+				NxProfiler_emptycount_len += buf_len;
+			}
+			
 			if(NxProfiler_flags & NXPROFILER_TOTAL)
 			{
 				PUSH(unsigned long, NxProfiler_total, buf)
 				ArrayInit(buf_d2, buf, id - NxProfiler_ids + 1);
 				ArrayBuild(NxProfiler_history, NxProfiler_history, buf_d2);
 		#else
-
+				ArrayInit(buf, 0, 0);
+				ArrayBuild(NxProfiler_history, NxProfiler_history, buf);
 		#endif
 
 				NxProfiler_history_len_d1 += buf_len;
 		NxProfiler_IncreaseSize(id);
 
 
+		if(NxProfiler_flags & NXPROFILER_COUNT)
+		{
+			NxProfiler_count[id]++;
+		}
+		
+		if(NxProfiler_flags & NXPROFILER_EMPTYCOUNT)
+		{
+			if(dTime == 0)
+			{
+				NxProfiler_emptycount[id]++;
+			}
+		}
+		
 		if(NxProfiler_flags & NXPROFILER_TOTAL)
 		{
 			NxProfiler_total[id] += dTime;
 		}
-
+		
 
 		if(NxProfiler_flags & NXPROFILER_HISTORY)
 		{
+			// Push dTime onto NxProfiler_history[id];
+
 			unsigned long buf[];
-			buf = NxProfiler_history[id];
 
-			ArrayBuild(buf, dTime);
+			// buf = NxProfiler_history[id];
+			asm { index buf, NxProfiler_history, id }
 
+			ArrayBuild(buf, buf, dTime);
+
+			/// Does this work?
 			NxProfiler_history[id] = buf;
 
 			++NxProfiler_history_len;
 	#else
 
 
-	void NxProfiler_Start(unsigned long flags = NXPROFILER_TOTAL,
+	void NxProfiler_Start(unsigned long flags = NXPROFILER_DEFAULT,
 						  unsigned int prealloc = 0)
 	{
 	}
 
 
 	void NxProfiler_Stop(string fname = "NxProfiler.prf",
-						 unsigned long flags = NxProfiler_flags)
+						 unsigned long flags = 0)
 	{
 	}