Looking for a Progress Window in MPS

Hello,

i have implemented a text-coding software in mps - very strange use case of mps capabilities, but very suitable! However, i have to sort some data in a mps model, which takes time 2-3 minutes.

Is there a possibility to display the progress bar window (same one while generating code?) Where can i find an example?

Dan
17 comments
Dan,

You can do it using Idea platform API:
ProgressManager.getInstance().run(...)

Example can be found in ModelCheckerViewer class and in some other places.

Regards,
Mihail.
0
Hi Mihail,

thanks for your answer. Btw - are you interested in using my language for profiling mps? I have some problems when deleting one of the rootnodes, containing my data nodes ...

But for know it works fine.. but could be an mps issue...
dan
0
Generally, I'm interested in your use case, especially if you know how to reproduce the lag.
The best variant is if you capture a performance snapshot using YourKit profiler and send it to me. You can also give me your language and an instructions on how to reproduce the lag - I'll make a snapshot by myself in this case.

Regards,
Mihail
0
Ok,

i ll look for an ideal use case to make the point.

Regarding the ProgressManager.getInstance().run(...), where i passed a Task.Modal(), can i simply pass in the model also and edit around in the model (in the thread of the Task?) ?? Is that okay, or should i do that differently?

Dan
0
cause now i m locked away.. i need to increment the progress and also access the model.. so this does not work inside of the run() @ Task.Modal  

read action {
  colName = columns.get(0).name;
}
indicator.setText("Processing words in column " + colName);


seems that read action also spans a thread ... when i remove the read action, everything is fine...

Dan
0
Dan,

you are right about the read-action, but it is executed in the same thread, just under a lock.
0
I see,

but then - what could be my problem. no exception - nothing. Is the lock the problem? Or better ... is the read action a blocking statement ?


public void run(@NotNull() ProgressIndicator indicator) {
  init(indicator);
  int numColumns = columns.size;
     
     
  setTotalSteps(indicator, numColumns);
     
  for (int i = 0; i < columns.size; i++) {
    string colName = "";
    read action {
      colName = columns.get(0).name;
    }
      
    indicator.setText("Processing words in column ");
    indicator.setText2("" + i + "/" + numColumns + " ");
      
    waitASecond();
    oneMoreStep(indicator);
  }
     
  end(indicator);
}
0
Dan,

If you are performing it in an action, set the action's "execute outside command" property to true. This could be the problem.
0
See - you get the "command" lock (which is a write-lock actually), start a progress under it. Progress spawns a thread for computation, and this thread tries to get a red lock, while the progress thread holds a write-lock, so it's a "deadlock" (not a real deadlock actually as you can cancel the action, I suppose).
0
And yes, the read- and write-actions are blocking statements.
0
Mh - i see. But how can i handle this situation in MPS?

public void run(@NotNull() ProgressIndicator indicator) {
  init(indicator);
  int numColumns = columns.size;
  
  setTotalSteps(indicator, numColumns);
  
  // no problem until here - process and indicator have to be set up in some way..
  
  // now start processing ... read something from the model, e.g. columname
  // and expose this name to the indicator for user ...  
  for (int i = 0; i < columns.size; i++) {
    string colName = "";
    read action {
      colName = columns.get(0).name;
    }
    indicator.setText("Processing words in column ");
   
    // do time consuming operation here ...   
    waitASecond();
    // done ....
    oneMoreStep(indicator);
  }
     
  end(indicator);
}
0
Dan,

Once again - if you are doing it in an action, just set "execute outside command" to true, and MPS will then let you manage read-write access by yourself (no write-action will be executed before starting the progress task). The code you wrote below should be left unchanged.
If you are performing this not in an action, then could you please provide a stacktrace for the moment when the ProgressManager.getInstance() is executed? I could then look at it and say whether it's a deadlock because of a write-access deadlock and what should you do in this case.

Regards,
Mihail
0
Hi Mihail,

thanks for your patience. well im using it in a refactoring.

refactor(refectoringContext)->void {
sequence<node<Column>> columns = refactoringContext.node.getColumnOfThisProject();
   
   
CodeBookGuesser_WordList guesser = new CodeBookGuesser_WordList(refactoringContext.project, columns.toList);
   
ProgressManager.getInstance().run(guesser);
   
refactoringContext.node.model.add root(guesser.getCodebook());

}

I do not get a stacktrace - mps simply hangs up...
0
I had similiar experiences with 'OutOfMemoryExceptions'. MPS hangs up or just shuts down. You might consider that too
0
Now I see )

I've checked - refactoring is executed in a write-action always. The problem is that we don't have a progress indicator for refactorings. Filed: http://youtrack.jetbrains.com/issue/MPS-16040

Nevertheless, you can do the following:
refactor(refectoringContext)->void {
  sequence<node<Column>> columns = refactoringContext.node.getColumnOfThisProject(); 
  CodeBookGuesser_WordList guesser = new CodeBookGuesser_WordList(refactoringContext.project, columns.toList); 
  
  SwingUtilities.invokeLater(new Runnable(){
    public void run(){
      ProgressManager.getInstance().run(guesser); 
    }
  }); 
}
prettyPrint();

Note that the line
refactoringContext.node.model.add root(guesser.getCodebook());
prettyPrint();
is better to be moved to your guesser and to be executed in the same read/write action in which you perform model analysis. If you don't do so, you can get, for example, already-deleted model when you try to add a root (as you add root in another write-action and the model can be deleted between two write-actions).

Do not hesitate to ask further questions,
Mihail
0
Simon,

OOM is not this case, imo. If you remember your case, please add some details.
0
NICE ... :) works perfect .
0

Please sign in to leave a comment.