show_progress syntax / why the progress bar jumps off the screen with some flashables

byrong

Senior Member
Jul 9, 2010
695
722
0
East Coast
This has to be one of the more pointless things I've ever put time into understanding. Since the time has already been invested, however, I figured I might as well share what I've learned.

In the CM7 Nightlies thread, we've recently been talking about custom "all-in-one" zips that people create to flash after any Nightly install. As I was looking through various scripts (both in the thread and elsewhere on the forum), I noticed an inconsistent syntax being used for the show_progress command.

If you've ever flashed a zip and watched your progress bar fill up so far that it goes off the right side of your screen, chances are that the zip had the wrong syntax.

A lot of scripts that I've seen are using:
show_progress(duration,fraction)
fraction = a fraction of the bar (more on that in a moment)
duration = seconds

But the correct usage is:
show_progress(fraction,duration)
fraction = a fraction of the bar (more on that in a moment)
duration = seconds

The "seconds" part just means how long the progress bar should take to fill up to the new level. It will not delay your script in any way: it will only take this much time if something else in the script is also taking that much time.

For example, if you run this snippet, you can watch the progress bar partially fill up pieces at a time. Each piece will take 5 seconds to fill, then pause for 2 seconds before the next piece starts (sleep command is for 7, so after the progress bar is done its 5 seconds of movement, there are 2 seconds of sleep left until the next command)

Code:
show_progress(0.2,5);
sleep(7);
show_progress(0.2,5);
sleep(7);
show_progress(0.2,5);
sleep(7);
In this snippet, I've removed the sleep commands:

Code:
show_progress(0.2,5);
show_progress(0.2,5);
show_progress(0.2,5);
Now the progress bar will instantly jump and then the script will immediately end. Even though each chunk was supposed to gradually fill up over 5 seconds, nothing in the script allowed it to actually run for that long.

Note also that the fractions are cumulative. I've seen a lot of scripts that use the show_progress command but have 10%/20%/30%/40% arguments built in. They seem to assume this means that each command is setting the progress bar that new value, but that is not the case. Instead, that means that they are starting at 0 and adding 10. Then adding 20 to 10. Then adding 30 to the existing 30. Then adding 40 to the existing 60... you get the idea.

Regarding the fraction part of the command, I had assumed that 0 meant 0%, 0.5 was 50%, 1 was 100%. In my testing, however, that has not been the case.

For example, I tried the following:
Code:
show_progress(1,15);
sleep(20);
I expected that the progress bar would fill up to 100% over the course of 15 seconds. Instead, it only filled up about 75%

I kept testing until I found what visually makes my progress bar look actually full: 1.34

So if I want to watch the progress bar fill from 0% - 100% over the course of 10 seconds, I would use:
Code:
show_progress(1.34,10);
I have no idea why that's the magic value, but it's repeatable on my device. Please try on your own Incredible and let me know if you see the same. I'm using CWM 3.x for whatever it's worth. It wouldn't surprise me if this was different in other versions of CWM, but I don't know.


As an example of what I've seen, here are some lines from a popular kernel's script (I am only copying the show_progress lines)
Code:
show_progress(0.500000, 10);
show_progress(0.500000, 20);
show_progress(0.500000, 40);
show_progress(0.500000, 60);
show_progress(0.500000, 70);
show_progress(0.500000, 80);
show_progress(0.500000, 90);
show_progress(0.500000, 100);
It looks like the script author was trying to make the progress bar fill up in increments of 10, with a 0.5 second delay. What is actually being done by these lines, however, is to keep adding 0.5 (which works out to roughly 37% of 1.34) to the progress bar.

In other words, these commands will fill up the progress bar as follows:
0% > 37% > 75% > 112% > 149% > 187% > 224% > 261% > 299% > 336% > 373%

If the progress commands had enough time, this would also mean that each chunk would fill at a slower pace (since the duration is increasing), but the script moves fast enough that the user never sees this.

None of this actually changes the functionality of the script, hence my earlier declaration that this was somewhat pointless to learn. This is strictly an aesthetic issue for the user, but if you are going to write scripts, I hope this comes in handy.
 

NilsP

Inactive Recognized Developer
Jul 31, 2009
5,921
5,510
113
Near Albany NY
I enjoyed your writeup. It put things in perspective for me. I had come to the conclusion that the % could not add up to more than 100%. However, if you put a 0,0 statement in front of each new show_progress for example

show_progress(0,0)
show_progress(10, 1)

would show as approximately 10%

Now is you want to show you are now at 50% you could use the following

show_progress(0,0)
show_progress(50, 1)

This would first reset the counter to 0 then jump to approximately 50%

However, after reading your writeup I came to another conclusion. Since the progress never depends on how much time actually elapsed and is based on a guess I calculated how long it actually takes to flash my ROM which turned out to be approximately 175 seconds.

So, I put one statement in the front of the script

show_progress(1.34,175)

and removed all others.

Now it shows the bar gradually grow to 100% as the install progresses and hits 100% pretty close to real time end. Actuality need to set the 175 to 2 or 3 seconds longer than your average install time.
 

byrong

