Very basic process CPU load determiner

Windows specific questions.
Post Reply
deltarho[1859]
Posts: 4313
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Very basic process CPU load determiner

Post by deltarho[1859] »

paul doe wrote:I don't particularly like crypto
That made me smile because I don't either. When I first got into crypto I had to go to MSDN to read the APIs and used to whisper to myself 'Once more unto the breach', take a deep breath and then plunge in not knowing what state I would be in after. I found one of the APIs written in such a cryptic fashion that I was tempted to write to Microsoft and ask them if there was any danger of them publishing it in plaintext. I used to get many GPFs per day and lost count of the number of GetLastErrors advising that a parameter was invalid and I was sat there looking at 12 of them. <Ha, ha>

That was 13 years ago. Things have changed, I no longer take a deep breath. No, I don't like it - I love it. <smile>

Thanks for you kind words, Paul.
dafhi
Posts: 1645
Joined: Jun 04, 2005 9:51

Re: Very basic process CPU load determiner

Post by dafhi »

@deltarho - if you haven't written a book, consider me surprised. Crypto sounds difficult. :P
deltarho[1859]
Posts: 4313
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Very basic process CPU load determiner

Post by deltarho[1859] »

@dafhi
if you haven't written a book, consider me surprised.
I am not sufficiently competent to presume that I could. I have several books on cryptography and there are sections in some of which I have read several times on different occasions and still do not fully understand.

What surprises me is the level of incompetency in corporations with regard digital security and why so many of them get hacked. A couple of years ago I submitted a password to a website owned by one of the biggest companies in the UK who should have known better. The password was rejected because it lacked complexity and it was suggested I include some special characters. I had submitted a 24 random alphanumeric character password which had an entropy of over 142 bits. I was tempted to write them advising that they did not have a computer big enough to scratch the surface of that password. What they failed to understand is that password length beats complexity any day of the week. Once a byte hits 8 bits of entropy that is as good as it is going to get. There is no theoretical limit to how many characters we can add to a password.

If anyone here has even just a passing interest in cryptography then they should visit, if they do not already do so, Schneier on Security. Not only is Schneier clever he is a good writer and what he writes is very readable. Now he should write a book. Oh wait, he has done - several in fact. A really good read is 'Cryptography Engineering' by Schneier, Neils Ferguson and Tadayoshi Kohno. Ferguson is a cryptographer at Microsoft and Kohno is a professor at the University of Washington. In that book is a password 'Salting and Stretching' method including a key check which I have used in many of my applications.
Crypto sounds difficult.
Difficult is a very good word to use because that is exactly what it is.

A tip for anyone embarking on using the Microsoft's Crypto APIs: Check the return values. You could write some code which, on the face of it, is working when, in fact, at least one API could have failed and you would be none the wiser without checking.
Last edited by deltarho[1859] on Oct 31, 2017 1:09, edited 1 time in total.
deltarho[1859]
Posts: 4313
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Very basic process CPU load determiner

Post by deltarho[1859] »

Improved modus operandi - well, I think so.

Previously when we pressed Enter, monitoring stopped and the 'Ave Session Load' info is displayed.

We no longer get invited to press Enter again but get the following message box.

Image

No explanation required with that other than a tidy up is carried out if we click Cancel or the message box close button.

I had one issue. On clicking Retry a character is placed in the keyboard buffer and CPU Load said 'Targer name was empty' and presented me with the message box again so I eat it with 'Dim AS String char = Inkey' and then all is well. <smile>
deltarho[1859]
Posts: 4313
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Very basic process CPU load determiner

Post by deltarho[1859] »

Slight problem. On considering second or subsequent processes the static variables in GetCPULOad need resetting. I cannot attend to that right now but as someone once said "I'll be back!"
dafhi
Posts: 1645
Joined: Jun 04, 2005 9:51

Re: Very basic process CPU load determiner

Post by dafhi »

what i meant by my 'your book' reference - you have a fun style in your posts which i enjoy reading
deltarho[1859]
Posts: 4313
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Very basic process CPU load determiner

Post by deltarho[1859] »

Once I got back it was a problem easily fixed. Up and running again.

