Avoid CPU 100% overload?

 

Hi,

What would you do if your Script/EA/Indicator overloads the CPU while running?

What would you check first, what optimization would you apply?

Especially if there is an endless loop in Script..

Thanks

 

lukins:

What would you do if your Script/EA/Indicator overloads the CPU while running?

What would you check first, what optimization would you apply?

Especially if there is an endless loop in Script..

optimizations are irrelevant, the code is broken, fix the code, optimize is the last thing to do after it's working correctly.

Put a Print statement at the top of every function like "function name start" and before any returns like "function name end 1."

run it and when it hangs the last line will tell you where and who called it. Comment out the print statements and add more inside the function's loops including variables and values. run and isolate.

 
WHRoeder:

optimizations are irrelevant, the code is broken, fix the code, optimize is the last thing to do after it's working correctly.

Put a Print statement at the top of every function like "function name start" and before any returns like "function name end 1."

run it and when it hangs the last line will tell you where and who called it. Comment out the print statements and add more inside the function's loops including variables and values. run and isolate.


Thanks for reply. If I understand correctly, you recommend me to find out the code that forces CPU load, right? I've already put such Print statements for almost every logical code part, but how can I determine which one uses more CPU?
 
lukins:

Thanks for reply. If I understand correctly, you recommend me to find out the code that forces CPU load, right? I've already put such Print statements for almost every logical code part, but how can I determine which one uses more CPU?

Look at timestamps. Most EA operations are CPU-bound, so if you don't Sleep() inside or write to file then this can help measuring how long your code executes. You can also try to create use some dll that will count milliseconds for you if timestamps are not enough.

--
Luke
ChartsAccess.com - MetaTrader charts in any phone.

 
Luke_ca:

Look at timestamps. Most EA operations are CPU-bound, so if you don't Sleep() inside or write to file then this can help measuring how long your code executes. You can also try to create use some dll that will count milliseconds for you if timestamps are not enough.

--
Luke
ChartsAccess.com - MetaTrader charts in any phone.


I see. Thanks for advice.
Reason: