3

I'm building a DSL application in XTend and I need to measure the time it takes to translate each document that I run through it.

I use the DSL capabilities to translate one data format (IFC) into another (TTL).

I tried to measure it using System.currentTimeMillis() in the doGenerate method of the generator (myDslGenerator.xtend) , but as far as I can see, this only measures the time it takes to write the output file, not the time it takes to parse the input file.

I don't need the time it takes to load the Eclipse application, just the actual time (not cpu-time) spent on translation for each file.

My current (wrong) approach gives me results between 0 and 500 ms for tasks that takes several (up to 20) seconds.

doGenerate is called from the ParallelBuilderParticipant class (handleChangedContents method) in the Eclipse dependencies, but I can't backtrace it any further to find where that is called from. But maybe this method actually wraps parsing as well (Resource resource = contect.resource) ?

Any insights would be great - thank you

EDIT: Trying to put some more information here - hope it's useful.

Functional Eclipse code

Measuring the runtime of the doGenerate method does give me the time it takes to write a ".ttl" file, but the time spent reading the ".ifc" file is not part of it, since it has been parsed before the doGenerate method is called. The doGenerate method is part of the XTend template, and comes from the AbstractGenerator.

Doing a usage search in the project, I can see that the doGenerate method is called from a Class called ParallelBuilderParticipant.

Dependency: ParallelBuilderParticipant.handeChangedContents

Will I find the full time it takes to parse one file and write another if I measure the time of this class instead? And if so, how do I do that, since this is a dependency .class file - Eclipse does not let me edit it.

Henry
  • 333
  • 1
  • 3
  • 10
  • Please show your code. See [MCVE] – Max Vollmer May 14 '18 at 11:35
  • There is not much to show. There is no problem in the code I wrote - I am just looking for something in the standard or generated Xtend code. The project is on my GitHub if it helps in any way: https://github.com/henriklange/ifcBrickConvertDsl – Henry May 14 '18 at 11:40
  • If there were no problem in your code you wouldn't have opened this question. Obviously your problem is that you're unable to measure the time accurately for a specific part of your project. Please create a [MCVE] that shows what you tried, and where you're stuck. And no, links to github are not helpful. Right now your question is either offtopic, or a duplicate, or unclear. Please read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Max Vollmer May 14 '18 at 11:45
  • I would show you code if it would help in any way, but it does not. I am asking about how a specific tool (Xtend) works in regards to where it calls my code from. I would not show you my HTML document to ask how Chrome parses an HTML document? I have read the articles that you link to, and perhaps the header could be better - that's all I get - I am pretty sure this question makes perfect sense to anyone who knows Xtend. – Henry May 14 '18 at 11:55
  • I know xtend and xtend is super flexible and versatile. I don't know how you setup your project and therefore I don't know how and where your files are loaded. Also questions about general hardware and software, or about recommendations for tools are offtopic. SO is for programming questions. If yours isn't a programming question, it might be better suited on another stackexchange site. I really want to help you, but with the current state of your question, I can't. – Max Vollmer May 14 '18 at 12:09
  • That is fair - I really want to be helpful and appreciate your time. Perhaps my own understanding of Xtend is what gets in the way and if I can answer any question that makes it easier to understand me, please let me know. When I run my project as an Eclipse application, I can insert text files or write them. Whenever I save, that text is parsed via my Xtext grammar and something new is written via my Xtend generator. The time that passes from I press save and until the file is generated, I would like to generate. I will update the question with some code and screenshots. – Henry May 14 '18 at 12:14
  • Your screenshots seem to be made in the resulting Eclipse IDE that you build with xtext. That's not the right place. You need to modify the project that builds the IDE, and you need to show us that project's code. There you can easily override `ParallelBuilderParticipant` or other xtext components, because xtext uses dependency injection. – Max Vollmer May 14 '18 at 12:51
  • I use Xtend in Eclipse to build another version of Eclipse that translates my files, yes. The screenshots are of the eclipse workspace that I work in to generate the other, not the resulting application. Or am I misunderstanding you? – Henry May 14 '18 at 12:56
  • Oh, I see, there was also some thinking mistake on my part. We always create both IDEs ourselves in our projects. Of course you can get a prebuild IDE with xtend that uses prebuild xtext dependencies. If no one else comes up with a smart solution, I hate to give you the bad news, but you probably also need to build the IDE that has xtend yourself. – Max Vollmer May 14 '18 at 13:06
  • I had a tunnel view here as I got so used to that procedure, I apologize. I now also get why you were a bit struggling with my requests for code. – Max Vollmer May 14 '18 at 13:07
  • 1
    Well, that definitely explains the miscommunication. Right now, I am looking into the parts of Xtend that I can actually manipulate from the template version to see if I can find any place to put a hook, but otherwise, I might need to either replace some dependencies with my own versions or find a template that is all Java, so I can edit the parts I need. – Henry May 14 '18 at 13:13
  • the main problem is that parsing, indexing, linking, resolving and validation + generation are all done in separate steps => you would need to have to measure at many different places. even if you have multiple files that reference each other you cannot even "blame" one file for all time if it itself needs other files e.g. during validation and this files would be loaded anyway (e.g. in a fullbuild) – Christian Dietrich May 15 '18 at 04:43
  • This is why I hooked in to the lexer, as that seems to be the first step in the process, so once that starts, I just put the current time in a variable and find it again once the file has been written. – Henry May 15 '18 at 06:47

