Welcome Guest.   Make a donation to an author on the site July 27, 2014, 11:19:14 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
Your Support Funds this Site: View the Supporter Yearbook.
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1] 2 Next   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: DONE: Replacement Power Options applet  (Read 30682 times)
Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,952



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« on: December 17, 2006, 12:02:15 PM »

Maybe not a snack but it would be useful.

Currently the Power Options in Control Panel work on the basis of keyboard and mouse activity.

I would like a replacement that works on a CPU threshold not being exceeded for a period (say 5%) - that way I could set Standby or Hibernate when the computer is truly idle - not just when I don't interact personally. That would allow extended processing applications (such as video recoding) to proceed without Power Options kicking in.

Anyone any ideas how to acheive this ?
« Last Edit: December 17, 2006, 12:23:48 PM by brotherS » Logged

skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #1 on: December 17, 2006, 05:37:09 PM »

 smiley How about this one?

LowToSleep - Stop a PC from falling asleep until the CPU is inactive.

Features:
- Change CPU limit using Settings in the tray menu
- Shows CPU usage in the tray

You'll find the downloads and more info at 1 Hour Software by Skrommel.

It just checks the CPU, and if it is above the limit (5 % is default), it sends a keystroke to a hidden control.

Skrommel
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,952



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #2 on: December 17, 2006, 06:12:23 PM »

Hey great idea - thanks. Nice to see you back  Thmbsup

(some pennies on the way)
Logged

Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,952



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #3 on: December 17, 2006, 06:31:02 PM »

Follow up:

I am getting an error at line 42 "Can't load icon" which appears repeatedly. See window ...



The value of %icon% looks to be negative everytime and the numerical value doesn't seem to match the actual CPU usage (according to task manager)?

I can see that the INI file allows you to set the delay time in minutes but could it also allow the setting of the frequency of checking (in ms) and also the CPU threshold (as a %).
« Last Edit: December 17, 2006, 07:32:30 PM by Carol Haynes » Logged

skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #4 on: December 17, 2006, 07:30:50 PM »

 smiley Man, you must really have a slow computer!

But seriously, what CPU is in there? I've never gotten any negative values, and they correspond very well with Task manager's tray icon. The code is lifted from the Autohotkey site, and noone has reported any anomalies...

I've just uploaded a new LowToSleep that checks if the icon exists, and I've changed the settings to show threshold in % and checking interval in seconds. Remember to delete your existing ini file!

Please keep me informed.

Skrommel
« Last Edit: January 12, 2007, 11:28:15 AM by skrommel » Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,952



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #5 on: December 17, 2006, 07:33:03 PM »

By duplicating the icons with a '-' in front of the number it works but I am getting odd CPU usage tooltips (like -88%) when I hover over the icon. The actual CPU usage is <10%. Could this be because I have a dual core processor?

I am using an AMD Athlon64 X2 4600+ ... so pretty slow Wink
Logged

Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,952



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #6 on: December 20, 2006, 06:48:29 AM »

Anyone any further thoughts on this? Unfortunately Skrommel's idea doesn't seem to work for me (I get negative CPU usage and the apparent numerical value calculated int he script is always high - ignoring the sign).
Logged

skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #7 on: December 20, 2006, 07:46:37 AM »

 Sad I've posted the question on the AHK forum, but noone has answered...

Skrommel
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #8 on: December 26, 2006, 11:57:17 AM »

 smiley Carol, try LowToSleep v1.0.

I've found typo in the settings file, causing the CPU load to be checked too fast.

Skrommel
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,952



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #9 on: December 26, 2006, 05:02:18 PM »

Strange - with <10% CPU activity LowToSleep is still reporting negative CPU activity (of the order of -80%) ???
Logged

f0dder
Charter Honorary Member
***
Posts: 8,774



[Well, THAT escalated quickly!]

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #10 on: December 26, 2006, 05:44:17 PM »

Hmm...

dunno if this is at all related, but for AMD dualcore CPUs, each core has it's own "Time Stamp Counter", and they don't update in parallel for a various number of reasons.

So, if an application queries the TSC (with assembly instruction RDTSC), store the number, thread gets scheduled to other CPU, RDTSC is done again and old value is subtracted (ie, timing is being done) you can end up with negative values.

This is why all Unreal Engine games crash on AMD64x2 boxes, unless they're launched with "affinity restriction".
Logged

