New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds travis_time tags to logs [WIP] #199
Adds travis_time tags to logs [WIP] #199
Conversation
@@ -1,6 +1,8 @@ | |||
#!/bin/bash | |||
source /etc/profile | |||
|
|||
IMEFORMAT="u=%U:r=%E:s=%S" |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This is super awesome! I swear all Sarnackis are god sends! |
end | ||
|
||
def measure(code) | ||
"{ time\n#{code};\n} 2> /tmp/timing.out " |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This is very exciting and very cool. Might also be good to add a timing start marker so we know which command/s has been timed? |
@joshk, |
Hey guys, so I pushed changed code. Let me write few words about this solution and where I need help with it. There is # (...)
travis_time_start() {
echo -en "travis_time:start\\r"
}
travis_time_finish() {
local result=$?
echo -en "travis_time:finish:`cat /tmp/timing.out`\\r"
return $result
}
# (...)
travis_time_start
{ time travis_retry bundle install 2>&3; } 3>&2 2> /tmp/timing.out
travis_time_finish
travis_assert There are 2 main differences from what I pushed before.
To make specs work with that design I added Do you have any idea how this can be tested? |
Btw: In a meantime I will try to add code to travis-web, to check this solution as a whole thing. Currently tests are not passing due to problem I have with writing matcher, but I think that tags are generated correctly. |
@lukesarnacki one idea came to mind, instead of outputting the time to a file, couldn't we use |
The drawback of such solution would be that time command gives real / user / system times and we are limited to real time only using Take a look at time man page (http://linux.die.net/man/1/time) and see if you find any of options interesting (memory? percentage of CPU?). I am not sure if this is useful at all, as I am not very familiar with travis. |
I think only Real time is what we care about right now. Writing to a file just feels a little odd to me, a little dirty in someways. Using |
Hi, Nice work. Great idea! Some days ago, I started working on a project with some scripts to create a trend from timestamps generated during a travis build. It would be great if we could combine our efforts? Or at least make our efforts compatible. :) I'm slightly in favor of having a seperate file with timestamps ( What do you think? |
If we don't want to use files, we could use named pipes which should be faster. Regardless what we use to get the result of time command, I'm all for using it, because we can get a lot of useful info which we can't get from our own date calculations. I would need to check in practice, but some potentially good looking options:
More on Memory data looks especially tempting for me, besides the regular times. |
I like the idea of being able to collect additional metrics. |
@lukesarnacki what needs to happen for this to move forward? Would love to have this as part of our builds. |
Oops, I knew I have forgotten about something... @roidrage current status is that code I wrote works (at least as far as I know), but tests won't pass. Please read last part of my comment #199 (comment) more or less when I write "here is where I need your help guys" ;). The other part is using those tags in ember app, which I haven't started on yet... So any help would be appreciated. |
@lukesarnacki that's awesome, thanks! @joshk @henrikhodne any ideas regarding the tests? Also, regarding the web frontend side of things, we can definitely look into that next. When the code is good to go, it should be able to run without interfering with the existing user interface, no? |
I just pushed close to final version of this PR. I am a bit embarrassed, when I realise that I finally figured that out in an 20 minutes ;). I guess that I couldn't see forest for the trees before and I needed step back. The only things that are in my opinion worth investigating a bit more are:
Other then that - tests are passing and I think it works as it should. |
@ruleant I totally missed your comment, sorry. I will take a look at it tomorrow :) Sounds interesting! |
@lukesarnacki No problem, looking forward to your comments. |
I brought this PR up to date and deployed to staging to test. It's not working quite right. See https://staging.travis-ci.org/BanzaiMan/travis_staging_test/jobs/391387#L14-L17 Not sure how $ git checkout -qf 5462b39f2865338a39d1ce4724b64335ef9eb52c
fatal: Not a git repository (or any of the parent directories): .git
travis_time:finish:u=0.001:r=0.004:s=0.001
The command "travis_time_finish" failed and exited with 128 during . The output suggests that the filter does not play well with I'll look into this in more detail tomorrow. |
The message above comes from |
So whats the status of this PR? What do we need to do to finish it off? |
@joshk There is a serious problem with the way |
I almost think it would be simpler to do the timing ourselves. eg. timestamp, run command, timestamp again, work out difference. |
That's more or less the way I do it in my project: log a timestamp, and calculate the time difference. With, after some parsing, these graphs as a result. To take the example from above (pseudo-code) :
This would add both start/end timestamp and the duration to the logfile. For my project those timestamps and/or duration logs would be very useful. is the location of the logfile available during |
@henrikhodne @BanzaiMan @lukesarnacki soooo guise, what can we do to get this finished off? I would hate to see this PR gather dust and go stale. How can we work together to make magic happen? |
As written, I don't think we can merge this. I think that a simpler approach that @ruleant suggested is preferable. I'll have to think how that might look a little more. |
agree! |
Hey guys, I think that I know the way to make it work with So I would love to see more metrics but it seems that simple approach would be much better here. Changing current code will be very easy fortunately ;). |
In order to measure commands' time, variables with timestamps are set before and after command execution. Time difference is printed as travis tag `travis_time:finish:` which can be used to show execution time on travis-web.
@BanzaiMan Can you run this and check if this is ok right now? Thanks! :) I changed it the way @ruleant suggested (using timestamps). I measure only seconds right now. We could add ms, but it won't work on OSX. I think we can go with seconds and see if we can get to miliseconds later. Also me and @drogus noticed that Try running these two scripts: echo -en "some long line here\r"; echo -en "shorter\n" echo -en "some long line here\r\033[0K"; echo -en "shorter\n" |
OK. I'll test this out tomorrow. |
Thanks a lot @BanzaiMan ! :) |
@lukesarnacki It has the same problem: https://staging.travis-ci.org/BanzaiMan/travis_staging_test/builds/391915#L27 Also, output from the command seems mangled. |
@BanzaiMan seems like I misunderstood the problem :( Thanks for help, will take a look once again. |
I think that the problem might lay in |
@@ -21,7 +21,7 @@ def raw(code, *args) | |||
end | |||
|
|||
def set(var, value, options = {}) | |||
cmd "export #{var}=#{value}", options.merge(log: false) | |||
cmd "export #{var}=#{value}", options.merge(log: false, timing: false) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
I think the issue is an order issue. If we make command assertion happen before timing then assertion will report the correct success/failure. eg. instead of time_start:command:time_finish:assertion, we want time_start:command:assertion:time_finish |
@joshk I think that might result in not reporting time for last fail command which may (or maybe not?) be useful, like: building a project failed, but I still want to know how long did it take. |
We might be able to use the Bash
We should add a |
I should read the comments first… I'll see if there's a way to make it work with functions. |
Looks like it works fine with functions too. I can look into updating the code and give it a spin. |
@henrikhodne it would be awesome! I haven't got time for open source for some time now and I am sad seeing this PR staying here for so long. |
@lukesarnacki No worries! Thanks for laying all the groundwork for this. |
Okay, I'm going to close this in favour of #263. |
This adds
travis_time:start
andtravis_time:end:s=0.01:u=0.01:r=0.01
tags to logs. This is marked as WIP because it is more like proof of concept which I would like to discuss. It was much harder to come up with than I expected and I would love to hear, if you also think that this is the way to go.All commands with
echo
andtiming
are wrapped intime
block and wrapped intravis_time
tags:On the beginning I wanted to make
time
one line but it broke almost all of the tests, so for now there are new lines to avoid this. I am wondering whether I should make it one line and change matchers or leave it like that with new lines.When command is finished, time is saved to timing.out file in
u=%U:r=%E:s=%S
format (it is set in environment variableTIMEFORMAT="u=%U:r=%E:s=%S"
). Then ontravis_time:end
tag its content is added usingcat
command.I am not sure if we need two tags, but I don't think that there is other way for knowing on what line command was displayed since we know time after output is printed. So basically time label in travis web would be shown where starting tag is, but time would be taken from ending tag.
I hope that I will proceed much faster with this feature from this point. Please let me know if you think that there is better way or if there is some hole in my logic. I will try to run travis locally soon and check this using
travis-web
(right now I am assuming that it will be possible to use it looking at how fold tags look like).Related issue: travis-ci/travis-ci#1246