2 Answers2

2

I found a solution that is good enough for what I need, and since I spent a lot of time looking for a solution online and almost as long making one myself, I thought I would share it.

It may have been unclear that I am using a pre-built version of Xtend with Eclipse Oxygen. To measure the time it takes to parse a file and write the result, I hooked into the lexer (InternalIfcBrickLexer.java) in the antlr package (org.xtext.ifcbrickconvert.parser.antlr.internal). In the constructor, InternalIfcBrickLexer(CharStream input) , I printed the System.currentTimeMillis() to the console. The lexer is run as the first process in a number of cases, including when you save.

In the generator (IfcBrickGenerator.xtend), I override the interface method void afterGenerate(Resource input, ...) and print the System.currentTimeMillis again.

To avoid calculations, I made a static variable in the lexer and subtract that from the current time in the afterGenerate method, and so, I now have the time it takes to lex, parse, translate and write a new file in milliseconds.

There might be a slight inaccuracy, as I don't know if something may be called before the lexer, but it seems pretty accurate from my initial tests, and since the files I work with take anywhere from 20 - 2000 seconds to complete, a couple of hundred milliseconds are not super important.

The one fallback of this method is that it needs to run on only one file - once you save the file and the processing starts, you may not alter any file - even without saving - or you will not get the correct result. This is however what I expected/wanted, so it is not a problem for me.

Thank you for the inputs - I hope someone finds this useful :)

Henry
  • 333
  • 1
  • 3
  • 10
  • 1
    Thanks - but I know. There is just a time constraint so I can't do it until tomorrow :) – Henry May 15 '18 at 06:48
1

First off, I will assume you meant you have built a DSL in Xtext with a code generator written in Xtend and you want to know how long it takes to translate a "program" written using your DSL into whatever you generate it into.

I am not sure Xtext has built-in support for this. Since you can already measure the time used to write the output files, I would suggest measuring from the "starting point" of the compilation. I guess Xtext, by default, triggers it automatically on save so you could try and see if you can setup your own hook alongside it.

user1292456
  • 778
  • 4
  • 12
  • Yes, I actually considered something like this - making a different application that gets System.currentTimeMillis when I press cmd+S and then just subtract that from the current time when output is made. Not the prettiest solution, but it should work. – Henry May 14 '18 at 12:36
  • Oh, and by the way - you are absolutely right. That IS what I mean. I will update the question again. – Henry May 14 '18 at 12:37