- carpe noctem
Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,952



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #11 on: December 27, 2006, 04:33:34 AM »

That sounds quite likely.

How do you launch a program with affinity restriction (I know how to change it once it is launched).

Logged

f0dder
Charter Honorary Member
***
Posts: 8,774



[Well, THAT escalated quickly!]

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #12 on: December 27, 2006, 06:11:05 PM »

You need to find a launcher - I wrote a little hacky tool with no error checking, but you're probably better off googling for "win2000launcher" smiley
Logged

- carpe noctem
skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #13 on: December 27, 2006, 06:22:48 PM »

 smiley Pocess from http://www.beyondlogic.org/solutions/processutil/processutil.htm can set the affinity of a process.

Skrommel

Quote
Change the affinity of processes . . .

The affinity is a mask which indicates on which processors (CPUs) a process can run. This is only useful on multiprocessor systems. When the -a option is used in conjunction with a process name or PID, the utility will show the System Affinity Mask and the Process Affinity Mask. The System Affinity Mask shows how many configured processors are currently available in a system. The Process Affinity Mask indicates on what processor(s) the specified process can run on.

C:\>process -a wordpad.exe

Command Line Process Viewer/Killer/Suspender for Windows NT/2000/XP V2.01
Copyright(C) 2002-2003 Craig.Peacock@beyondlogic.org
Getting Affinity Mask for PID 1084 'wordpad.exe'
System  : 0x0001 0b00000000000000000000000000000011  [2 Installed Processor(s)]
Process : 0x0001 0b00000000000000000000000000000011

 

To set the affinity mask, simply append the binary mask after the PID/Image Name. Any leading zeros are ignored, so there is no requirement to enter the full 32 bit mask.

C:\>process -a wordpad.exe 01

Command Line Process Viewer/Killer/Suspender for Windows NT/2000/XP V2.01
Copyright(C) 2002-2003 Craig.Peacock@beyondlogic.org
Setting Affinity Mask for PID 1084 'wordpad.exe'
Affinity Mask Successfully Set to 00000000000000000000000000000001
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #14 on: January 11, 2007, 05:18:17 PM »

 smiley Try LowToSleep v1.1!

I've added affinity to show the correct cpu usage on mutliple core/cpu systems. But I haven't got one, so please telle me if it works!

Skrommel
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,952



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #15 on: January 12, 2007, 12:09:57 PM »

I still get large negative usage values (eg. -80% even when CPU usage is under 10%)
Logged

skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #16 on: January 17, 2007, 06:45:44 PM »

 tellme How about LowToSleep v1.2?

Skrommel
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
f0dder
Charter Honorary Member
***
Posts: 8,774



[Well, THAT escalated quickly!]

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #17 on: January 17, 2007, 09:00:08 PM »

Hm, some things... unless I pass parameters for all three variables to GetSystemTimes, it doesn't return anything - the following code would simply print fluff! with SysInternals' dbgview. Adding "dummy1" and "dummy2", I get some garbage output, indicating that there's output.
[copy or print]
lala = %idleticks% + "fluff!"
DllCall("kernel32.dll\OutputDebugString", "uint", &lala)
(christ, AutoHotKey is a weird language).

I still get -100% usage, though - and I'm pretty sure affinity isn't the problem, GetSystemTimes shouldn't be affected by that (rdtsc, GetTickCount() and QueryPerformanceCounter() are, though - I originally thought you were using one of those).

What the heck is going on in the loop in GETCPULOAD?

EDIT: oh, A_TickCount probably translates to a call to GetTickCount(), so affinity might be necessary after all. And the Loop seems to be necessary because of AHK's weird "everything is a string, but we don't translate API output" philosophy. Hm.

EDIT2: I've modified the GETCPULOAD() function somewhat...
[copy or print]
GETCPULOAD() ;originally made by shimanov
{
  Global
  idletime0 = %idletime% ; Save previous values
  tick0 = %tick%

  DllCall("Kernel32.dll\GetSystemTimes", "*UInt64", idletime, "*Uint64", dummy1, "*Uint64", dummy2)

  tick := A_TickCount
  dIdle := (idletime - idletime0)
  dTick := (tick - tick0)

  load := 100 - 0.01 * dIdle/dTick

  outstr = Spent time: %dIdle%/%dTick%
  DllCall("kernel32.dll\OutputDebugString", "str", outstr)

  Return,load
}
With dbgview, I get values like...
[copy or print]
Spent time: 20000000/1000
Spent time: 20000000/1000
Spent time: 19843750/1000
Spent time: 20000000/1000
Spent time: 19843750/1000
Spent time: 20000000/1000
Spent time: 19687500/1000

