question

Tomi Kosunen avatar image
0 Likes"
Tomi Kosunen asked Raja Sekaran edited

How to use stats.state?

Hi

I want to get the processing and setup time of an Processor. I have tried to use Object.stats.state to do that but something goes wrong. I get an error (below). What's wrong?

Error:

time: 0.000000 exception: FlexScript exception: Could not access state variable on object Vaihe2 (profile: 2) at MODEL:/Tools/UserEvents/UserEvent1>variables/eventexception: FlexScript exception: Could not access state variable on object Vaihe2 (profile: 2) at MODEL:/Tools/UserEvents/UserEvent1>variables/event

My code:

forobjecttreeunder(model()){
if(getnodename(classobject(a)) == "Processor") {
Object processor = a.as(Object);
double processing_time = processor.stats.state(2).value;
double setup_time = processor.stats.state(21).value;
}
}

FlexSim 18.1.1
programmingstatistics and reports
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Joerg Vogel avatar image
1 Like"
Joerg Vogel answered Tomi Kosunen commented
  1. OBJECT.stats.state().getTotalTimeAt(STATE_PROCESSING)

OBJECT is a reference to the processor.

Your code casts the "a" already to an Object in the declaration of the variable processor. You don't need to cast the "a" directly twice.

  1. forobjecttreeunder(model()){
  2. if(isclasstype(a,CLASSTYPE_PROCESSOR)){
  3. Object processor = a;
  4. print(processor.name, " time",
  5. processor.stats.state().getTotalTimeAt(STATE_PROCESSING));
  6. }
  7. }
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Raja Sekaran avatar image
0 Likes"
Raja Sekaran answered Raja Sekaran edited

@tomi.kosunen

You can also access the profile stats value of the object by using the below code.

  1. Table profile = model().find("/Processor1>stats/state_current").as(TrackedVariable).profile;
  2. double Other = profile[1][2]; /*other*/
  3. double IdleTime = profile[2][2]; /*idle*/
  4. double ProcessTime = profile[3][2]; /*processing*/
  5. double Busy = profile[4][2]; /*busy*/

I have attached the sample model.

getprofilestatsv181.fsm

Hope this is useful for you.

Thanks


5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Joerg Vogel edited

The ProcessTime or setup time treenodes don't contain numerical data you can directly read. They contain FlexScript with a return value. If you want to read the current times you have to put the return value of the FlexScript code into a label that you can read and then you can return the value.

instead of

  1. return 10;

use

  1. double ProcessTime = 10;
  2. current.labels.assert("Time_of_actual_process", ProcessTime);
  3. current.Time_of_actual_process=ProcessTime; // EDIT
  4. return ProcessTime;

If you need the time value to compute the finish of processing you should keep in mind that there are events (break down, scheduled down) that can delay the finish time. Then you can use triggers or events that fire when the process finishes.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.