Jump to content
pedeathtrian

How does scheduling work?

Recommended Posts

Hello everyone.

 

1. Where in script scheduler can kick in and stop execution? Can it be on + in this expression: _a = (_b - _c) + (_d - _e); ?

2. How do I know if there were context switches within some code? How many?



_start = diag_tickTime;
//
some code;
//
_end = diag_tickTime;
_diff = _end - _start;


How do I know if _diff shows actual time 'some code;' was executing and not 'some code;' + other scripts times?

3. Does  sleep 0;  cause voluntary preemption?

 

Thanks.

Share this post


Link to post
Share on other sites

Seems like nobody ever wanted to profile their sqf code. Sad.

Share this post


Link to post
Share on other sites

what is 

 

Seems like nobody ever wanted to prifile their sqf code. Sad.

what is "prifile"?

Share this post


Link to post
Share on other sites

Thanks for the link, Nikander.

Indeed, good tutorial, but unfortunately, does not give me required info.

Seems like I'm looking for something too strange and hardcore that it does not even exist (outside of BIS).

Share this post


Link to post
Share on other sites

I mean, if I had the "CPU clock" in addition to "wall clock" (diag_tickTime), that would be enough for me. I mean the ability to know how much time this script runs. The clock that stops when scheduler runs other scripts, and runs only when your script runs.

Any OS has such clock for their processes (you can see it in task manager for example).

Should require very small change to interpreter and insignificant overhead on execution.

 

Then you can measure your code for the time it was really running, not some wall clock time.

Share this post


Link to post
Share on other sites

1. Where in script scheduler can kick in and stop execution? Can it be on + in this expression: _a = (_b - _c) + (_d - _e); ?

Since Arma 2 the script can be interrupted on any instruction. In case of your example that would be the assignment, the subtractions and the addition.

2. How do I know if there were context switches within some code? How many?

You don't. This isn't information exposed to the script.

  • Like 2

Share this post


Link to post
Share on other sites

Thanks for reply, deadfast. 

Since Arma 2 the script can be interrupted on any instruction. In case of your example that would be the assignment, the subtractions and the addition.

That's what I thought it would do.

 

You don't. This isn't information exposed to the script.

And that too, unforutnately. Actually I don't care about context switches, only about times.

 

And seems like I found sort-of answer for my 3rd question. In the place I should've been looked first. On sleep's page in comments section Sbsmac writes:

To wait for the next frame, or give other scripts a chance to run, use Sleep 0.001

 

Share this post


Link to post
Share on other sites

Profile, sorry for typo.

 

You can download and run special profiling branch with lots of profiling commands, so no point saying no one wants script profiling.

  • Like 1

Share this post


Link to post
Share on other sites
A post of clarifications (I hope).

 

When I write some code (mostly C/C++) I usually first write it, debug it and then profile when needed.

I'm quite new to SQF, but the habit is strong, so I find lack of profiling tools kinda disappointing.

So I wanted to write profiling tool for SQF, but first I investigate the possibility of such tool creation (here comes this topic).

The tool that could produce output similar to gprof for example, with Flat profile, Call graphs and Annotated source (since I always know what __FILE__ script runs, on what __LINE__, and I can loadFile it for annotation). Line by line would require too much changes to source code, so I wasn't planning to impement it.

Script writer would be able to put some marks in his code (just like diag_tickTime, but with collecting this info). Every time execution hit the mark, some info is stored somewhere for later analysis.

After some (possibly a lot) of executions, analysis is done and information in one of the mentioned formats is logged. Then script writer reads it and eliminates bottle necks in his code; sees what functions call what and possible detect code that is not executed at all. Some coverage testing can be done also.

If implemented using macros, this method would only affect performance in debug/profiling mode and only be used by script writer on development stage.

It will always have some overhead on preprocessing stage though.

 

Everyone in community could benefit from existence of such tool: developers create more effective code; players get missions that run faster; fps rises; everyone happy.

SQF codebase and its complexity rises day by day. At some point in the future there will be definitely a necessity of having such tool.

Ideally there would be built-in profiling capabilities for SQF (e.g. in prof build), which would not require much changes to source code, but I don't expect it to appear.

 

The problem now is I cannot rely on diag_tickTime command for implementing such tool for the reasons provided in this topic earlier. Probably, on long runs this will not influence too much and stats will strive closer to real numbers, I dunno.

Thx to MarkCode82 for mentioning diag_activeSQFScripts. I think it's possible to implement sampling profiling on top of it (though it's not very accurate and wasn't my goal initially).

 

