Jump to content

High page faults


Recommended Posts

While page faults are normal, it's been brought to my attention one of my scripts runs very high page faults. After some investigation it seems that I'm using a winexist inside a loop and that causes the faults. After using the code from the help file in the sample below, it ends up hitting between 7000 and 11000 page faults per minute.

1) Is this normal?

2) Is this an inappropriate way to use winexist?

3) Should this be a concern?

I would appreciate anyone's advice.

While 1
    If WinExists("Untitled -") Then
        ;MsgBox(0, "", "Window exists")
    EndIf
WEnd
Link to comment
Share on other sites

Lame... but if you throw a sleep statement in the loop you will avoid maxing out your CPU (perhaps where the faults come from) and at the very least get "fewer" of the faults.

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

True. In my full script I do actually sleep some, however I also use more winexist calls and so my count is even higher. In general a poorly written script from many years ago. But I was amazed to see just these simple lines of code were causing that. Made me wonder if it was improper to use winexist in a continual loop.

Link to comment
Share on other sites

It really depends on WinExists what calls within the OS. It could touch a lot of other functions and code. While Windows is not the best handler of VM, that is a high number of faults.

I'm not sure a sleep statement will help, it is either in RAM or it is not.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Winwaitclose doesn't work for me as i'm waiting for a window to exist and have a specific title.

Interestingly I tested processexist to look for a work around... it's way worse. 240,000 (yes that's thousand) page faults in 60 sec. $x=WinGetTitle("[active]") seems to get what I want with no page faults. Both tests included a sleep(50). But I'd love to know why the page faults on the two "~exist" commands.

Link to comment
Share on other sites

This seems like an implementation questions more then anything else. I would guess that the WinActive, WinWaitClose and other such functions use a lot of the same code.

This is more of a questions for the devs - Valik, Jos?

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Interesting observations.

You could look at it this way.

WinExist - is a bit like looking for the joker in a pack of playing card you have to turn over a look at every card to be sure that it is not in the pack.

WinGetTitle([Active]) - is like checking to see if the next card is the jocker you only to look at the card on the top of the deck, much less work.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

There's nothing wrong with the WinExists function itself, just that you're calling it so frequently.

Based on the code you posted, it sounds like you're waiting for a window to exist, not for it to close.

Have you tried WinWait?

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Link to comment
Share on other sites

I'm just now looking into preferred way to redesign. I did see winwait still has many page faults. Although much less that ~exist functions. However, as I think about it, the usage of these functions being called in a loop would be taxing, but that would be CPU usage wouldn't it? Why the page faults?

Link to comment
Share on other sites

@stampy

you could use an event hook with SetWinEventHook API

it would hook global window or dialog creation.

will only hook a window if its a foreground window (active) or a dialog (#32770 class dialog MsgBox etc)

it does not continuously detect presence of window as in a loop

can be started and stopped on demand.

no growing page faults either

Siao, Progandy and Rasim have posted examples of this

I can post an example showing message box capture.

I see fascists...

Link to comment
Share on other sites

Further testing shows that wingetpos and controlgetpos also had similar problems with continual page faults. Not nearly as bad but there. I found with wingetpos, controlgetpos and also winexist if using the handle of the window rather than the title the page faults stopped. All tests done using standard default title matching. Interesting, still not sure why.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...