1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
|
#ifndef JobRecord_h
#define JobRecord_h
/******************************************************************************
*
* Copyright (C) 2002 Hugo PEREIRA <mailto: hugo.pereira@free.fr>
*
* This 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 2 of the License, or (at your option) any later
* version.
*
* This software 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/>.
*
*******************************************************************************/
#include "Job.h"
#include "XmlOptions.h"
#include <QList>
//* keep track of job memory and usage
class JobRecord: public Counter
{
public:
//* list of records
using List = QList<JobRecord>;
//* constructor
JobRecord( void ):
Counter( "JobRecord" ),
records_(
XmlOptions::get().get<int>( "SAMPLES" ),
XmlOptions::get().get<int>( "RECORD_LENGTH" ) )
{}
//* constructor
JobRecord( const Job& job ):
Counter( "JobRecord" ),
job_( job ),
records_(
XmlOptions::get().get<int>( "SAMPLES" ),
XmlOptions::get().get<int>( "RECORD_LENGTH" ) )
{ updateJob( job ); }
//* lower than operator
bool operator < ( const JobRecord& other ) const
{ return id() < other.id(); }
//* equal to operator
bool operator == ( const JobRecord& other ) const
{ return id() == other.id(); }
//* storage
class Record: public Counter
{
public:
//* empty constructor
Record( void ):
Counter( "Record" ),
virtualMemory_(0),
residentMemory_(0),
sharedMemory_(0),
cpu_(0),
memory_(0)
{}
//* constructo from job
Record( const Job& job );
//* sum operator
Record& operator += ( const Record& record )
{
virtualMemory_ += record.virtualMemory_;
residentMemory_ += record.residentMemory_;
sharedMemory_ += record.sharedMemory_;
cpu_ += record.cpu_;
memory_ += record.memory_;
return *this;
}
//* divide
Record divide( const int& value )
{
Q_ASSERT( value > 0 );
Record out( *this );
out.virtualMemory_ /= value;
out.residentMemory_ /= value;
out.sharedMemory_ /= value;
out.cpu_ /= value;
out.memory_ /= value;
return out;
}
//* virtual memory
int virtualMemory_;
//* resident memory
int residentMemory_;
//* shared memory
int sharedMemory_;
//* cpu (%)
double cpu_;
//* mem (%)
double memory_;
//* streamer
friend QTextStream& operator << ( QTextStream& out, const Record& record )
{
out << record.cpu_ << " " << record.memory_;
return out;
}
};
//* Record List
using RecordList = QList<Record>;
//* data samples storage
class Samples: public Counter
{
public:
//* construtor
Samples( int sampleSize = 0, int length = 0 ):
Counter( "JobRecord::Samples" ),
sampleSize_( sampleSize ),
maxLength_( length )
{}
//* set sample size
void setSampleSize( const int& sampleSize );
//* set data point size
void setMaxLength( const int length );
//* max length
int maxLength( void ) const
{ return maxLength_; }
//* retrieve data
const RecordList& records( void ) const
{ return recordList_; }
//* add a data point
void add( const Record& record );
private:
//* list of measurements
RecordList sampleList_;
//* list of differences
RecordList recordList_;
//* sample size
int sampleSize_ = 0;
//* number of data point to store
int maxLength_ = 0;
};
//*@name accessor
//@{
//* id
int id( void ) const
{ return job_.id(); }
//* current record
const Record& current( void ) const
{ return current_; }
//* max record
const Record& max( void ) const
{ return max_; }
//* get records
const Samples& samples( void ) const
{ return records_; }
//@}
//*@name modifier
//@{
//* update statistics from job informations
bool updateJob( const Job& job );
//* get records
Samples& samples( void )
{ return records_; }
//@}
//* used to select with Id matching an integer
class SameIdFTor
{
public:
//* constructor
SameIdFTor( const int& id ):
id_( id )
{}
//* predicate
bool operator() (const JobRecord& job ) const
{ return job.id() == id_; }
private:
//* field index
int id_;
};
private:
//* job Id
Job job_;
//* current record
Record current_;
//* max
Record max_;
//* records
Samples records_;
};
#endif
|