Author Topic: PixelOverlay-Clock script slowly degrades and then stops  (Read 328 times)

Offline JonB256

  • Supporting Member
  • ******
  • Join Date: Mar 2013
  • Location: Granbury, Texas
  • Posts: 5,189
  • Kudos: 124
    • Granbury Christmas Lights
PixelOverlay-Clock script slowly degrades and then stops
« on: March 15, 2019, 08:04:26 AM »
On a small 2x2 P6 matrix, I am running the pixeloverlay-clock.pl script from the Repository.

I edited the script (from within the File Manager) to be centered, not scrolling, and then "Run" it from the same location.

Works great!  for about 4 hours. Then it starts skipping seconds and catching up. After about 8 hours or so, it will just freeze.

This is on a PocketBeagle (if that makes any difference) with Dan's PocketScroller mounted.

Code: [Select]
#!/usr/bin/perl
#############################################################################
# PixelOverlay-Clock.pl - Scroll a changing clock across a matrix
#############################################################################
# Set our library path to find the FPP Perl modules
use lib "/opt/fpp/lib/perl/";

# Use the FPP Memory Map module to talk to the daemon
use FPP::MemoryMap;

#############################################################################
# Setup some variables (this is the part you want to edit for font, color, etc.)
my $name  = "P6x4panel";    # Memory Mapped block name
my $color = "#00FF00";      # Text Color (also names like 'red', 'blue', etc.)
my $fill  = "#000000";      # Fill color (not used currently)
my $font  = "fixed";        # Font Name
my $size  = "16";           # Font size
my $pos   = "center";       # Position: 'scroll', 'center', 'x,y' (ie, '10,20')
my $dir   = "R2L";          # Scroll Direction: 'R2L', 'L2R', 'T2B', 'B2T'
my $pps   = 15;              # Pixels Per Second

#############################################################################
# This function will get called once per second and returns the text string
# to be displayed at that point in time.
sub GetNextMessage
{
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

$msg = sprintf("%02d:%02d:%02d", $hour, $min, $sec);

return $msg;
}

#############################################################################
# Main part of program

# Instantiate a new instance of the MemoryMap interface
my $fppmm = new FPP::MemoryMap;

# Open the maps
$fppmm->OpenMaps();

# Get info about the block we are interested in
my $blk   = $fppmm->GetBlockInfo($name);

# Clear the block, probably not necessary
$fppmm->SetBlockColor($blk, 0, 0, 0);

# Enable the block (pass 2 for transparent mode, or 3 for transparent RGB)
$fppmm->SetBlockState($blk, 1);

# Loop forever (ie, you'll need to CTRL-C to stop this script or kill it)
while (1) {
$fppmm->TextMessage($blk, \&GetNextMessage, $color, $fill, $font, $size, $pos, $dir, $pps);
}

# Disable the block
$fppmm->SetBlockState($blk, 0);

# Close the maps (shouldn't make it here with the above "while (1)" loop)
$fppmm->CloseMaps();

# Exit cleanly (shouldn't make it here with the above "while (1)" loop)
exit(0);

#############################################################################

Offline CaptainMurdoch

  • Administrator
  • *****
  • Join Date: Sep 2013
  • Location: Washington
  • Posts: 9,836
  • Kudos: 214
Re: PixelOverlay-Clock script slowly degrades and then stops
« Reply #1 on: March 15, 2019, 09:34:45 AM »
Dan is currently rewriting a lot of this code and moving the functionality of the Perl module directly into fppd, so text writing will be done via a REST API call and the current Pixel Overlay scripts will need to be updated to work with the new code.   I haven't run the clock script long term, but there could be an issue with memory not being freed up automatically somewhere.  Users running the non-clock scripts may not notice for a lot longer time since those scripts don't change the image every second.

Can you login via ssh and run "ps auxw | grep YOURSCRIPTNAME" after starting the script and then run the same thing an hour or two later and see if the memory used is growing?  The memory number are in the 5th and 6th columns.  The 5th is the virtual memory mapped for the process and the 6th is the resident memory for the process, this is essentially how much real memory the process is taking.
-
Chris

Offline JonB256

  • Supporting Member
  • ******
  • Join Date: Mar 2013
  • Location: Granbury, Texas
  • Posts: 5,189
  • Kudos: 124
    • Granbury Christmas Lights
Re: PixelOverlay-Clock script slowly degrades and then stops
« Reply #2 on: March 15, 2019, 10:48:10 AM »
Thanks, Chris.  You did make me learn a bit about REST APIs and their usage.

I do see memory numbers creeping up in a PuTTy window but won't be home around the time I expect it to have problems. Will have to wait until Monday.

here is what I'm seeing so far, though (about one hour of run time)
Memory usage on the "about" page is slowly creeping up, also.

