Re: About some questions on PocketPC (CPU Usage,..)
- From: "hidex" <hidex@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 20 Jun 2005 12:42:04 -0700
2.
Please help me here! I write the following code and put SumThreadTimes(); in
OnInitDialog, but it's like no work! No value show in my edit box. Am I
worng?
Thank for your help.
int CCPU_UsageDlg::SumThreadTimes()
{
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
int newKernel=0;
int oldKernel=0;
int newUser=0;
int oldUser=0;
int newTime=0;
int oldTime=0;
int CPU_Usage=0;
THREADENTRY32 entry;
entry.dwSize = sizeof(THREADENTRY32);
Thread32First(hSnapShot, &entry);
FILETIME creation, exit, kernel, user;
do
{
if(GetThreadTimes( (HANDLE) entry.th32ThreadID , &creation, &exit,
&kernel, &user)==0)
{
AfxMessageBox (_T("Can't get thread time!"));
}
else
{
oldKernel=newKernel;
oldUser=newUser;
oldTime=newTime;
newKernel += kernel.dwLowDateTime;
newUser += user.dwLowDateTime;
newTime += creation.dwLowDateTime;
entry.dwSize = sizeof(THREADENTRY32);
CPU_Usage=(newKernel-oldKernel+newUser-oldUser)/(newTime-oldTime);
UpdateData(false);
this->m_cpu=(CString)CPU_Usage;
AfxMessageBox (_T("Success"));
}
Sleep(1000);
} while( Thread32Next(hSnapShot, &entry) );
CloseToolhelp32Snapshot(hSnapShot);
}
"Paul G. Tobey [eMVP]" wrote:
> 1. By enumerating them, as mentioned, with HeapFirst, HeapNext and keeping
> track of the process ID returned for each heap. You're wasting your time on
> this, if the goal is to save data memory. You aren't going to be able to
> 'release' memory that a process is actively using without crashing the
> process. There is *no swap file* in Windows CE. All data memory is in RAM.
>
> 2. Try a few things. I don't know of any sample code, but, best I can tell
> from a few minutes looking at the API, you could have tried 100 different
> ways of using the API in the time you've spent asking for help.
>
> Paul T.
>
>
>
> "hidex" <hidex@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:268E4BBB-0F3F-4D28-B0AB-4266A223B6A6@xxxxxxxxxxxxxxxx
> > 1.
> > Oh, I see. So can we know how many heaps that a process has? And Have any
> > method to release these *heaps*? In my idea, I just want to reduce memory
> > load.
> > At PC side, I can release the memory size of processes so that obtain more
> > memory space.
> >
> > 2.
> > Because I just want to try measure CPU workload on PDA, it's not easy to
> > find, obviously. Is there GetThreadTimes() sample code on PDA can be
> > shown?
> > I have no idea to do it.
> >
> > 3.
> > Thanks for your reply, maybe I am wrong. :p
> >
> >
> > "Paul G. Tobey [eMVP]" wrote:
> >
> >> 1. No, that won't get you the first process size. It will get you the
> >> first
> >> *heap* size. A process might have several heaps.
> >>
> >> 2. So you *are* trying to get a percentage. Well, to do that I think
> >> you'll
> >> have to measure the change in thread times over a known total elapsed
> >> time.
> >> Windows CE is not the same as desktop Windows, obviously.
> >>
> >> 3. No, that makes no sense. How are you supposedly doing this on the
> >> desktop? Someone might be able to come up with a similar action on the
> >> Windows CE device, if you can tell us that. "Terminating a module" makes
> >> no
> >> sense, though.
> >>
> >> Paul T.
> >>
> >> "hidex" <hidex@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> >> news:B4BB02BB-DF94-48FB-9440-62A69392E4F1@xxxxxxxxxxxxxxxx
> >> > Sorry for my crossing post in multiple newsgroup, really sorry!
> >> > Thank for your reply,
> >> > 1.
> >> > I will try Heap32First to find process size. :-)
> >> >
> >> > 2.
> >> > I will try GetThreadTimes(), Because I try to find CPU workload of PDA.
> >> > I get CPU loading using NtQuerySystemInformation and following formula.
> >> > CurrentCpuIdle = IdleTime / SystemTime
> >> > CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors
> >> >
> >> > 3.
> >> > I think terminating a module can reduce memory loading, isn't it ?
> >> > Because I want to release memory :-) Am I wrong?
> >> >
> >> > "Paul G. Tobey [eMVP]" wrote:
> >> >
> >> >> Q1. Look at the ToolHelp API. If it's anywhere, that's where you'll
> >> >> find
> >> >> it. I think that you *might* be able to get what you want by creating
> >> >> a
> >> >> snapshot, then enumerating the heaps using Heap32First, Heap32Next,
> >> >> and
> >> >> associating the size of each with the corresponding process.
> >> >>
> >> >> Q2. Check ToolHelp, again, to enumerate the list of threads, and then
> >> >> GetThreadTimes(). This doesn't give some usage percentage or
> >> >> something,
> >> >> so
> >> >> you'll have to be more specific about what you want, if this isn't it.
> >> >>
> >> >> Q3. This doesn't have any meaning to me. What do you think that
> >> >> "terminating a module" will do?
> >> >>
> >> >> Paul T.
> >> >>
> >> >> "hidex" <hidex@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> >> >> news:0571B986-1C42-423D-BDBC-F013FF411883@xxxxxxxxxxxxxxxx
> >> >> >I have some question want to ask (All work on PDA):
> >> >> > Q1.
> >> >> > Have any method to obtain memory size of each process? Because the
> >> >> > GetProcessMemoryInfo doesn't support EVC(eMbedded Visual C++) 4.0.
> >> >> > If have any methods, please tell me how to do it. thanks.
> >> >> >
> >> >> > Q2.
> >> >> > How to get CPU Usage of PDA using eVC++ 4.0? I can't find any sample
> >> >> > or
> >> >> > discussion on MDSN, can we do it? and have any sample code using
> >> >> > c++(in
> >> >> > more
> >> >> > complete).thanks for your help.
> >> >> >
> >> >> > Q3.
> >> >> > How can we "terminate a module"?? We can use TerminateProcess API to
> >> >> > terminate a Process,but I can't find any API to terminate modules.
> >> >> > How
> >> >> > can
> >> >> > we
> >> >> > do?
> >> >> >
> >> >> > There are a lot of questions, but I can't find any solution in last
> >> >> > serval
> >> >> > months.
> >> >> >
> >> >> > Please help me. Thanks for your help.
> >> >> >
> >> >> >
> >> >>
> >> >>
> >> >>
> >>
> >>
> >>
>
>
>
.
- Follow-Ups:
- Re: About some questions on PocketPC (CPU Usage,..)
- From: Paul G. Tobey [eMVP]
- Re: About some questions on PocketPC (CPU Usage,..)
- References:
- About some questions on PocketPC (CPU Usage,..)
- From: hidex
- Re: About some questions on PocketPC (CPU Usage,..)
- From: Paul G. Tobey [eMVP]
- Re: About some questions on PocketPC (CPU Usage,..)
- From: hidex
- Re: About some questions on PocketPC (CPU Usage,..)
- From: Paul G. Tobey [eMVP]
- Re: About some questions on PocketPC (CPU Usage,..)
- From: hidex
- Re: About some questions on PocketPC (CPU Usage,..)
- From: Paul G. Tobey [eMVP]
- About some questions on PocketPC (CPU Usage,..)
- Prev by Date: Device Management Client
- Next by Date: Re: About some questions on PocketPC (CPU Usage,..)
- Previous by thread: Re: About some questions on PocketPC (CPU Usage,..)
- Next by thread: Re: About some questions on PocketPC (CPU Usage,..)
- Index(es):
Relevant Pages
|