 |
|
 |
compiled code using Microsoft Visual C++ 2005
program is in a loop at this point under wincore.cpp
{
ASSERT(::IsWindow(m_hWnd));
// don't translate non-input events
if ((lpMsg->message < WM_KEYFIRST || lpMsg->message > WM_KEYLAST) &&
(lpMsg->message < WM_MOUSEFIRST || lpMsg->message > AFX_WM_MOUSELAST))
return FALSE;
return IsDialogMessage(lpMsg);
}
int CWnd::RunModalLoop(DWORD dwFlags)
{
ASSERT(::IsWindow(m_hWnd)); // window must be created
ASSERT(!(m_nFlags & WF_MODALLOOP)); // window must not already be in modal state
// for tracking the idle time state
BOOL bIdle = TRUE;
LONG lIdleCount = 0;
BOOL bShowIdle = (dwFlags & MLF_SHOWONIDLE) && !(GetStyle() & WS_VISIBLE);
HWND hWndParent = ::GetParent(m_hWnd);
m_nFlags |= (WF_MODALLOOP|WF_CONTINUEMODAL);
MSG *pMsg = AfxGetCurrentMessage();
// acquire and dispatch messages until the modal state is done
for (;;)
{
ASSERT(ContinueModal());
// phase1: check to see if we can do idle work
while (bIdle &&
!::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE))
{
ASSERT(ContinueModal());
// show the dialog when the message queue goes idle
if (bShowIdle)
{
ShowWindow(SW_SHOWNORMAL);
UpdateWindow();
bShowIdle = FALSE;
}
// call OnIdle while in bIdle state
if (!(dwFlags & MLF_NOIDLEMSG) && hWndParent != NULL && lIdleCount == 0)
{
// send WM_ENTERIDLE to the parent
::SendMessage(hWndParent, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)m_hWnd);
}
if ((dwFlags & MLF_NOKICKIDLE) ||
!SendMessage(WM_KICKIDLE, MSGF_DIALOGBOX, lIdleCount++))
{
// stop idle processing next time
bIdle = FALSE;
}
}
// phase2: pump messages while available
do
{
ASSERT(ContinueModal());
// pump message, but quit on WM_QUIT
if (!AfxPumpMessage())
{
AfxPostQuitMessage(0);
return -1;
}
// show the window when certain special messages rec'd
if (bShowIdle &&
(pMsg->message == 0x118 || pMsg->message == WM_SYSKEYDOWN))
{
ShowWindow(SW_SHOWNORMAL);
UpdateWindow();
bShowIdle = FALSE;
}
if (!ContinueModal())
goto ExitModal;
// reset "no idle" state after pumping "normal" message
if (AfxIsIdleMessage(pMsg))
{
bIdle = TRUE;
lIdleCount = 0;
}
} while (::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE));
}
ExitModal:
m_nFlags &= ~(WF_MODALLOOP|WF_CONTINUEMODAL);
return m_nModalResult;
john
|
|
|
|
 |
|
 |
Can I modify process create time, and HOW?
|
|
|
|
 |
|
 |