EDIT 3: Okay, I should have seen this earlier. Quoting MSDN for GetSystemTimes, emphasis is mine: "Retrieves system timing information. On a multiprocessor system, the values returned are the sum of the designated times across all processors.".

So, for NT systems, add a EnvGet, NumCpu, NUMBER_OF_PROCESSORS near the top of the script, and do dIdle := (idletime - idletime0) / NumCpu. Feels somewhat hacky, but works. Probably better using GetSystemInfo() and checking the dwNumberOfProcessors field, but I dunno how AHK handles structs. If you do the environment thing, check for 9x and assign 1 to NumCpu.
« Last Edit: January 17, 2007, 09:31:14 PM by f0dder » Logged

- carpe noctem
Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,952



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #18 on: January 18, 2007, 03:29:18 AM »

Sounds like progress - but I don't pretend I have followed the argument  embarassed
Logged

CodeTRUCKER
Supporting Member
**
Posts: 1,027



Bush Flying... where I'd rather be.

see users location on a map View Profile Read user's biography. Give some DonationCredits to this forum member
« Reply #19 on: January 18, 2007, 04:26:01 AM »

I'll take a shot at it.  I think what is going on is to use the internal "clock" counts to a certain quantity defined by... I'm not sure, but the countdown/up is what triggers the event.  Clear as mud, right?
« Last Edit: December 08, 2009, 06:59:50 PM by CodeTRUCKER » Logged

I applaud those that refuse to commit "intellectual suicide."

Truth, unlike opinion, tradition, etc. will always be able to stand on its own.  Truth is not a static, but a living entity and will perpetually impart life; therefore, any "truth" that does not or can not impart life can not be Truth.

I am persuaded the only reason bad men have succeeded is not because good men have done nothing, but that good men did not do enough.

An Open Letter to My Friends


Notice: - Unless stated otherwise, I receive no compensation for anything I post here.
Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,952



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #20 on: January 18, 2007, 06:41:29 AM »

Scratches head .... yes I think I understand that ...  tellme
Logged

f0dder
Charter Honorary Member
***
Posts: 8,774



[Well, THAT escalated quickly!]

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #21 on: January 18, 2007, 10:16:04 AM »

Okay, let me try... you were in the right direction, Farmsteader smiley

the code runs once every second, and measures:

1) how many miliseconds elapsed since it last run (tick-tick0). This might seem superfluous, but it CAN vary a bit, since the code runs at normal priority.

2) how much time the CPU was idle (the value from GetSystemTimes) (again, a relative timing, idletime-idletime0).

Thing is, GetSystemTimes returns totals for all CPUs - so on a 2-core system, although only one second has elapsed, 2 "cpu-seconds" could be spent idle, and this is why we have to divide by NUMBER_OF_PROCESSORS.

The affinity thing is anyother problem, and I'm not sure it applies here (can't remember if it affects GetTickCount(), or only the RDTSC CPU instruction and the win32 api QueryPerformanceCounter()). But that problem happens on AMD dualcore CPUs, because their internal time-stamp counters aren't synchronized (while on intel dualcores it seems like either there's a single TSC, or the TSCs are synchronized).
Logged

- carpe noctem
skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #22 on: January 18, 2007, 10:47:39 AM »

 tellme Anyone care to test LowToSleep v1.3?

- 20070118 - v1.3: Retrieves the number of processors for correct calculations on multi core systems.

Skrommel
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
Carol Haynes
Waffles for England (patent pending)
Global Moderator
*****
Posts: 7,952



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #23 on: January 18, 2007, 11:18:47 AM »

Ah ! Now that seems to work for me (at least for reporting CPU usage). Thanks that's great.

I'll try it out now for allowing sleeping on sustained low CPU usage.
Logged

skrommel
Fastest code in the west
Developer
***
Posts: 882



View Profile WWW Give some DonationCredits to this forum member
« Reply #24 on: January 18, 2007, 11:47:05 AM »

 cheesy Great!

Thanks for finding the solution, f0dder!

Skrommel
Logged

Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.
Pages: [1] 2 Next   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.046s | Server load: 0.12 ]