bug fix: sort the instance list.

This commit is contained in:
Zhen Tang 2013-07-16 10:09:22 +08:00
parent eb8e2258fa
commit 311181948f
2 changed files with 18 additions and 9 deletions

View File

@ -127,6 +127,7 @@ double Common::GetCounterValueWithIdle(const wchar_t * fullCounterPath,int idleT
list<wstring> Common::GetInstanceName(const wchar_t * objectName)
{
list<wstring> ret;
vector<wstring> tmp;
wchar_t * counterListBuffer = NULL;
wchar_t * instanceListBuffer = NULL;
DWORD dwCounterListSize = 0;
@ -143,32 +144,38 @@ list<wstring> Common::GetInstanceName(const wchar_t * objectName)
if(status == ERROR_SUCCESS)
{
wchar_t * instance = instanceListBuffer;
int count=0;
wstring last;
for(; *instance != 0; instance += lstrlen(instance) + 1)
{
if(instance==instanceListBuffer)
tmp.push_back(wstring(instance));
}
sort(tmp.begin(),tmp.end());
int count=0;
wstring last;
vector<wstring>::iterator iter;
for(iter=tmp.begin();iter!=tmp.end();iter++)
{
if(iter==tmp.begin())
{
last=wstring(instance);
ret.push_back(wstring(instance));
last=wstring((*iter).c_str());
ret.push_back(wstring((*iter).c_str()));
count=0;
}
else
{
if(last==wstring(instance))
if(last==wstring((*iter).c_str()))
{
count++;
wchar_t buffer[10];
_itow_s(count,buffer,10);
wstring toInsert(instance);
wstring toInsert((*iter).c_str());
toInsert+=L"#";
toInsert+=buffer;
ret.push_back(toInsert);
}
else
{
last=wstring(instance);
ret.push_back(wstring(instance));
last=wstring((*iter).c_str());
ret.push_back(wstring((*iter).c_str()));
count=0;
}
}

View File

@ -9,6 +9,8 @@
#include <memory>
#include <string>
#include <list>
#include <algorithm>
#include <vector>
using namespace std;