Page 1 of 1

No More Progress Bar in Afwatch

Posted: Thu Jun 02, 2022 12:46 pm
by SteffenD
Hi there,

I noticed that Afwatch doesn't show a per-frame progress bar when rendering with Cycles any more (3.x+).
The syntax of the render log has changed to:

Code: Select all

Fra:31 Mem:1232.12M (Peak 2206.01M) | Time:02:15.69 | Remaining:02:00.57 | Mem:1139.36M, Peak:1237.26M | SHOT010_Scene, ViewLayer | Sample 2128/4096
The "blender_cycles.py" parser contains:

Code: Select all

for line in lines:
            # deal with new syntax
            status, perc = self.extractPercentage(line, '| Rendered ', 'Tiles')
            if status:
                self.percentframe = perc
                need_calc = True
            # deal with old syntax
            status, perc = self.extractPercentage(line, '| Path Tracing Tile ', ',')
            if status:
                self.percentframe = perc
                need_calc = True
So, it expects either "Rendered" or "Path Tracing Tile" to read the percentage from the log but he new (let's call it Cycles X) syntax prints "Sample". My Python knowledge isn't good enough to add the new syntax.
Can anybody help me / us?

Thanks

Re: No More Progress Bar in Afwatch

Posted: Sun Jun 05, 2022 4:04 pm
by SteffenD
OK, I fixed it (hopefully, it's more like an educated guess at copy&paste ;) ).

Code: Select all

# -*- coding: utf-8 -*-

from parsers import blender

class blender_cycles(blender.blender):
    """Blender Cycles
    """

    def __init__(self):
        blender.blender.__init__(self)

    def extractPercentage(self, line, left_token, right_token):
        """Tries to extract the percentage of the current render progress in this line.
        
        Works with the old syntax:
            (...) RenderLayer | Rendered 136/510 Tiles, Denoised 96 tiles
        And the new syntax:
            (...) RenderLayer | Path Tracing Tile  136/510, Denoised 96 tiles
        
        Args:
            line (string) : blender cycles render output line to parse
            left_token (string) : separator string to extract the percentage on the left side
            right_token (string) : separator string to extract the percentage on the right side
            
        Returns:
            (bool) : True if a percentage got extracted, False if not
            (int)  : percentage value
            
        """
        tokens = line.split(left_token)
        if len(tokens) > 1:
            tokens = tokens[1].split(right_token)   
            numbers = tokens[0].split('/')
            if len(numbers) == 2:
                try:
                    part0 = int(numbers[0])
                    part1 = int(numbers[1])
                    if part1 > 0:
                        perc = int(100 * part0 / part1)
                        return True, perc
                except:
                    pass
        return False, 0

    
    def do(self, i_args):
        data = i_args['data']

        lines = data.split('\n')
        need_calc = False
        for line in lines:
            # deal with Cycles X syntax
            status, perc = self.extractPercentage(line, '| Sample ', '\n')
            if status:
                self.percentframe = perc
                need_calc = True
            # deal with new syntax
            status, perc = self.extractPercentage(line, '| Rendered ', 'Tiles')
            if status:
                self.percentframe = perc
                need_calc = True
            # deal with old syntax
            status, perc = self.extractPercentage(line, '| Path Tracing Tile ', ',')
            if status:
                self.percentframe = perc
                need_calc = True                        
        if need_calc:
            self.calculate()
        blender.blender.do(self, i_args)
If I find some time I'll try a pull request. In the mean time you can just replace the blender_cycles.py in /cgru/afanasy/python/parsers with these changes

EDIT: I tried my best and made a pull request. I hope I didn't break anything!

Re: No More Progress Bar in Afwatch

Posted: Sun Jun 05, 2022 4:13 pm
by SteffenD
To get it running you have to update every client's blender_cycles.py and restart afrender

Re: No More Progress Bar in Afwatch

Posted: Mon Jun 06, 2022 8:56 am
by timurhai
Thank You!

Re: No More Progress Bar in Afwatch

Posted: Mon Jun 20, 2022 10:40 am
by SteffenD
Just noticed that my "fix" is only partially working. As soon as Cycles uses "Tiles" (e.g. when you render resolution is > 2048 px in a default scene or you deliberately told Cycles to use tiles e.g. to save some memory), every single tile reports its render progress in the range from 0 to max samples, i.e. in a default scene with 4096 adaptive samples and 4 tiles, Cycles counts up from 0 to 4096 four times. My primitive "logic" does not handle this case, the progress bars move back and restarts several times which might look confusing.
My Python-fu is very very limited so maybe some real coder can fix this ;)

Re: No More Progress Bar in Afwatch

Posted: Mon Jun 20, 2022 10:50 am
by timurhai
Hi!
Does Blender(Cycles) prints some info about tiles count before the render?
If so, parser should parse tiles number first, then caclulate total percentage using tiles count.

Re: No More Progress Bar in Afwatch

Posted: Mon Jun 20, 2022 11:06 am
by SteffenD
Thanks for you quick reply :)

Yes, I just found this:

Code: Select all

Fra:1 Mem:840.29M (Peak 1682.40M) | Time:00:06.59 | Remaining:18:15.69 | Mem:1147.60M, Peak:1153.71M | Scene, ViewLayer | Rendered 1/12 Tiles, Sample 80/4096
So there is info about the current tile / total number of tiles and of course the samples rendered.

Re: No More Progress Bar in Afwatch

Posted: Mon Jun 20, 2022 12:30 pm
by timurhai
So from this string

Code: Select all

Rendered 1/12 Tiles
we can parse and store total tiles count and the current tile number.

Re: No More Progress Bar in Afwatch

Posted: Tue Jun 21, 2022 12:46 pm
by SteffenD
Yes, but I'm an extreme coding noob :lol: and at least I can't do it.

Re: No More Progress Bar in Afwatch

Posted: Wed Jun 22, 2022 9:26 am
by timurhai
Look at https://docs.python.org/3/library/re.html#match-objects

Code: Select all

>>> import re
>>> re.search('Rendered (\d+)/(\d+) Tiles','Fra:1 Mem:840.29M (Peak 1682.40M) | Time:00:06.59 | Remaining:18:15.69 | Mem:1147.60M, Peak:1153.71M | Scene, ViewLayer | Rendered 1/12 Tiles, Sample 80/4096').groups()
('1', '12')