Senior Member
Jul 9, 2010
695
722
0
East Coast
Thanks for the additional info, NilsP: that is very interesting about resetting the progress bar at each step (and therefore being able to have more granular control)

You read my mind re: putting one show_progress at the beginning of the script that is timed based on avg installation duration. After figuring this stuff out, I put that on my "to do" list: figure out how long my personal scripts take and try to time the progress bar accordingly.

The advantage of the one-line route is not only simplicity, but a smoother progress bar. The disadvantage is if someone is running a phone that (for whatever reason) has a far-from-average install time.

For those who decide to have lots of individual progress markers through their script, at least if the timing is off, the next progress command will bump the bar to the right place. Of course, the disadvantage here is that the progress bar will fill up at an uneven pace.

Since it's based on pre-defined time, It's not that great of a function, no matter how you slice it :(
I agree that adding a few seconds to the average install time is probably the best route. This way, users who have a slow phone still have "padding" built in at the end (they won't think their phone has frozen). Users who have fast phones will just see the progress bar steadily fill to a partial state, then all of a sudden get a message that the script is done.
 
  • Like
Reactions: cottino

Molikai1988

Member
Jul 15, 2012
19
6
0
Oak Ridge
Although...

What I have been doing in my ROMs is this:

<code>
[Mod info]
...
show_progress(0,0)
[tell user formats happening]
[Format partitions]
show_progress(0.2,0)
...
[tell user system is copying]
[copy system]
show_progress(0.6,0)
...
[etc.. until 1.34 is hit]
...
[snarky comment about how my rom is awesome; credits]

</code>

Usually i pay little attention to time but more to total percent based on the weird 1.34 scale.

Great post though man.
 

mstdzw

Senior Member
May 26, 2009
316
53
0
I'm make a test zip:
CWM_Progress_test.zip

Code:
show_progress(0.100000, 0);
ui_print("1 +100000");
run_program("/sbin/sleep", "5");

show_progress(0.300000, 0);
ui_print("2 +300000");
run_program("/sbin/sleep", "5");

show_progress(0.300000, 0);
ui_print("3 +300000");
run_program("/sbin/sleep", "5");

show_progress(0.300000, 0);
ui_print("4 +300000");
run_program("/sbin/sleep", "5");

show_progress(0.300000, 0);
ui_print("5 +300000");
run_program("/sbin/sleep", "5");

show_progress(0.400000, 10);
ui_print("6 +400000, 10 finish");
run_program("/sbin/sleep", "5");
I have ~1mm free to 100%, how to complet this?
 

jbliz

Senior Member
Dec 25, 2013
105
13
0
Kendari
Not for me

I have try this :
show_progress(1.34, 10);

But it's not fully 100%. So I change it to :
show_progress(2.67, 10);

Yes, now that 100%. Just for me .
 

Octanium91

Senior Member
May 4, 2014
349
487
63
Kremenchug
octanium-os.blogspot.com
Try this!

Try this

Code:
#
# Progress bar
#
#Set range
#Where 0.1000000 - fraction (maximum 100%), 0 - seconds
show_progress(0.100000,0);
#Set the position of the progress bar on:
# 10%
set_progress(0.100000);
# 20%
set_progress(0.200000);
# 55%
set_progress(0.550000);
# 97%
set_progress(0.970000);
# 100%
set_progress(1.000000);
Code for test in recovery
Code:
#
# Progress bar
#
#Set range
#Where 0.1000000 - fraction (maximum 100%), 0 - seconds
ui_print("show progress");
show_progress(0.100000,0);
sleep(2);
#Set the position of the progress bar on:
# 10%
ui_print("10%");
set_progress(0.100000);
sleep(2);
# 20%
ui_print("20%");
set_progress(0.200000);
sleep(2);
# 55%
ui_print("55%");
set_progress(0.550000);
sleep(2);
# 97%
ui_print("97%");
set_progress(0.970000);
sleep(2);
# 100%
ui_print("100%");
set_progress(1.000000);
sleep(2);
Good luck!
 
  • Like
Reactions: defim and #Henkate

DeluxeMark

Senior Member
Sep 25, 2015
309
82
0
Try this

Code:
#
# Progress bar
#
#Set range
#Where 0.1000000 - fraction (maximum 100%), 0 - seconds
show_progress(0.100000,0);
#Set the position of the progress bar on:
# 10%
set_progress(0.100000);
# 20%
set_progress(0.200000);
# 55%
set_progress(0.550000);
# 97%
set_progress(0.970000);
# 100%
set_progress(1.000000);
Code for test in recovery
Code:
#
# Progress bar
#
#Set range
#Where 0.1000000 - fraction (maximum 100%), 0 - seconds
ui_print("show progress");
show_progress(0.100000,0);
sleep(2);
#Set the position of the progress bar on:
# 10%
ui_print("10%");
set_progress(0.100000);
sleep(2);
# 20%
ui_print("20%");
set_progress(0.200000);
sleep(2);
# 55%
ui_print("55%");
set_progress(0.550000);
sleep(2);
# 97%
ui_print("97%");
set_progress(0.970000);
sleep(2);
# 100%
ui_print("100%");
set_progress(1.000000);
sleep(2);
Good luck!
It worked! Thank you