Latest version here.
deltarho[1859]
Posts: 4313
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Very basic process CPU load determiner

Post by deltarho[1859] »

dafhi wrote:you have a fun style in your posts which i enjoy reading
I don't work at that - it is simply my disposition.

The funny thing is that it is a joy to be told that and very much more than being congratulated on a piece of code and I have absolutely no idea why.

When I was in my late teens I was a very troubled young man with my head 'in the clouds' most of the time and my father couldn't do anything with me so he hauled me off to see a Psychiatrist. I have a working class background and when I say working class, boy, do I mean working class. I did not fit well in my surroundings. At the end of the session I was asked if ever I had read any George Bernard Shaw or Oscar Wilde. I hadn't. I made it my business to do so. I took to Wilde like a house on fire and have been going downhill ever since. <laugh>

Over the years during drinking sessions with friends I'd make a remark which made them laugh. A friend once said "You know David, you should write down your quips". The list grew and grew. Few people knew of my list and about thirty years ago I mentioned them to my then girlfriend who was a bit of a literary buff. She asked if she could have a copy as she knew someone who was the editor of a small magazine. I said OK. It subsequently turned out that her friend was a trustee inmate at Wandsworth Prison in the UK and he ran the prison magazine. It seems that my quips were well received by the other inmates. I remember thinking that if Oscar Wilde was looking down he would be rolling about the floor in fits of laughter.

I lost the list many years ago and have not conjured many in the subsequent years. I used to write quips during bouts of the 'blues' but I don't suffer from them any more and they have been replaced with arthritis.

I have written a couple of plays but only one has been read by one person. One is about a couple of doctors discussing a couple of patients they were looking at on a becnh in the asylum courtyard. We home in on the bench. The patients were discussing gender and sexuality. We listen for quite a while and it becomes clear that these two guys are barking mad and in the best place for them. The play ends with the realisation that the two patients are in fact doctors and the two guys looking at them are patients.

So, there you have it - I am barking mad, like most people but I may be a little more so than most.

<smile>
dafhi
Posts: 1645
Joined: Jun 04, 2005 9:51

Re: Very basic process CPU load determiner

Post by dafhi »

deltarho[1859] wrote:
dafhi wrote:you have a fun style in your posts which i enjoy reading
I don't work at that - it is simply my disposition.
you answered my unwritten query :)
I took to Wilde like a house on fire and have been going downhill ever since. <laugh>
I'm not sharpest slice of bread in the tackle box :-) one of my quips.
Over the years during drinking sessions with friends I'd make a remark which made them laugh. A friend once said "You know David, you should write down your quips". The list grew and grew.
not surprised
Few people knew of my list and about thirty years ago I mentioned them to my then girlfriend who was a bit of a literary buff. She asked if she could have a copy as she knew someone who was the editor of a small magazine. I said OK. It subsequently turned out that her friend was a trustee inmate at Wandsworth Prison in the UK and he ran the prison magazine. It seems that my quips were well received by the other inmates. I remember thinking that if Oscar Wilde was looking down he would be rolling about the floor in fits of laughter.

I lost the list many years ago and have not conjured many in the subsequent years. I used to write quips during bouts of the 'blues' but I don't suffer from them any more and they have been replaced with arthritis.

I have written a couple of plays but only one has been read by one person. One is about a couple of doctors discussing a couple of patients they were looking at on a becnh in the asylum courtyard. We home in on the bench. The patients were discussing gender and sexuality. We listen for quite a while and it becomes clear that these two guys are barking mad and in the best place for them. The play ends with the realisation that the two patients are in fact doctors and the two guys looking at them are patients.
if i believed in the need for income i'd be tempted to run with your idea :D of course i'd be missing out on the details.

if you would be so kind ..

j/k :-)
deltarho[1859]
Posts: 4313
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Very basic process CPU load determiner

Post by deltarho[1859] »

dafhi wrote:I'm not sharpest slice of bread in the tackle box :-) one of my quips.
Here is a small set from memory.

The fear of losing someone often leads to good behaviour.
The fear of finding someone often leads to bad behaviour.

