2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-12 16:46:35 +00:00

Fixed Renderer, to enbale multi-processing Rendering

git-svn-id: https://svn.fhem.de/fhem/trunk@688 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
odroegehorn 2010-08-10 22:20:41 +00:00
parent 8c3c05b4a2
commit 8aec519ae1
3 changed files with 46 additions and 12 deletions

View File

@ -5328,7 +5328,8 @@ isday</pre>
<ul>
The FHEMRENDERER module is intended to render (draw) graphics based on the FHEM Log-Files.
This can be done either based on a timer (used in the module) or based on a direct call of GET.
The rendered graphics will be stored in a pre-defined directory with a predefined prefix of the files.
The rendered graphics will be stored in a pre-defined directory with a predefined prefix of the files. The renderer can also work in a multi-process mode,
which doesn't block the main FHEM-Loop.
<br> <br>
<a name="FHEMRENDERERdefine"></a>
@ -5340,12 +5341,13 @@ isday</pre>
Otherwise this option has no real meaning for FHEMRENDERER.<br>
<br>
As a side-effect of defining this "device" the following attributes will be set for this "device":<br>
&nbsp;&nbsp;plotmode gnuplot <br>
&nbsp;&nbsp;plotsize 800,200 <br>
&nbsp;&nbsp;refresh 00:10:00 <br>
&nbsp;&nbsp;room Unsorted <br>
&nbsp;&nbsp;status off <br>
&nbsp;&nbsp;tmpfile /tmp/ <br>
&nbsp;&nbsp;plotmode gnuplot <br>
&nbsp;&nbsp;plotsize 800,200 <br>
&nbsp;&nbsp;refresh 00:10:00 <br>
&nbsp;&nbsp;room Unsorted <br>
&nbsp;&nbsp;status off <br>
&nbsp;&nbsp;tmpfile /tmp/ <br>
&nbsp;&nbsp;multiprocess off <br>
<br>
NOTE: The Logfile will report (with LogLevel 2) that the FHEMRENDERER has been defined.
@ -5448,7 +5450,16 @@ isday</pre>
filenames.<br/> You can specify a path to which the files will be
rendered. If you also specify a prefix, this will be used to build the
resulting filename.
</li><br> </li> </ul>
</li><br>
<li>multiprocess<br/>
This defines if the Renderer works in a multiprocessing mode.<br/>
You can set multiprocessing either to ON / OFF and the renderer will draw the
time-scheduled tasks either in multiprocessing mode, or not.
NOTE: Direct GET calls, except for a general GET (for all weblinks) will be renderer
in an interactive mode, meaning that the FHEM-Loop will be block as long as the graphics are rendered.
If you want to use multiprocessing, set the RENDERER and multiprocessing to ON and the
weblink-graphics will be rendered in the background.
</li><br></li> </ul>
</ul>
</ul>

View File

@ -84,6 +84,7 @@ my $__data; # Filecontent from browser when editing a file
my $__svgloaded; # Do not load the SVG twice
my $__lastxmllist; # last time xmllist was parsed
my $FHEMRENDERER_tmpfile; # TempDir & File for the rendered graphics
my $__mp;
#####################################
sub
@ -94,7 +95,7 @@ FHEMRENDERER_Initialize($)
# $hash->{ReadFn} = "FHEMRENDERER_Read";
$hash->{DefFn} = "FHEMRENDERER_Define";
$hash->{UndefFn} = "FHEMRENDERER_Undef";
$hash->{AttrList}= "loglevel:0,1,2,3,4,5,6 plotmode:gnuplot,gnuplot-scroll plotsize refresh tmpfile status";
$hash->{AttrList}= "loglevel:0,1,2,3,4,5,6 plotmode:gnuplot,gnuplot-scroll plotsize refresh tmpfile status multiprocess";
$hash->{SetFn} = "FHEMRENDERER_Set";
$hash->{GetFn} = "FHEMRENDERER_Get";
}
@ -121,6 +122,7 @@ FHEMRENDERER_Define($$)
$__timeinterval = FHEMRENDERER_getAttr("refresh", "00:10:00");
$__plotmode = FHEMRENDERER_getAttr("plotmode", "gnuplot");
$__plotsize = FHEMRENDERER_getAttr("plotsize", "800,200");
$__mp = FHEMRENDERER_getAttr("multiprocess", "off");
$FHEMRENDERER_tmpfile = FHEMRENDERER_getAttr("tmpfile", "/tmp/");
FHEMRENDERER_setAttr("status", "off");
@ -174,6 +176,7 @@ FHEMRENDERER_Get($@)
my $ret = undef;
my $v;
my $t;
my $pid;
FHEMRENDERER_parseXmlList(0);
@ -183,8 +186,9 @@ FHEMRENDERER_Get($@)
$__plotmode = FHEMRENDERER_getAttr("plotmode", "gnuplot");
$__plotsize = FHEMRENDERER_getAttr("plotsize", "800,200");
$FHEMRENDERER_tmpfile = FHEMRENDERER_getAttr("tmpfile", "/tmp/");
if (@a <= 2) {
$__mp = FHEMRENDERER_getAttr("multiprocess", "off");
if (@a <= 2) {
if (@a == 2) {
my ($p,$v) = split("=",$a[1], 2);
@ -197,6 +201,16 @@ FHEMRENDERER_Get($@)
}
}
if ($__mp ne "off") {
$pid = fork();
if (not defined $pid) {
return ("ERROR: No MultiProcessing possible");
}
if ($pid > 0) {
return $ret;
}
}
foreach my $type (sort keys %__types) {
if($type eq "weblink") {
foreach my $d (sort keys %__devs ) {
@ -255,7 +269,11 @@ FHEMRENDERER_Get($@)
} else {
return "\"get FHEMRENDERER\" needs either none, 1(pos) or 3-5 arguments ([file-name] device type logfile [pos=zoom=XX&off=YYY])";
}
return $ret;
if (not defined $pid) {
return $ret;
} else {
exit(0);
}
}
#####################

View File

@ -47,12 +47,15 @@ The FHEMRENDERER uses attributes to control the behaviour:
room Unsorted
status off
tmpfile /tmp/
multiprocess off
These attributes have the following meaning:
plotmode, plotsize: Control gnuplot and the desired output
refresh: type HH:MM:SS, is the time-interval in which the re-rendering is done
status: Tells if the timer-based re-rendering is on/off
tmpfile: Is the path (and prefix, if given) of the graphic-files, that will be rendered
multiprocess: You can set "on" or "off". If multiprocess is "on" the time-scheduled renderings will be done in a
mutli-process manner, and FHEM will not be blocked by the rendering process.
NOTE: The timer-based rendering renders ONLY those fileplots, for which you have defined a WebLink !
See WebLink for more details on how to define.
@ -88,6 +91,7 @@ DEFINE
room Unsorted
status off
tmpfile /tmp/
multiprocess off
NOTE: The Logfile will report (with LogLevel 2) that the FHEMRENDERER has been defined.
@ -169,6 +173,7 @@ ATTR
refresh Timer-Interval for rerendering (HH:MM:SS)
status Status of the Timer (off/on)
tmpfile Path and prefix of for the rendered graphics (e.g. /tmp/)
multiprocess on / off