Code: [Select]
fpp@PocketScroller:~$ ps aux2 | grep PixelOverlay-Clock.pl
fpp      11525  0.0  0.1   1432   972 ?        S    10:46   0:00 sh -c sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root     11526  0.0  0.4   4624  2440 ?        S    10:46   0:00 sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root     11527 95.4 16.5 116808 82072 ?        R    10:46   1:41 /usr/bin/perl /home/fpp/media/scripts/PixelOverlay-Clock.pl
fpp      11551  0.0  0.3   3764  1640 pts/0    S+   10:48   0:00 grep PixelOverlay-Clock.pl
fpp@PocketScroller:~$ ps aux2 | grep PixelOverlay-Clock.pl
fpp      11525  0.0  0.1   1432   972 ?        S    10:46   0:00 sh -c sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root     11526  0.0  0.4   4624  2440 ?        S    10:46   0:00 sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root     11527 94.8 16.7 117760 83020 ?        R    10:46   3:33 /usr/bin/perl /home/fpp/media/scripts/PixelOverlay-Clock.pl
fpp      11649  0.0  0.3   3764  1516 pts/0    S+   10:50   0:00 grep PixelOverlay-Clock.pl
fpp@PocketScroller:~$ ps aux2 | grep PixelOverlay-Clock.pl
fpp      11525  0.0  0.1   1432   972 ?        S    10:46   0:00 sh -c sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root     11526  0.0  0.4   4624  2440 ?        S    10:46   0:00 sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root     11527 91.7 20.2 135416 100716 ?       R    10:46  41:10 /usr/bin/perl /home/fpp/media/scripts/PixelOverlay-Clock.pl
fpp      11826  0.0  0.3   3764  1584 pts/0    S+   11:31   0:00 grep PixelOverlay-Clock.pl
fpp@PocketScroller:~$ ps aux2 | grep PixelOverlay-Clock.pl
fpp      11525  0.0  0.1   1432   972 ?        S    10:46   0:00 sh -c sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root     11526  0.0  0.4   4624  2440 ?        S    10:46   0:00 sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root     11527 92.1 20.9 138800 104060 ?       R    10:46  46:10 /usr/bin/perl /home/fpp/media/scripts/PixelOverlay-Clock.pl
fpp      11896  0.0  0.3   3764  1612 pts/0    S+   11:36   0:00 grep PixelOverlay-Clock.pl
fpp@PocketScroller:~$ ps aux2 | grep PixelOverlay-Clock.pl
fpp      11525  0.0  0.1   1432   972 ?        S    10:46   0:00 sh -c sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root     11526  0.0  0.4   4624  2440 ?        S    10:46   0:00 sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root     11527 92.3 21.2 140364 105664 ?       R    10:46  49:45 /usr/bin/perl /home/fpp/media/scripts/PixelOverlay-Clock.pl
fpp      11960  0.0  0.3   3764  1672 pts/0    S+   11:40   0:00 grep PixelOverlay-Clock.pl

Offline CaptainMurdoch

  • Administrator
  • *****
  • Join Date: Sep 2013
  • Location: Washington
  • Posts: 9,836
  • Kudos: 214
Re: PixelOverlay-Clock script slowly degrades and then stops
« Reply #3 on: March 15, 2019, 02:54:33 PM »
So in less than an hour running, the memory utilization went up by 20MBytes.  That doesn't look good if it is a consistent pattern.

I will take another look at the perl module to see if there is anything we could be doing to prevent that.  I glanced at it earlier, but since most of that code hasn't been touched in years I didn't glance long enough to totally refresh my memory on all the aspects of it.

Offline JonB256

  • Supporting Member
  • ******
  • Join Date: Mar 2013
  • Location: Granbury, Texas
  • Posts: 5,189
  • Kudos: 124
    • Granbury Christmas Lights
Re: PixelOverlay-Clock script slowly degrades and then stops
« Reply #4 on: March 22, 2019, 06:31:24 AM »
So in less than an hour running, the memory utilization went up by 20MBytes.  That doesn't look good if it is a consistent pattern.

I will take another look at the perl module to see if there is anything we could be doing to prevent that.  I glanced at it earlier, but since most of that code hasn't been touched in years I didn't glance long enough to totally refresh my memory on all the aspects of it.

