Fixed Renderer, to enbale multi-processing Rendering

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

View File

@@ -5328,7 +5328,8 @@ isday</pre>
<ul> <ul>
The FHEMRENDERER module is intended to render (draw) graphics based on the FHEM Log-Files. 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. 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> <br> <br>
<a name="FHEMRENDERERdefine"></a> <a name="FHEMRENDERERdefine"></a>
@@ -5346,6 +5347,7 @@ isday</pre>
&nbsp;&nbsp;room Unsorted <br> &nbsp;&nbsp;room Unsorted <br>
&nbsp;&nbsp;status off <br> &nbsp;&nbsp;status off <br>
&nbsp;&nbsp;tmpfile /tmp/ <br> &nbsp;&nbsp;tmpfile /tmp/ <br>
&nbsp;&nbsp;multiprocess off <br>
<br> <br>
NOTE: The Logfile will report (with LogLevel 2) that the FHEMRENDERER has been defined. NOTE: The Logfile will report (with LogLevel 2) that the FHEMRENDERER has been defined.
@@ -5448,6 +5450,15 @@ isday</pre>
filenames.<br/> You can specify a path to which the files will be 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 rendered. If you also specify a prefix, this will be used to build the
resulting filename. resulting filename.
</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> </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 $__svgloaded; # Do not load the SVG twice
my $__lastxmllist; # last time xmllist was parsed my $__lastxmllist; # last time xmllist was parsed
my $FHEMRENDERER_tmpfile; # TempDir & File for the rendered graphics my $FHEMRENDERER_tmpfile; # TempDir & File for the rendered graphics
my $__mp;
##################################### #####################################
sub sub
@@ -94,7 +95,7 @@ FHEMRENDERER_Initialize($)
# $hash->{ReadFn} = "FHEMRENDERER_Read"; # $hash->{ReadFn} = "FHEMRENDERER_Read";
$hash->{DefFn} = "FHEMRENDERER_Define"; $hash->{DefFn} = "FHEMRENDERER_Define";
$hash->{UndefFn} = "FHEMRENDERER_Undef"; $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->{SetFn} = "FHEMRENDERER_Set";
$hash->{GetFn} = "FHEMRENDERER_Get"; $hash->{GetFn} = "FHEMRENDERER_Get";
} }
@@ -121,6 +122,7 @@ FHEMRENDERER_Define($$)
$__timeinterval = FHEMRENDERER_getAttr("refresh", "00:10:00"); $__timeinterval = FHEMRENDERER_getAttr("refresh", "00:10:00");
$__plotmode = FHEMRENDERER_getAttr("plotmode", "gnuplot"); $__plotmode = FHEMRENDERER_getAttr("plotmode", "gnuplot");
$__plotsize = FHEMRENDERER_getAttr("plotsize", "800,200"); $__plotsize = FHEMRENDERER_getAttr("plotsize", "800,200");
$__mp = FHEMRENDERER_getAttr("multiprocess", "off");
$FHEMRENDERER_tmpfile = FHEMRENDERER_getAttr("tmpfile", "/tmp/"); $FHEMRENDERER_tmpfile = FHEMRENDERER_getAttr("tmpfile", "/tmp/");
FHEMRENDERER_setAttr("status", "off"); FHEMRENDERER_setAttr("status", "off");
@@ -174,6 +176,7 @@ FHEMRENDERER_Get($@)
my $ret = undef; my $ret = undef;
my $v; my $v;
my $t; my $t;
my $pid;
FHEMRENDERER_parseXmlList(0); FHEMRENDERER_parseXmlList(0);
@@ -183,6 +186,7 @@ FHEMRENDERER_Get($@)
$__plotmode = FHEMRENDERER_getAttr("plotmode", "gnuplot"); $__plotmode = FHEMRENDERER_getAttr("plotmode", "gnuplot");
$__plotsize = FHEMRENDERER_getAttr("plotsize", "800,200"); $__plotsize = FHEMRENDERER_getAttr("plotsize", "800,200");
$FHEMRENDERER_tmpfile = FHEMRENDERER_getAttr("tmpfile", "/tmp/"); $FHEMRENDERER_tmpfile = FHEMRENDERER_getAttr("tmpfile", "/tmp/");
$__mp = FHEMRENDERER_getAttr("multiprocess", "off");
if (@a <= 2) { if (@a <= 2) {
if (@a == 2) { if (@a == 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) { foreach my $type (sort keys %__types) {
if($type eq "weblink") { if($type eq "weblink") {
foreach my $d (sort keys %__devs ) { foreach my $d (sort keys %__devs ) {
@@ -255,7 +269,11 @@ FHEMRENDERER_Get($@)
} else { } else {
return "\"get FHEMRENDERER\" needs either none, 1(pos) or 3-5 arguments ([file-name] device type logfile [pos=zoom=XX&off=YYY])"; return "\"get FHEMRENDERER\" needs either none, 1(pos) or 3-5 arguments ([file-name] device type logfile [pos=zoom=XX&off=YYY])";
} }
if (not defined $pid) {
return $ret; return $ret;
} else {
exit(0);
}
} }
##################### #####################

View File

@@ -47,12 +47,15 @@ The FHEMRENDERER uses attributes to control the behaviour:
room Unsorted room Unsorted
status off status off
tmpfile /tmp/ tmpfile /tmp/
multiprocess off
These attributes have the following meaning: These attributes have the following meaning:
plotmode, plotsize: Control gnuplot and the desired output plotmode, plotsize: Control gnuplot and the desired output
refresh: type HH:MM:SS, is the time-interval in which the re-rendering is done 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 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 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 ! 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. See WebLink for more details on how to define.
@@ -88,6 +91,7 @@ DEFINE
room Unsorted room Unsorted
status off status off
tmpfile /tmp/ tmpfile /tmp/
multiprocess off
NOTE: The Logfile will report (with LogLevel 2) that the FHEMRENDERER has been defined. 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) refresh Timer-Interval for rerendering (HH:MM:SS)
status Status of the Timer (off/on) status Status of the Timer (off/on)
tmpfile Path and prefix of for the rendered graphics (e.g. /tmp/) tmpfile Path and prefix of for the rendered graphics (e.g. /tmp/)
multiprocess on / off