class_TimeTools.inc.php 8.43 KB
<?php
/**
 * @file	TimeTools.inc.php
 * @category freeSN
 * @mailto	code [at] netz.coop
 * @version 0.4.200901
 * @link http://netz.coop
 * 
 *  @copyright Copyright by netz.coop e.G. 2015
 *  
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

class TimeTools {

	public static   $highestMTextID;
	public static   $lastendtime;
	public static   $startime;
	public static   $timepassedsincelasttest;

	public static   $totaltests;
	public static   $numberOfTests;

	public static   $DBtotaltests;
	public static   $DBnumberOfTests;

	public static   $RegExptotaltests;
	public static   $RegExpnumberOfTests;

	public static   $Xmltotaltests;
	public static   $XmlnumberOfTests;
	public static   $DBFails;
	public static   $RegExpFails;
	public static   $XmlFails;

	public static   $totaltime;
	public static   $varlastMtextID;
	public static   $startmemorypeak;
	public static   $startmemory;
	public static   $endmemorypeak;
	public static   $endmemory;
	public static   $memfree;
	public static   $array_allert_tests = array();

	public static function fnc_startTime() {
		self::$startime = time();
		self::$startmemorypeak=memory_get_peak_usage  ( );
		self::$startmemory=memory_get_usage  ( );
	}

	public static function fnc_endTime($param_numberOfTestspassed, $param_testcase=array('0'=>'DB','1'=>true), $param_testInput,$param_fail=false,$param_rtn,$param_wich =null) {
		if(!is_array($param_rtn)) {
			$param_rtn = array();
			$param_rtn['cur']['MCase'] = $param_wich;
		}
                if(!isset($param_rtn['cur']['BC'])){
                    $param_rtn['cur']['BC']='-';
                }
		self::$highestMTextID =$param_testInput['MTextID']; {
			self::$totaltests = self::$totaltests +$param_numberOfTestspassed;
			self::$numberOfTests =self::$numberOfTests+$param_numberOfTestspassed;
                        if(key_exists('0', $param_testcase)){
                            if($param_testcase['0']=='DB') {
				self::$DBtotaltests = self::$DBtotaltests +$param_numberOfTestspassed;
				self::$DBnumberOfTests =self::$DBnumberOfTests+$param_numberOfTestspassed;
				if($param_testcase['1']==='Failed') {
					self::$DBFails='Failed';
				}
                            }else if($param_testcase['0']=='RegExp') {
                                    self::$RegExptotaltests = self::$RegExptotaltests +$param_numberOfTestspassed;
                                    self::$RegExpnumberOfTests =self::$RegExpnumberOfTests+$param_numberOfTestspassed;
                                    if($param_testcase['1']==='Failed') {
                                            self::$RegExpFails='Failed';
                                    }
                            }else if($param_testcase['0']=='Xml') {
                                    self::$Xmltotaltests = self::$Xmltotaltests +$param_numberOfTestspassed;
                                    self::$XmlnumberOfTests =self::$XmlnumberOfTests+$param_numberOfTestspassed;
                                    if($param_testcase['1']==='Failed') {
                                            self::$XmlFails='Failed';
                                    }
                            }
                        }
			
		}
		$endtime = time();
		if(!isset(self::$lastendtime) ) {
			$var_seconds = $endtime -self::$startime;
		}else {
			$var_seconds = $endtime - self::$lastendtime;
		}
		$timepassedtotal = getdate( $endtime - self::$startime );
		if(!isset(self::$lastendtime)) {
			self::$lastendtime = $endtime;
		}else {
			self::$timepassedsincelasttest = getdate($endtime - self::$lastendtime);
			self::$lastendtime =$endtime;
		}
		self::$totaltime = $timepassedtotal;
		self::$endmemorypeak=memory_get_peak_usage  (  );
		self::$endmemory=memory_get_usage  ( );
		$array_time_warn= STMANAGEData::getGenCfgSTStd('0');
		if($array_time_warn['timetools']['notice'] > $var_seconds) {
                    if(!key_exists('BC', $param_rtn['cur'])){
                        $param_rtn['cur']['BC']='';
                    }
//                    D::show($param_rtn,'',1,1);
			STMANAGEData::setAllTests('<b>'.'TEST '. $param_rtn['cur']['MCase']. '=>'.$param_rtn['cur']['BC'].': '.$param_testInput['MTextID'].' '.$param_rtn['cur']['comment']." ==> Time passed :<font style=\"color:red\"> ". $timepassedtotal["minutes"]. " min " .$timepassedtotal["seconds"]. " sec" . "  </font><font style=\"color:purple\">|#|</font> Number of Tests: <font style=\"color:red\">". $param_numberOfTestspassed .'</font> Memory: <font style=\"color:red\">"' . self::$endmemory .'" </font> Memory Peak: <font style=\"color:red\">"' . self::$endmemorypeak .' time for Testobject: '.$var_seconds.' s " </font></b>');
		}else if($array_time_warn['timetools']['warn'] > $var_seconds) {
			STMANAGEData::setAllTests('<b '."<bg style=\"color:orange\"><font style=\"color:orange\">".$var_seconds.' sec </bg> </font> TEST '. $param_rtn['cur']['MCase']. '=>'.$param_rtn['cur']['BC'].': '.$param_testInput['MTextID'].' '.$param_rtn['cur']['comment']." ==> Time passed :<font style=\"color:red\"> ". $timepassedtotal["minutes"]. " min " .$timepassedtotal["seconds"]. " sec" . "  </font><font style=\"color:purple\">|#|</font> Number of Tests: <font style=\"color:red\">". $param_numberOfTestspassed .'</font> Memory: <font style=\"color:red\">"' . self::$endmemory .'" </font> Memory Peak: <font style=\"color:red\">"' . self::$endmemorypeak .' time for Testobject: '.$var_seconds.' s " </font></b>');
		}else if($array_time_warn['timetools']['alert'] > $var_seconds) {
			STMANAGEData::setAllTests('<b '."<bg style=\"color:purple\"><font style=\"color:purple\">".$var_seconds.' sec </bg> </font> TEST '. $param_rtn['cur']['MCase']. '=>'.$param_rtn['cur']['BC'].': '.$param_testInput['MTextID'].' '.$param_rtn['cur']['comment']." ==> Time passed :<font style=\"color:red\"> ". $timepassedtotal["minutes"]. " min " .$timepassedtotal["seconds"]. " sec" . "  </font><font style=\"color:purple\">|#|</font> Number of Tests: <font style=\"color:red\">". $param_numberOfTestspassed .'</font> Memory: <font style=\"color:red\">"' . self::$endmemory .'" </font> Memory Peak: <font style=\"color:red\">"' . self::$endmemorypeak .' time for Testobject: '.$var_seconds.' s " </font></b>');
		}else {
			STMANAGEData::setAllTests('<b '."<bg style=\"color:red\"><font style=\"color:red\">".$var_seconds.' sec </bg></font> TEST '. $param_rtn['cur']['MCase']. '=>'.$param_rtn['cur']['BC'].': '.$param_testInput['MTextID'].' '.$param_rtn['cur']['comment']." ==> Time passed :<font style=\"color:purple\"> ". $timepassedtotal["minutes"]. " min " .$timepassedtotal["seconds"]. " sec" . "  </font><font style=\"color:purple\">|#|</font> Number of Tests: <font style=\"color:purple\">". $param_numberOfTestspassed .'</font> Memory: <font style=\"color:red\">"' . self::$endmemory .'" </font> Memory Peak: <font style=\"color:red\">"' . self::$endmemorypeak .' time for Testobject: '.$var_seconds.' s " </font></b>');
			$string = '<b '."<bg style=\"color:red\"><font style=\"color:red\">".$var_seconds.' sec </bg></font> TEST '. $param_rtn['cur']['MCase']. '=>'.$param_rtn['cur']['BC'].': '.$param_testInput['MTextID']." ==> Time passed :<font style=\"color:purple\"> ". $timepassedtotal["minutes"]. " min " .$timepassedtotal["seconds"]. " sec" . "  </font><font style=\"color:purple\">|#|</font> Number of Tests: <font style=\"color:purple\">". $param_numberOfTestspassed .'</font> Memory: <font style=\"color:red\">"' . self::$endmemory .'" </font> Memory Peak: <font style=\"color:red\">"' . self::$endmemorypeak .' time for Testobject: '.$var_seconds.' s " </font></b>';
			self::$array_allert_tests[]= $string;
		}
		self::$varlastMtextID = $param_testInput['MTextID'];
	}

	public static function  showMEM($param_string) {
		// 		$varString = 'free -mo |grep Mem | awk \'{ print "Total: " $2 "M Used: " $3 "M" }\'';
		// 		self::$memfree = system($varString);
		// 		STMANAGEData::setAllTests('<b>'.$param_string.'  RAM: <font style=\"color:red\">"' .self::$memfree .'" </font> </b>');
	}
}
?>