Thx to killzone_kid, I found those debug/prof branch builds with support for diag_*Frame commands. Will try it when prof build for hotfix is ready. For now, I'm still not sure if it porovides abilities to profile SQF code in the way I can get output in mentioned formats.

 

If you have any information that can help me implement a profiler for SQF (or stop at once creating weird stuff), please share.

Thank you.

 

Share this post


Link to post
Share on other sites

My Editing tool (link in sig.) already does some basic profiling of SQF (SQF Analyzer), it simply tells you things that can be done to improve performance or best practice, and in the end does it really need to be any more complex? Scripts aren't what chokes 99.99999% of missions (unless you foolish enough to run a billion loops with many many many complex commands, then yes, FPS will be in the toilet). Its a crapload of AI or an old CPU (i7 920 anyone?). So profiling scripts to the extent you mentioned probably isn't worth anybody's time when it could be spent making other aspects of the game better.

Share this post


Link to post
Share on other sites

austin_medic,

what your tool does is called static code analysis. Being great thing by itself, it however does not substitute "live" debugging and profiling.

Crapload of AI is controlled by FSM AFAIK, which is in turn script itself.

Having a powerful CPU, lots of RAM and super-duper fast SSD are not exuses for not optimising code. Performance pitfalls can hide everywhere. Even in libraries everyone used to trust.

 

PS. There's always space to optimize some code. Especially in the field where nobody ever used profiler.

Share this post


Link to post
Share on other sites

Profiling tool also is BIS_fnc_codePerformance for a direct call to it, and in your debug console in arma 3 your little "speedo" looking icon checks the codes performance.
But remember if it's scheduled vs unscheduled that codes results will be different.

https://community.bistudio.com/wiki/BIS_fnc_codePerformance

Make a dynamic code profiler like the following
[expression(String),Any([parameters]),cycles(Number)] call BIS_fnc_codePerformance;

 [
  _this select 0,
  _this select 1,
  _this select 2
 ] params 
 [
  "_inputCode", 
  "_numberOfCycles",
  ["_parameters", []]
 
 ];

[_inputCode,_parameters,_numberOfCycles] call BIS_fnc_codePerformance;

An optimisation note private ["_var"]; is now deprecated and obsolete replaced by:
https://community.bistudio.com/wiki/params

Share this post


Link to post
Share on other sites

An optimisation note private ["_var"]; is now deprecated and obsolete replaced by:

https://community.bistudio.com/wiki/params

 

It is neither deprecated nor obsolete. Please do not spread misinformation. Both 

private "_var";

and 

private ["_var1", "_var2", ...];

 

are still quite handy depending on a situation.

Share this post


Link to post
Share on other sites

I apologize not private ["_var"];

 

BIS_fnc_params was replaced for the
params command but the fact params allows you to.
1. define Default values

2. Value type checking before data is passed to it such as expected data types

3. Expected array size, and expected entries

 

It is by far superior to private and BIS_fnc_params

and you could probably compileFinal it as well. as a Hardened layer of security

Share this post


Link to post
Share on other sites

params allows you to.

1. define Default values

2. Value type checking before data is passed to it such as expected data types

3. Expected array size, and expected entries

Pretty sure BIS_fnc_param provides those three as well, params is just provided as a scripting command which inherently is more optimized than an external function (therefore making the function version obsolete).

 

Hmm, yea looky here: https://community.bistudio.com/wiki/BIS_fnc_param

Share this post


Link to post
Share on other sites

I know, params is engine internal not built from the script engine code. And as you said more optimised. I understand that, thats why I pretty quickly moved from BIS_fnc_params directly to params.

even says it in the wiki:

BIS_fnc_params
60px-Arma_3_logo_black.png This function is obsolete since the introduction of param and params.

Share this post


Link to post
Share on other sites

It is by far superior to private and BIS_fnc_params

Disagree on private. They are just for different things. params = private + some work to parse input. params can never be more effective when it comes to define local variables only. So the most effective way for now is

params ["_only","_passed","_arguments"];
private ["_all","_other","_locals"];

Share this post


Link to post
Share on other sites

Easy way to check profile the code using arma 3's debugger run both code, locally if they return faster or slower the next then you know the information. Nvm what I said above private looks like it was updated pretty recently and is not deprecated. Apologies but BIS_fnc_params is deprecated 

Share this post


Link to post
Share on other sites

Nvm what I said above private looks like it was updated pretty recently and is not deprecated. Apologies but BIS_fnc_params is deprecated

private command hasn't been touched when param and params were introduced

Share this post


Link to post
Share on other sites

private command hasn't been touched when param and params were introduced

 

I think he meant the change were private could also be used on single variables to replace local (Could be mistaking something here)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×