Being close to life can be as bad as being close to death.
The secret is to try and avoid being too close to either.

You may be able to persuade those with wit.
You may be able to persuade the witless.
You will never be able to persuade the half-wit
for they live in the twilight zone.

If you take yourself seriously you may find that nobody else does.
If you do not take yourself seriously you may find that everybody else does.

If you have what you believe to be original thought and nobody opposes it then you are sadly mistaken.

If you indulge in nothing but passing thoughts you may end up with a memory like a sieve.

In fact, God created woman first but got it right the second time. *

Opportunities are always golden, but some are better at panning than others.

If your best is mediocre then do it with style.

True genius is to excel and do it with style.

Critical Path Analysis warning.
Take a wrong turn occasionally.

Why write a sentence when a paragraph will do.

* I should add that I do not believe that - I am an atheist. <laugh> Truth is I do not believe any of that quip.
dafhi
Posts: 1645
Joined: Jun 04, 2005 9:51

Re: Very basic process CPU load determiner

Post by dafhi »

I like the finding someone and taking self seriously sets. Original thought is a fun one too. I have 'opinions' - *wink* - but there's almost no point saying them; rather, i'm (trying to) reconfigure myself to embody them. Quick examples: I don't believe in nutrition, I do believe in free energy (creating something from nothing)

I've, several times, gone for periods of days (record is 4) w/o eating and felt better than normal. I guess my mind got in the way. The bottom fell out from those experiences. I'm feeling another push and it's a bit more forceful than in the past, where I was just casual about things.
deltarho[1859]
Posts: 4313
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Very basic process CPU load determiner

Post by deltarho[1859] »

The three stages of man: Facetious, thoughtful, facetious.
dafhi wrote:I'm feeling another push and it's a bit more forceful than in the past, where I was just casual about things.
Ah, the tedium of middle age. I am now in the third stage, whence I came.

The three stages vary considerably - I was thoughtful for about two years. ( I am being facetious. )
deltarho[1859]
Posts: 4313
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Very basic process CPU load determiner

Post by deltarho[1859] »

I have not got much console writing experience - the bulk of my work at PowerBASIC was GUI.

What I did not know was that a console app could be themed. For those that did not know that either then simply add theme.rc to the compiler option switches.

theme.rc

Code: Select all

1 24 "Theme.xml"
You supply "Theme.xml"

The message box used in CPU Load will now be themed.
deltarho[1859]
Posts: 4313
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Very basic process CPU load determiner

Post by deltarho[1859] »

There is very little information available with regard to Microsoft's Performance Monitor. If we hover over any controls we don't get any tool tip pop ups, for example. Evetually I managed to fathom out how to get a process cpu load. Similar story with Cpustres.exe. Eventually I managed to fathom out how to use that.

Here are four tests:
Image

At the top of each CPU Load screenshot is the average load according to the Performance Monitor, cropped portion of a saved image, over the same session time as CPU Load, give or take a second or two.

Cpustres.exe is itself being monitored.

For all loads tested CPU Load's average session load is less than the Performance Monitor average load. However, as the loads increase CPU Load gets closer to the Performance Monitor. The last test has CPU Load at 21.46% compared to the Performance Monitor at 21.841%.

It had been noticed, above, that the Task Manager tends to under estimate loads when they are small.

If our applications are loading our CPU less than, say, 5% then all we need remember is that the actual load will be a litle larger than CPU Load is indicating but at that level I shouldn't think that we would be concerned that much.

If our applications are loading the CPU to the extent that we need to consider how to reduce the load then CPU Load will probably be giving us an accurate figure.
Last edited by deltarho[1859] on Nov 01, 2017 13:09, edited 1 time in total.
deltarho[1859]
Posts: 4313
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Very basic process CPU load determiner

Post by deltarho[1859] »

Cpustres.exe will only stress four cores and I did not want to 'max out' as CPU Load would show 50% so I backed off a little.

CPU Load is now displaying at 99.2% of the Performance Monitor figure ie an accuracy of just over two significant figures.
Image

I am 'maxed out' of ideas on this topic so I will call it a day. <smile>
Post Reply