It is consistent. Memory count keeps going up. Finally, it will stop running and the display will freeze at that time. (so my SSH won't show the final amount of memory usage at "time of death."

Offline CaptainMurdoch

  • Administrator
  • *****
  • Join Date: Sep 2013
  • Location: Washington
  • Posts: 9,836
  • Kudos: 214
Re: PixelOverlay-Clock script slowly degrades and then stops
« Reply #5 on: March 22, 2019, 10:06:26 AM »
It is consistent. Memory count keeps going up. Finally, it will stop running and the display will freeze at that time. (so my SSH won't show the final amount of memory usage at "time of death."

Are you running the latest master code on this or v2.6?  In Master, we use a different library now, GraphicsMagick vs the previous ImageMagick, so I'm wondering if the effect is still the same in Master.  If it is, then I will dive deeper into the code.  I have a note to look at it, but haven't had a chance yet.

Offline dkulp

  • Developer
  • ******
  • Join Date: Sep 2013
  • Location: Framingham, MA
  • Posts: 1,504
  • Kudos: 87
    • KulpLights.com
Re: PixelOverlay-Clock script slowly degrades and then stops
« Reply #6 on: March 22, 2019, 10:23:55 AM »
The other thing I'd like to do is re-write the script to use the REST API instead of the Perl stuff.   Should simplify the script a bit (I hope) and possibly remove the memory leak.   That said, if I did this, I'd also move it to php or python instead of perl. 

Offline JonB256

  • Supporting Member
  • ******
  • Join Date: Mar 2013
  • Location: Granbury, Texas
  • Posts: 5,189
  • Kudos: 124
    • Granbury Christmas Lights
Re: PixelOverlay-Clock script slowly degrades and then stops
« Reply #7 on: March 22, 2019, 05:50:12 PM »
Are you running the latest master code on this or v2.6?  In Master, we use a different library now, GraphicsMagick vs the previous ImageMagick, so I'm wondering if the effect is still the same in Master.  If it is, then I will dive deeper into the code.  I have a note to look at it, but haven't had a chance yet.

Running on Master.  Will switch it to v2.6 and test.

Switched the PocketScroller to v2.6.  So far, the script is not working.
Reinstalled MatrixTools and tested - looks good.
Erased old script, installed new from Repository and edited.
Still nothing. :(

but I do see this error message :
Can't locate auto/Image/Magick/QueryMultil.al in @INC (@INC contains: /opt/fpp/lib/perl/ /etc/perl /usr/local/lib/arm-linux-gnueabihf/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/arm-linux-gnueabihf/perl5/5.24 /usr/share/perl5 /usr/lib/arm-linux-gnueabihf/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/arm-linux-gnueabihf/perl-base) at /opt/fpp/lib/perl/FPP/MemoryMap.pm line 682.
« Last Edit: March 22, 2019, 06:41:43 PM by JonB256 »

Offline JonB256

  • Supporting Member
  • ******
  • Join Date: Mar 2013
  • Location: Granbury, Texas
  • Posts: 5,189
  • Kudos: 124
    • Granbury Christmas Lights
Re: PixelOverlay-Clock script slowly degrades and then stops
« Reply #8 on: March 25, 2019, 05:40:01 AM »
Moved back to Master branch since v2.6 didn't run.
Finally caught it when it was skipping display seconds (sometimes up to 10 seconds) but before it crashed.
613 minutes of run time. It was crashed the next time I checked.

Code: [Select]
fpp@PocketScroller:~$ ps aux2 | grep PixelOverlay-Clock.pl
fpp       2074  0.0  0.2   1432  1036 ?        S    14:25   0:00 sh -c sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root      2075  0.0  0.4   4624  2396 ?        S    14:25   0:00 sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root      2076 95.6 33.8 203268 168128 ?       R    14:25 316:18 /usr/bin/perl /home/fpp/media/scripts/PixelOverlay-Clock.pl
fpp       4260  0.0  0.3   3764  1520 pts/0    S+   19:56   0:00 grep PixelOverlay-Clock.pl
fpp@PocketScroller:~$ ps aux2 | grep PixelOverlay-Clock.pl
fpp       2074  0.0  0.2   1432  1036 ?        S    14:25   0:00 sh -c sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root      2075  0.0  0.4   4624  2396 ?        S    14:25   0:00 sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root      2076 95.6 37.8 223348 188104 ?       R    14:25 367:12 /usr/bin/perl /home/fpp/media/scripts/PixelOverlay-Clock.pl
fpp       4545  0.0  0.3   3764  1492 pts/0    S+   20:49   0:00 grep PixelOverlay-Clock.pl
fpp@PocketScroller:~$ ps aux2 | grep PixelOverlay-Clock.pl
fpp       2074  0.0  0.0   1432    72 ?        S    Mar24   0:00 sh -c sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root      2075  0.0  0.0   4624   372 ?        S    Mar24   0:00 sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Clock.pl
root      2076 83.4 53.4 305232 265384 ?       D    Mar24 613:57 /usr/bin/perl /home/fpp/media/scripts/PixelOverlay-Clock.pl
fpp       6391  0.6  0.0   3764   380 pts/0    S+   02:41   0:00 grep PixelOverlay-Clock.pl
fpp@PocketScroller:~$ ps aux2 | grep PixelOverlay-Clock.pl
fpp       7714  0.0  0.3   3764  1524 pts/0    S+   06:35   0:00 grep PixelOverlay-Clock.pl

From my usage point, if the memory leak isn't easily fixed, could the script be set to Kill itself once per hour, free the memory and restart?

Offline dkulp

  • Developer
  • ******
  • Join Date: Sep 2013
  • Location: Framingham, MA
  • Posts: 1,504
  • Kudos: 87
    • KulpLights.com
Re: PixelOverlay-Clock script slowly degrades and then stops
« Reply #9 on: March 25, 2019, 03:27:05 PM »

On the very latest master (just committed a fix), can you try the script in the attached zip?   This is written in php instead of perl and uses the new REST api instead of the Perl memory map stuff.   Thus, the php process doesn't really do much at all, but if there is a memory leak in the image library it may manifest itself in the FPPD daemon instead since it's running in there.




Offline JonB256

  • Supporting Member
  • ******
  • Join Date: Mar 2013
  • Location: Granbury, Texas
  • Posts: 5,189
  • Kudos: 124
    • Granbury Christmas Lights
Re: PixelOverlay-Clock script slowly degrades and then stops
« Reply #10 on: March 25, 2019, 06:58:44 PM »
Installed and running. Amount of text is a bit much for my 2x2 P6 display. Set font to 8pt to fit everything.
Will watch for memory changes.

Offline JonB256

  • Supporting Member
  • ******
  • Join Date: Mar 2013
  • Location: Granbury, Texas
  • Posts: 5,189
  • Kudos: 124
    • Granbury Christmas Lights
Re: PixelOverlay-Clock script slowly degrades and then stops
« Reply #11 on: March 26, 2019, 04:57:27 AM »
Running overnight - still running. Same memory check shows virtually no memory creep (and seems to use a lot less)

Code: [Select]
fpp@PocketScroller:~$ ps aux2 | grep PixelOverlay-Countdown.php
fpp       2048  0.0  0.1   1432   896 ?        S    19:56   0:00 sh -c sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Countdown.php
root      2049  0.0  0.4   4624  2420 ?        S    19:56   0:00 sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Countdown.php
root      2050  0.3  3.1  68364 15900 ?        S    19:56   0:00 /usr/bin/php /home/fpp/media/scripts/PixelOverlay-Countdown.php
fpp       2186  0.0  0.3   3764  1672 pts/0    S+   20:00   0:00 grep PixelOverlay-Countdown.php
fpp@PocketScroller:~$ ps aux2 | grep PixelOverlay-Countdown.php
fpp       2048  0.0  0.1   1432   896 ?        S    Mar25   0:00 sh -c sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Countdown.php
root      2049  0.0  0.4   4624  2420 ?        S    Mar25   0:00 sudo /opt/fpp/scripts/eventScript /home/fpp/media/scripts/PixelOverlay-Countdown.php
root      2050  0.2  3.2  68364 15904 ?        S    Mar25   1:30 /usr/bin/php /home/fpp/media/scripts/PixelOverlay-Countdown.php
fpp       5825  0.0  0.3   3764  1676 pts/0    S+   05:52   0:00 grep PixelOverlay-Countdown.php
fpp@PocketScroller:~$

Offline dkulp

  • Developer
  • ******
  • Join Date: Sep 2013
  • Location: Framingham, MA
  • Posts: 1,504
  • Kudos: 87
    • KulpLights.com
Re: PixelOverlay-Clock script slowly degrades and then stops
« Reply #12 on: March 26, 2019, 05:40:49 AM »
The REST api moves all the graphics/font handling into FPPD.   Thus, if there is a memory leak, it will be in FPPD, not the script now.   

Offline JonB256

  • Supporting Member
  • ******
  • Join Date: Mar 2013
  • Location: Granbury, Texas
  • Posts: 5,189
  • Kudos: 124
    • Granbury Christmas Lights
Re: PixelOverlay-Clock script slowly degrades and then stops
« Reply #13 on: March 26, 2019, 06:10:45 AM »
Ok. I'll watch the Memory Usage on the about.php page.

Also, worked on "Center" but did not seem to work for "L2R"
Never got any scrolling text.

Offline dkulp

  • Developer
  • ******
  • Join Date: Sep 2013
  • Location: Framingham, MA
  • Posts: 1,504
  • Kudos: 87
    • KulpLights.com
Re: PixelOverlay-Clock script slowly degrades and then stops
« Reply #14 on: March 26, 2019, 06:45:29 AM »
Ok. I'll watch the Memory Usage on the about.php page.

Also, worked on "Center" but did not seem to work for "L2R"
Never got any scrolling text.


It likely wouldn't with that script.   Since it restarts the scroll every second, you would have to adjust the pixelPerSecond to get across the entire screen within one second.  Or adjust the "sleep" to sleep more than a second, but then it wouldn't update the seconds every second. 

 

Back to top