Browse Source

!5 性能测试调优,修改部分占用cpu操作。

80374463 6 years ago
parent
commit
06efbbee09
1 changed files with 47 additions and 44 deletions
  1. 47 44
      spbase/sp_gui.cpp

+ 47 - 44
spbase/sp_gui.cpp

@@ -348,7 +348,8 @@ static int DrawLineString(Graphics &graphics, wstring &msg, Font *font, RectF &r
 
 		format->SetMeasurableCharacterRanges(nCount, crs);
 
-		graphics.MeasureCharacterRanges(msg.substr(nFrom + nLineCount, nCount).c_str(), nCount, font, layoutRect, format, nCount, regions);
+		//tempMsg = msg.substr(nFrom + nLineCount, nCount);
+		graphics.MeasureCharacterRanges(msg.data() + nFrom + nLineCount, nCount, font, layoutRect, format, nCount, regions);
 	
 		for (int i = 0; i < nCount; i++)
 		{
@@ -378,8 +379,8 @@ static int DrawLineString(Graphics &graphics, wstring &msg, Font *font, RectF &r
 						nLineCount++;
 				}
 
-				auto wszLine = msg.substr(nFrom, nLineCount);
-				graphics.DrawString(wszLine.c_str(), nLineCount, font, layoutRect, format, brush);
+				//auto wszLine = msg.substr(nFrom, nLineCount);
+				graphics.DrawString(msg.data() + nFrom, nLineCount, font, layoutRect, format, brush);
 
 				// reset  vars
 				nFrom += nLineCount;
@@ -400,7 +401,7 @@ static int DrawLineString(Graphics &graphics, wstring &msg, Font *font, RectF &r
 	// output last line
 	if (nLineCount > 0)
 	{
-		graphics.DrawString(msg.substr(nFrom, nLineCount).c_str(), nLineCount, font, layoutRect, format, brush);
+		graphics.DrawString(msg.data() + nFrom, nLineCount, font, layoutRect, format, brush);
 		nNextLinePosY += nLineHeight + nLineSpace;
 	}
 
@@ -411,7 +412,8 @@ static int DrawRunningInfo(Graphics &graphics, int nLeftWidth, int nRightWidth,
 {
 	// 全部输出
 	// get lock
-	while (InterlockedCompareExchange(&getEntityResource()->m_Locking, 1, 0) == 1)
+	auto entityRes = getEntityResource();
+	while (InterlockedCompareExchange(&entityRes->m_Locking, 1, 0) == 1)
 	{
 		Sleep(100);
 	}
@@ -424,9 +426,9 @@ static int DrawRunningInfo(Graphics &graphics, int nLeftWidth, int nRightWidth,
 	SolidBrush redBrush(Color(255, 174, 0, 0));
 	SolidBrush redBrush2(Color(255, 130, 0, 0));
 	
-	if (getEntityResource()->m_InBlueScreenMode)
+	if (entityRes->m_InBlueScreenMode)
 	{
-		strLeft = getEntityResource()->m_BlueScreenMsg;
+		strLeft = entityRes->m_BlueScreenMsg;
 
 		Font	 font(&fontFamily, 32, FontStyleBold, UnitPoint);
 
@@ -444,14 +446,14 @@ static int DrawRunningInfo(Graphics &graphics, int nLeftWidth, int nRightWidth,
 		StringFormat format;
 
 		int nNextLinePosY = 10;
-		auto it = getEntityResource()->m_OutputMsgs.rbegin();
-		if (getEntityResource()->m_InBrowseMode)
+		auto it = entityRes->m_OutputMsgs.rbegin();
+		if (entityRes->m_InBrowseMode)
 		{
-			for (int i = 0; i < getEntityResource()->m_SkipLineNum && i < (int)getEntityResource()->m_OutputMsgs.size(); i++)
+			for (int i = 0; i < entityRes->m_SkipLineNum && i < (int)entityRes->m_OutputMsgs.size(); i++)
 				it++;
 		}
 
-		for (; it != getEntityResource()->m_OutputMsgs.rend() && nNextLinePosY < nHeight; it++)
+		for (; it != entityRes->m_OutputMsgs.rend() && nNextLinePosY < nHeight; it++)
 		{			
 			auto &strLine = *it;
 
@@ -476,16 +478,16 @@ static int DrawRunningInfo(Graphics &graphics, int nLeftWidth, int nRightWidth,
 	int nLostCount = 0;
 	int nToStartCount = 0;
 	wchar_t strTmp[128] = {};
-	for (int i = 0; i < getEntityResource()->m_EntityCount; i++)
+	for (int i = 0; i < entityRes->m_EntityCount; i++)
 	{
-		if (getEntityResource()->m_EntitysInfo[i].EntityState >= 2 && getEntityResource()->m_EntitysInfo[i].EntityState <= 4)
+		if (entityRes->m_EntitysInfo[i].EntityState >= 2 && entityRes->m_EntitysInfo[i].EntityState <= 4)
 		{
 			nStartedCount++;
 		}
-		else if (getEntityResource()->m_EntitysInfo[i].EntityState == 6)
+		else if (entityRes->m_EntitysInfo[i].EntityState == 6)
 		{
 			nLostCount++;
-			swprintf_s(strTmp, 128, L"        模块[%s]启动失败\r\n", getEntityResource()->m_EntitysInfo[i].EntityName.c_str());
+			swprintf_s(strTmp, 128, L"        模块[%s]启动失败\r\n", entityRes->m_EntitysInfo[i].EntityName.c_str());
 			strLostEntitys += strTmp;
 		}
 	}
@@ -516,10 +518,10 @@ static int DrawRunningInfo(Graphics &graphics, int nLeftWidth, int nRightWidth,
 	// 输出当前启动状态信息
 	Font	 rfont2(&fontFamily, 11, FontStyleRegular, UnitPoint);
 
-	if (getEntityResource()->m_StartupInfo.length() > 0)
+	if (entityRes->m_StartupInfo.length() > 0)
 	{
 		RectF rrectF2(nLeftWidth + 6, nNextLinePosY, nRightWidth, nHeight - 180);
-		DrawLineString(graphics, getEntityResource()->m_StartupInfo, &rfont2, rrectF2, &centerFormat, &whiteBrush, 5, nNextLinePosY);
+		DrawLineString(graphics, entityRes->m_StartupInfo, &rfont2, rrectF2, &centerFormat, &whiteBrush, 5, nNextLinePosY);
 		nNextLinePosY += 10;
 	}
 
@@ -531,7 +533,7 @@ static int DrawRunningInfo(Graphics &graphics, int nLeftWidth, int nRightWidth,
 	}
 
 	// 输出严重错误信息
-	for (auto it2 = getEntityResource()->m_FatalMsgs.rbegin(); it2!= getEntityResource()->m_FatalMsgs.rend() && nNextLinePosY < nHeight; it2++)
+	for (auto it2 = entityRes->m_FatalMsgs.rbegin(); it2!= entityRes->m_FatalMsgs.rend() && nNextLinePosY < nHeight; it2++)
 	{
 		RectF rrectF2(nLeftWidth + 30, nNextLinePosY, nRightWidth, nHeight - 200);
 		wstring strLine = L"\r\n        【" + *it2+ L"】";
@@ -539,7 +541,7 @@ static int DrawRunningInfo(Graphics &graphics, int nLeftWidth, int nRightWidth,
 	}
 	
 	// release lock
-	InterlockedExchange(&getEntityResource()->m_Locking, 0);
+	InterlockedExchange(&entityRes->m_Locking, 0);
 	return 0;
 }
 
@@ -604,7 +606,8 @@ static void SetBrowseModeShift(int nShiftLines)
 		return;
 
 	// get lock
-	while (InterlockedCompareExchange(&getEntityResource()->m_Locking, 1, 0) == 1)
+	auto entityRes = getEntityResource();
+	while (InterlockedCompareExchange(&entityRes->m_Locking, 1, 0) == 1)
 	{
 		Sleep(100);
 	}	
@@ -818,10 +821,9 @@ void sp_gui_destroy(sp_gui_t *gui)
 int sp_gui_show_running_info(sp_gui_t *gui, const char *pMsg, int type)
 {
 	// get lock
-	while (InterlockedCompareExchange(&getEntityResource()->m_Locking, 1, 0) == 1)
-	{
+	auto entityRes = getEntityResource();
+	while (InterlockedCompareExchange(&entityRes->m_Locking, 1, 0) == 1)
 		Sleep(100);
-	}
 
 	SYSTEMTIME st = {};
 	GetLocalTime(&st);
@@ -829,47 +831,47 @@ int sp_gui_show_running_info(sp_gui_t *gui, const char *pMsg, int type)
 	if (type == 1)
 	{
 		// bluescreen 
-		getEntityResource()->m_InBlueScreenMode = true;
+		entityRes->m_InBlueScreenMode = true;
 		swprintf_s(szBuf, 1024, L"%S\r\n", pMsg);
-		getEntityResource()->m_BlueScreenMsg = szBuf;
+		entityRes->m_BlueScreenMsg = szBuf;
 	}
 	else if (type == 2)
 	{
 		// fatal error
 		swprintf_s(szBuf, 1024, L"%S", pMsg);
-		getEntityResource()->m_FatalMsgs.push_back(szBuf);
-		if (getEntityResource()->m_FatalMsgs.size() > 100)
-			getEntityResource()->m_FatalMsgs.pop_front();
+		entityRes->m_FatalMsgs.push_back(szBuf);
+		if (entityRes->m_FatalMsgs.size() > 100)
+			entityRes->m_FatalMsgs.pop_front();
 	}
 	else if (type == 3)
 	{
 		// important startup info
 		swprintf_s(szBuf, 1024, L"%S", pMsg);
-		getEntityResource()->m_StartupInfo = szBuf;
+		entityRes->m_StartupInfo = szBuf;
 	}
 	else
 	{
 		// startup info
 		swprintf_s(szBuf, 1024, L"[%02d:%02d:%02d] %S\r\n", st.wHour, st.wMinute, st.wSecond, pMsg);
-		getEntityResource()->m_OutputMsgs.push_back(szBuf);
+		entityRes->m_OutputMsgs.push_back(szBuf);
 
 		// 只保留最近500条
-		if (getEntityResource()->m_OutputMsgs.size() > 500)
-			getEntityResource()->m_OutputMsgs.pop_front();
+		if (entityRes->m_OutputMsgs.size() > 500)
+			entityRes->m_OutputMsgs.pop_front();
 	}
 
 	
 	// browse mode continues 30s
-	if (getEntityResource()->m_InBrowseMode && GetTickCount() - getEntityResource()->m_LastShiftTick >= 30000)
+	if (entityRes->m_InBrowseMode && GetTickCount() - entityRes->m_LastShiftTick >= 30000)
 	{
-		getEntityResource()->m_InBrowseMode = false;
-		getEntityResource()->m_SkipLineNum = 0;
+		entityRes->m_InBrowseMode = false;
+		entityRes->m_SkipLineNum = 0;
 	}
 
 	// release lock
-	InterlockedExchange(&getEntityResource()->m_Locking, 0);
+	InterlockedExchange(&entityRes->m_Locking, 0);
 
-	if (type >= 1 || (!getEntityResource()->m_InBlueScreenMode && !getEntityResource()->m_InBrowseMode))
+	if (type >= 1 || (!entityRes->m_InBlueScreenMode && !entityRes->m_InBrowseMode))
 	{
 		if (!PostMessageA(gui->hWnd, WM_DISPLAY, NULL, NULL)) {
 			return Error_Unexpect;
@@ -882,22 +884,23 @@ int sp_gui_show_running_info(sp_gui_t *gui, const char *pMsg, int type)
 int sp_gui_show_entity_info(sp_gui_t *gui, const char *entity, int state)
 {
 	auto strEntity = CSimpleStringA2W(CSimpleStringA(entity));
+	auto entityRes = getEntityResource();
 	int i = 0;
-	for (; i < getEntityResource()->m_EntityCount; i++)
+	for (; i < entityRes->m_EntityCount; i++)
 	{
-		if (wcsicmp(strEntity, getEntityResource()->m_EntitysInfo[i].EntityName.c_str()) == 0)
+		if (wcsicmp(strEntity, entityRes->m_EntitysInfo[i].EntityName.c_str()) == 0)
 		{
-			getEntityResource()->m_EntitysInfo[i].EntityState = state;
+			entityRes->m_EntitysInfo[i].EntityState = state;
 			break;
 		}
 	}
 
-	if (i == getEntityResource()->m_EntityCount && getEntityResource()->m_EntityCount<80)
+	if (i == entityRes->m_EntityCount && entityRes->m_EntityCount<80)
 	{
 		// new entity
-		getEntityResource()->m_EntitysInfo[i].EntityName = strEntity;
-		getEntityResource()->m_EntitysInfo[i].EntityState = state;
-		getEntityResource()->m_EntityCount++;
+		entityRes->m_EntitysInfo[i].EntityName = strEntity;
+		entityRes->m_EntitysInfo[i].EntityState = state;
+		entityRes->m_EntityCount++;
 	}
 
 	if (!PostMessageA(gui->hWnd, WM_DISPLAY, NULL, NULL)) {