Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
litz-a committed Jan 20, 2016
1 parent 9029908 commit 9aa6e45
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 24 deletions.
19 changes: 19 additions & 0 deletions GLDUserInfoUtils/CBBNameSpace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*************************************************************************
*
* 广联达CBB命名空间定义
*
* duanb 2015.12.21
* 备注:
* 审核:
*
* Copyright (c) 2015 Glodon Corporation
*
*************************************************************************/

#ifndef CBBNAMESPACE_H
#define CBBNAMESPACE_H

#define CBB_GLODON_BEGIN_NAMESPACE namespace CBB {
#define CBB_GLODON_END_NAMESPACE } //namespace CBB

#endif // GNAMESPACE_H
3 changes: 2 additions & 1 deletion GLDUserInfoUtils/GLDCpuInfoUtils.h.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ CBB_GLODON_BEGIN_NAMESPACE
done = TRUE;
}
}
// todo ÊÍ·Å

ptr = buffer;

while (byteOffset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= returnLength)
Expand All @@ -166,6 +166,7 @@ CBB_GLODON_BEGIN_NAMESPACE
ptr++;
}

free(buffer);
coreCount.m_cpuCoreCount = processorCoreCount;
coreCount.m_cpuLogicalCoreCount = logicalProcessorCount;

Expand Down
8 changes: 4 additions & 4 deletions GLDUserInfoUtils/GLDDiskInfoUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ CBB_GLODON_BEGIN_NAMESPACE
0,
NULL);

std::shared_ptr<HANDLE> spHandle(hDevice, CloseHandle);
std::shared_ptr<void> spHandle(hDevice, CloseHandle);