I want to check memory usage by a process running in a remote system. Here is the code snippet I am using. I am specifying the system name/ IP, but call to PdhAddCounter()is failing. Any suggestion?
TCHAR szAvailBytes[256] = TEXT("");
TCHAR szWorkingSet[256] = TEXT("");
TCHAR szBuffer[256] = TEXT("");
DWORD dwBufferSize = sizeof(szAvailBytes);
HCOUNTER hAvailBytes,
hCacheBytes,
hWorkingSet;
HQUERY hQuery = NULL;
PDH_COUNTER_PATH_ELEMENTS pdhCpe;
PDH_STATUS pdhStatus;
PDH_FMT_COUNTERVALUE pdhfmtAvail,
pdhfmtWorking;
__try
{
pdhStatus = PdhOpenQuery(NULL, 0, &hQuery);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
//
// Make Counter Path
//
pdhCpe.szMachineName = TEXT();
pdhCpe.szObjectName = TEXT("Memory");
pdhCpe.szInstanceName = NULL;
pdhCpe.szParentInstance = NULL;
pdhCpe.dwInstanceIndex = -1;
pdhCpe.szCounterName = TEXT("Available Bytes");
pdhStatus = PdhMakeCounterPath(&pdhCpe, szAvailBytes, &dwBufferSize, 0);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
pdhCpe.szObjectName = TEXT("Process");
pdhCpe.szInstanceName = TEXT("explorer");
pdhCpe.szCounterName = TEXT("Working Set");
dwBufferSize = sizeof(szWorkingSet);
pdhStatus = PdhMakeCounterPath(&pdhCpe, szWorkingSet, &dwBufferSize, 0);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
//
// Add counters.
//
pdhStatus = PdhAddCounter(hQuery, szWorkingSet, 0, &hWorkingSet); // failing here :: Access denied
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
//
// Get the data.
//
pdhStatus = PdhCollectQueryData(hQuery);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
pdhStatus = PdhGetFormattedCounterValue(hWorkingSet, PDH_FMT_LONG | PDH_FMT_NOSCALE, NULL, &pdhfmtWorking);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
wsprintf(szBuffer, TEXT("Working Set = %ld\n"), pdhfmtWorking.longValue);
OutputDebugString(szBuffer);
__finally
{
if (hQuery != NULL)
{
pdhStatus = PdhCloseQuery(hQuery);
if (pdhStatus != ERROR_SUCCESS)
{
}
}
}
|
|
|
|
 |
|
 |
Are you using Windows XP or Vista?
Aryan S wrote: pdhStatus = PdhAddCounter(hQuery, szWorkingSet, 0, &hWorkingSet); // failing here :: Access denied
Is this one of the PDH error status codes defined in PDHMsg.h?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
 |
|
 |
Sir,with all due respect.
I want to know, How much memory each processes are consuming as it shown by taskmgr in win2000 and Upward
|
|
|
|
 |
|
 |
Like this:
void main( void )
{
TCHAR szAvailBytes[256] = TEXT("");
TCHAR szCacheBytes[256] = TEXT("");
TCHAR szWorkingSet[256] = TEXT("");
TCHAR szBuffer[256] = TEXT("");
DWORD dwBufferSize = sizeof(szAvailBytes);
HCOUNTER hAvailBytes,
hCacheBytes,
hWorkingSet;
HQUERY hQuery = NULL;
PDH_COUNTER_PATH_ELEMENTS pdhCpe;
PDH_STATUS pdhStatus;
PDH_FMT_COUNTERVALUE pdhfmtAvail,
pdhfmtCache,
pdhfmtWorking;
__try
{
pdhStatus = PdhOpenQuery(NULL, 0, &hQuery);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
pdhCpe.szMachineName = TEXT("your machine");
pdhCpe.szObjectName = TEXT("Memory");
pdhCpe.szInstanceName = NULL;
pdhCpe.szParentInstance = NULL;
pdhCpe.dwInstanceIndex = -1;
pdhCpe.szCounterName = TEXT("Available Bytes");
pdhStatus = PdhMakeCounterPath(&pdhCpe, szAvailBytes, &dwBufferSize, 0);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
pdhCpe.szCounterName = TEXT("Cache Bytes");
dwBufferSize = sizeof(szCacheBytes);
pdhStatus = PdhMakeCounterPath(&pdhCpe, szCacheBytes, &dwBufferSize, 0);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
pdhCpe.szObjectName = TEXT("Process");
pdhCpe.szInstanceName = TEXT("_Total");
pdhCpe.szCounterName = TEXT("Working Set");
dwBufferSize = sizeof(szWorkingSet);
pdhStatus = PdhMakeCounterPath(&pdhCpe, szWorkingSet, &dwBufferSize, 0);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
pdhStatus = PdhAddCounter(hQuery, szAvailBytes, 0, &hAvailBytes);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
pdhStatus = PdhAddCounter(hQuery, szCacheBytes, 0, &hCacheBytes);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
pdhStatus = PdhAddCounter(hQuery, szWorkingSet, 0, &hWorkingSet);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
pdhStatus = PdhCollectQueryData(hQuery);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
pdhStatus = PdhGetFormattedCounterValue(hAvailBytes, PDH_FMT_LONG | PDH_FMT_NOSCALE, NULL, &pdhfmtAvail);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
pdhStatus = PdhGetFormattedCounterValue(hCacheBytes, PDH_FMT_LONG | PDH_FMT_NOSCALE, NULL, &pdhfmtCache);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
pdhStatus = PdhGetFormattedCounterValue(hWorkingSet, PDH_FMT_LONG | PDH_FMT_NOSCALE, NULL, &pdhfmtWorking);
if (pdhStatus != ERROR_SUCCESS)
{
__leave;
}
wsprintf(szBuffer, TEXT("Avail Bytes = %ld\n"), pdhfmtAvail.longValue);
OutputDebugString(szBuffer);
wsprintf(szBuffer, TEXT("Cache Bytes = %ld\n"), pdhfmtCache.longValue);
OutputDebugString(szBuffer);
wsprintf(szBuffer, TEXT("Working Set = %ld\n"), pdhfmtWorking.longValue);
OutputDebugString(szBuffer);
wsprintf(szBuffer, TEXT("Physical Mem = %ldMB\n"), (pdhfmtAvail.longValue + pdhfmtCache.longValue + pdhfmtWorking.longValue) / (1024 * 1024));
OutputDebugString(szBuffer);
}
__finally
{
if (hQuery != NULL)
{
pdhStatus = PdhCloseQuery(hQuery);
if (pdhStatus != ERROR_SUCCESS)
{
}
}
}
}
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-- modified at 8:41 Monday 11th September, 2006
|
|
|
|
 |
|
 |
Is it possible to obtain the dll module called by the specific process.
sometime the memory allocation was done in the external dlls, so I want to know how about that.
Best Regards
|
|
|
|
 |
|
 |
Hi DavidCrow,
I can add the counter with instance and i am increasing the raw value of it but i can not see that value it is showing only 0. If i am incrementing the counter value without instance then it can be monitored but with instance i am unable to monitor it.
i creating the counter like it
CounterCreationDataCollection^ CCDC = gcnew CounterCreationDataCollection;
// Add the counter.
CounterCreationData^ averageCount64 = gcnew CounterCreationData;
averageCount64->CounterType = PerformanceCounterType::AverageCount64;
averageCount64->CounterName = "Counter2";
CCDC->Add( averageCount64 );
// Add the base counter.
CounterCreationData^ averageCount64Base = gcnew CounterCreationData;
averageCount64Base->CounterType = PerformanceCounterType::AverageBase;
averageCount64Base->CounterName = "Counter3";
CCDC->Add( averageCount64Base );
PerformanceCounterCategory::Create( "ZAverageInstanceCategory", "Demonstrates usage of the AverageCounter64 performance counter type.", CCDC );
PerformanceCounter^% PC = gcnew PerformanceCounter( "ZAverageInstanceCategory","Counter2","instance1", false );
PC->RawValue = 10;
PerformanceCounter^% BPC = gcnew PerformanceCounter( "ZAverageInstanceCategory","Counter3","instance2", false );
BPC->RawValue = 0;
Thanks
vijay
|
|
|
|
 |
|
 |
Hi,
i downloaded your code. it gives a compilin error sayin
fatal error RC1015: cannot open include file 'res//ProcessInfo.rc2'
i cant find that file in the dwnloaded files.. pls chk
|
|
|
|
 |
|
 |
The file is in the zip. I suspect you have unzipped all of the files into a single folder. If this is the case, there are 2 solutions:
1) create a res folder underneath the folder you extracted to, and place ProcessInfo.rc2 and ProcessInfo.ico into it.
2) Extract the files again, and make sure that "Use Folder Names" is checked
|
|
|
|
 |
