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 Joerg Vogel commented ·

You get statistical data of the tracked variables there. You haven't any access to the data of every event by the statistic. You get for example the total time of a state. If you like to see it yourself, you add a state pie chart to a dashboard and then you open the statistic collector in the toolbox to see how the data of the state processing is collected.

0 Likes 0 ·
Tomi Kosunen avatar image Tomi Kosunen Joerg Vogel commented ·

I still don't know, what is wrong with my code. All I need is the processing time statistics out from the Processor (as value). Can it be done with the Object stats.state() or should I use some other method?

0 Likes 0 ·
Joerg Vogel avatar image
1 Like"
Joerg Vogel answered Tomi Kosunen commented
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.

forobjecttreeunder(model()){
  if(isclasstype(a,CLASSTYPE_PROCESSOR)){
     Object processor = a;
     print(processor.name, " time",
           processor.stats.state().getTotalTimeAt(STATE_PROCESSING));
   }
}
· 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.

Tomi Kosunen avatar image Tomi Kosunen commented ·

Thanks @Jörg Vogel

This is what I needed.

0 Likes 0 ·
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.

Table profile = model().find("/Processor1>stats/state_current").as(TrackedVariable).profile;
double Other = profile[1][2]; /*other*/
double IdleTime = profile[2][2]; /*idle*/
double ProcessTime = profile[3][2]; /*processing*/
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

return 10;

use

double ProcessTime = 10;
current.labels.assert("Time_of_actual_process", ProcessTime);
current.Time_of_actual_process=ProcessTime; // EDIT
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.

Tomi Kosunen avatar image Tomi Kosunen commented ·

Thanks @Jörg Vogel

My question was maybe unclear. I need to get the processing time of the Processor as statistics (how much work has been done so far) to print out. Not the process time (how long it takes to process a part). And there is this Object.stats.state that I don't know how to use.

In the manual:

// Get the state of a multiprocessor,
// using the multiprocessor state profile
Object obj =  model().find("MultiProcessor1");
int curState = obj.stats.state(1).value;

In the tree tree view:

0 Likes 0 ·
veuwy.png (17.4 KiB)

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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