if (INVALID_HANDLE_VALUE == hDevice)
if (INVALID_HANDLE_VALUE == spHandle.get())
{
return "";
}
Expand All @@ -84,7 +84,7 @@ CBB_GLODON_BEGIN_NAMESPACE
// get the necessary output buffer size
STORAGE_DESCRIPTOR_HEADER storageDescriptorHeader = { 0 };
DWORD dwBytesReturned = 0;
if (!::DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY,
if (!::DeviceIoControl(spHandle.get(), IOCTL_STORAGE_QUERY_PROPERTY,
&storagePropertyQuery, sizeof(STORAGE_PROPERTY_QUERY),
&storageDescriptorHeader, sizeof(STORAGE_DESCRIPTOR_HEADER),
&dwBytesReturned, NULL))
Expand All @@ -99,7 +99,7 @@ CBB_GLODON_BEGIN_NAMESPACE
ZeroMemory(pOutBuffer, dwOutBufferSize);

// get the storage device descriptor
if (!::DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY,
if (!::DeviceIoControl(spHandle.get(), IOCTL_STORAGE_QUERY_PROPERTY,
&storagePropertyQuery, sizeof(STORAGE_PROPERTY_QUERY),
pOutBuffer, dwOutBufferSize,
&dwBytesReturned, NULL))
Expand Down
22 changes: 11 additions & 11 deletions GLDUserInfoUtils/GLDProcessUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ CBB_GLODON_BEGIN_NAMESPACE
}


ulong getCurrentWorkingSetByHandle(DWORD processID)
ulong getCurrentWorkingSetByPID(DWORD processID)
{
HANDLE processHandle = getHandleByID(processID);

Expand All @@ -240,7 +240,7 @@ CBB_GLODON_BEGIN_NAMESPACE
return -1;
}

ulong getCurrentWorkingSetByHandle(const QString &processName)
ulong getCurrentWorkingSetByName(const QString &processName)
{
HANDLE handle = getHandleByName(processName);

Expand All @@ -259,7 +259,7 @@ CBB_GLODON_BEGIN_NAMESPACE
return pmc.WorkingSetSize / 1024;
}

ulong getPeekWorkingSetByHandle(DWORD processID)
ulong getPeekWorkingSetByPID(DWORD processID)
{
HANDLE processHandle = getHandleByID(processID);

Expand All @@ -271,7 +271,7 @@ CBB_GLODON_BEGIN_NAMESPACE
return -1;
}

ulong getPeekWorkingSetByHandle(const QString &processName)
ulong getPeekWorkingSetByName(const QString &processName)
{
HANDLE handle = getHandleByName(processName);

Expand All @@ -290,7 +290,7 @@ CBB_GLODON_BEGIN_NAMESPACE
return pmc.PeakWorkingSetSize / 1024;
}

ulong getPrivateWorkingSet(DWORD processID)
ulong getPrivateWorkingSetByPID(DWORD processID)
{
// hold the working set
DWORD dWorkingSetPages[1024 * 128] = {0};
Expand Down Expand Up @@ -391,19 +391,19 @@ CBB_GLODON_BEGIN_NAMESPACE
return WSPrivate;
}

ulong getPrivateWorkingSet(const QString &processName)
ulong getPrivateWorkingSetByName(const QString &processName)
{
return getPrivateWorkingSet(getIDByName(processName));
return getPrivateWorkingSetByPID(getIDByName(processName));
}

ulong getSharedWorkingSet(DWORD processID)
ulong getSharedWorkingSetByPID(DWORD processID)
{
return getCurrentWorkingSetByHandle(processID) - getPrivateWorkingSet(processID);
return getCurrentWorkingSetByPID(processID) - getPrivateWorkingSetByPID(processID);
}

ulong getSharedWorkingSet(const QString &processName)
ulong getSharedWorkingSetByName(const QString &processName)
{
return getCurrentWorkingSetByHandle(processName) - getPrivateWorkingSet(processName);
return getCurrentWorkingSetByName(processName) - getPrivateWorkingSetByName(processName);
}

ulong getIDByName(const QString &processName)
Expand Down
16 changes: 8 additions & 8 deletions GLDUserInfoUtils/GLDProcessUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,56 +31,56 @@ CBB_GLODON_BEGIN_NAMESPACE
* @param processID 进程PID
* @return
*/
ulong getCurrentWorkingSetByHandle(DWORD processID);
ulong getCurrentWorkingSetByPID(DWORD processID);

/**
* @brief 当前指定进程的占用的工作集(内存),KB为单元
* @param processID 进程名
* @return
*/
ulong getCurrentWorkingSetByHandle(const QString &processName);
ulong getCurrentWorkingSetByName(const QString &processName);

/**
* @brief 当前指定进程的占用的峰值工作集(内存),KB为单元
* @param processID 进程PID
* @return
*/
ulong getPeekWorkingSetByHandle(DWORD processID);
ulong getPeekWorkingSetByPID(DWORD processID);

/**
* @brief 当前指定进程的占用的峰值工作集(内存),KB为单元
* @param processID 进程名
* @return
*/
ulong getPeekWorkingSetByHandle(const QString &processName);
ulong getPeekWorkingSetByName(const QString &processName);

/**
* @brief 当前指定进程的占用的专用工作集(内存),KB为单元
* @param processID 进程PID
* @return
*/
ulong getPrivateWorkingSet(DWORD processID);
ulong getPrivateWorkingSetByPID(DWORD processID);

/**
* @brief 当前指定进程的占用的专用工作集(内存),KB为单元
* @param processName 进程名
* @return
*/
ulong getPrivateWorkingSet(const QString &processName);
ulong getPrivateWorkingSetByName(const QString &processName);

/**
* @brief 当前指定进程的占用的共享工作集(内存),KB为单元
* @param processID 进程PID
* @return
*/
ulong getSharedWorkingSet(DWORD processID);
ulong getSharedWorkingSetByPID(DWORD processID);

/**
* @brief 当前指定进程的占用的共享工作集(内存),KB为单元
* @param processID 进程名
* @return
*/
ulong getSharedWorkingSet(const QString &processName);
ulong getSharedWorkingSetByName(const QString &processName);

/**
* @brief 根据进程PID获取进程名
Expand Down

0 comments on commit 9aa6e45

Please sign in to comment.