|
 |
coderider wrote:
The file is in the zip.
It is now, but wasn't when pranay posted.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
 |
|
 |
How to get CPU usage per process? Shall be possible to calculate trough GetProcessTimes, but how?
|
|
|
|
 |
|
 |
Airport1 wrote:
How to get CPU usage per process?
This article hints at it, but here's a working example:
PDH_STATUS pdhStatus;
HQUERY hQuery = NULL;
HCOUNTER hProcessorTime;
PDH_COUNTER_PATH_ELEMENTS pdhCpe;
PDH_FMT_COUNTERVALUE pdhfmtProcessorTime;
TCHAR szProcessorTime[256],
szBuffer[256];
DWORD dwBufferSize;
__try
{
pdhStatus = PdhOpenQuery(NULL, 0, &hQuery);
if (pdhStatus != ERROR_SUCCESS)
__leave;
pdhCpe.szMachineName = TEXT("crow-nt");
pdhCpe.szObjectName = TEXT("Process");
pdhCpe.szInstanceName = TEXT("Idle");
pdhCpe.szParentInstance = NULL;
pdhCpe.dwInstanceIndex = -1;
pdhCpe.szCounterName = TEXT("% Processor Time");
dwBufferSize = sizeof(szProcessorTime);
pdhStatus = PdhMakeCounterPath(&pdhCpe, szProcessorTime, &dwBufferSize, 0);
if (pdhStatus != ERROR_SUCCESS)
__leave;
pdhStatus = PdhAddCounter(hQuery, szProcessorTime, 0, &hProcessorTime);
if (pdhStatus != ERROR_SUCCESS)
__leave;
pdhStatus = PdhCollectQueryData(hQuery);
if (pdhStatus != ERROR_SUCCESS)
__leave;
pdhStatus = PdhGetFormattedCounterValue(hProcessorTime, PDH_FMT_LONG, NULL, &pdhfmtProcessorTime);
if (pdhStatus != ERROR_SUCCESS)
__leave;
if (ERROR_SUCCESS == pdhStatus)
wsprintf(szBuffer, TEXT("Processor Time = %ld\n"), pdhfmtProcessorTime.longValue);
}
__finally
{
if (hQuery != NULL)
pdhStatus = PdhCloseQuery(hQuery);
}
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
 |
|
 |
Hello,
thanks for this sample, i need little help to use this ,
i must to read the current cpu usage!
My program crash with Access violation after:
pdhStatus = PdhCollectQueryData(hQuery);
if (pdhStatus != ERROR_SUCCESS)
__leave;
I recive an PDH_NO_DATA, what to do now?
#define PDH_NO_DATA ((DWORD)0x800007D5L)
i make something wrong, but idont know what!
By compilig there are no errors, nothing, looks ok!
thanks for help!
termal
-- modified at 9:03 Friday 20th July, 2007
|
|
|
|
 |
|
 |
termal wrote: My program crash with Access violation after:
pdhStatus = PdhCollectQueryData(hQuery);
Is hQuery valid?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
 |
|
 |
Hello,
yes ist valid, it's not NULL, if that is what you mean?!
I put your sample code in a own function with name int GetProcInf();
int GetProcInf()
{
__try{
pdhStatus = PdhOpenQuery(NULL, 0, &hQuery); if (pdhStatus != ERROR_SUCCESS)
__leave;
pdhCpe.szMachineName = TEXT("crow-nt");
pdhCpe.szObjectName = TEXT("Process");
pdhCpe.szInstanceName = TEXT("Idle");
pdhCpe.szParentInstance = NULL;
pdhCpe.dwInstanceIndex = -1;
pdhCpe.szCounterName = TEXT("% Processor Time");
dwBufferSize = sizeof(szProcessorTime);
pdhStatus = PdhMakeCounterPath(&pdhCpe, szProcessorTime, &dwBufferSize, 0);
if (pdhStatus != ERROR_SUCCESS) __leave;
pdhStatus = PdhAddCounter(hQuery, szProcessorTime, 0, &hProcessorTime); if (pdhStatus != ERROR_SUCCESS) __leave;
pdhStatus = PdhCollectQueryData(hQuery);
if (pdhStatus != ERROR_SUCCESS) __leave;
......
}
This is what i try to read current cpu usage
Many thanks for help!
termal
|
|
|
|
 |
|
 |
termal wrote: pdhCpe.szMachineName = TEXT("crow-nt");
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
 |
|
 |
ups
here to set own machine name!?
|
|
|
|
 |
|
 |
termal wrote: here to set own machine name!?
Of course. That's why the member variable is called szMachineName.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
 |
|
 |
Airport1 wrote:
How to get CPU usage per process? Shall be possible to calculate trough GetProcessTimes, but how?
|
|
|
|
 |
|
 |
Why are you quoting Airport1?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
 |
|
 |
By using above example we are getting kernel,user,creation times of process.
How to get number of cpu cycles a particular process has executed from these information.
|
|
|
|
 |
|
 |
See my response to Airport1.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
 |
|
 |
I noticed that GetProcessTimes returns the same user time and kernel time if the application is idle; that is, if I have an application which has been idle for eight hours, the user time at the end of that eight hours is the same as the beginning of the eight hours. Same goes for the kernel time.
How can I differentiate an idle application from a frozen application?
thanks.
|
|
|
|
 |
|
 |
m.bergman wrote:
I noticed that GetProcessTimes returns the same user time and kernel time if the application is idle; that is, if I have an application which has been idle for eight hours, the user time at the end of that eight hours is the same as the beginning of the eight hours. Same goes for the kernel time.
As it should. Just because a process is idle does not mean it is doing absolutely nothing (e.g., waiting around for user input is doing something). It is still in either the user or kernel mode.
m.bergman wrote:
How can I differentiate an idle application from a frozen application?
See if this article helps. It does nothing with frozen, however. I did see the "How can I detect if an application is frozen" question some time back. Maybe you can Google for it. I seem to recall it mentioning something about sending the suspect application a message and noting the result, if any. Try SendMessageTimeout(..., WM_NULL, ..., SMTO_ABORTIFHUNG, 4000, ...), which waits 4 seconds for the window to respond.
|
|
|
|
 |