Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Worker\Bin\Status Class Reference
Inheritance diagram for Hoa\Worker\Bin\Status:

Public Member Functions

 main ()
 
 usage ()
 
- Public Member Functions inherited from Hoa\Console\Dispatcher\Kit
 __construct (Router $router, Dispatcher $dispatcher, View\Viewable $view=null)
 
 getOption (&$optionValue, $short=null)
 
 setOptions (Array $options)
 
 makeUsageOptionsList (Array $definitions=[])
 
 resolveOptionAmbiguity (Array $solutions)
 
 status ($text, $status)
 
 readLine ($prefix=null)
 
 readPassword ($prefix=null)
 
- Public Member Functions inherited from Hoa\Dispatcher\Kit
 __construct (Router $router, Dispatcher $dispatcher, View\Viewable $view=null)
 
 construct ()
 

Protected Attributes

 $options
 
- Protected Attributes inherited from Hoa\Console\Dispatcher\Kit
 $options = null
 
 $_options = null
 

Additional Inherited Members

- Public Attributes inherited from Hoa\Console\Dispatcher\Kit
 $parser = null
 
- Public Attributes inherited from Hoa\Dispatcher\Kit
 $router = null
 
 $dispatcher = null
 
 $view = null
 
 $data = null
 

Detailed Description

Class .

Status all workers.

Definition at line 51 of file Status.php.

Member Function Documentation

Hoa\Worker\Bin\Status::main ( )

The entry method.

Returns
void

Definition at line 71 of file Status.php.

72  {
73  $run = 'hoa://Data/Variable/Run';
74 
75  while (false !== $c = $this->getOption($v)) {
76  switch ($c) {
77  case 'r':
78  $run = $v;
79 
80  break;
81 
82  case 'h':
83  case '?':
84  return $this->usage();
85 
86  break;
87 
88  case '__ambiguous':
89  $this->resolveOptionAmbiguity($v);
90 
91  break;
92  }
93  }
94 
95  $run = resolve($run);
96  Core::getInstance()->initialize([
97  'protocol.Data/Variable/Run' => "\r" . $run . DS
98  ]);
99  $outi = [['ID', 'PID', 'Socket', 'Uptime', 'Messages', 'Last']];
100  $outm = [];
101  $now = new \DateTime();
102  $t = 0;
103 
105  'Shared worker informations',
106  'foreground(yellow)'
107  ), "\n\n";
108 
109  foreach (glob($run . DS . '*.wid') as $wid) {
110  $worker = new Worker\Shared(substr(basename($wid), 0, -4));
111  $infos = $worker->getInformations();
112  $uptime = new \DateTime();
113  $uptime->setTimestamp((int) $infos['start']);
114  $last = new \DateTime();
115  $last->setTimestamp((int) $infos['last_message']);
116 
117  $outi[] = [
118  $infos['id'],
119  $infos['pid'],
120  $infos['socket'],
121  $uptime->diff($now)->format('%ad%H:%I:%S'),
122  $infos['messages'],
123  0 === $infos['last_message']
124  ? '-'
125  : $last->diff($now)->format('%ad%H:%I:%S')
126  ];
127 
128  $outm[] = $infos;
129 
130  ++$t;
131  }
132 
133  echo Console\Chrome\Text::columnize($outi, 0, 1, '|'), "\n";
134 
135  $max_id = 0;
136  $max_peak = 0;
137 
138  foreach ($outm as $m) {
139  $max_id < strlen($m['id'])
140  and $max_id = strlen($m['id']);
141 
142  $max_peak < $m['memory_peak']
143  and $max_peak = $m['memory_peak'];
144  }
145 
146  foreach ($outm as $m) {
147  $outmm = str_pad($m['id'], $max_id) . ' ';
148  $max = (int) (($m['memory_peak'] * 39) / $max_peak);
149  $peak = (int) (($m['memory_allocated_peak'] * 40) / $max_peak);
150  $memory = (int) (($m['memory_allocated'] * 40) / $max_peak);
151 
152  for ($i = 0; $i < $memory - 1; ++$i) {
154  '|',
155  'foreground(green)'
156  );
157  }
158 
159  for (; $i < $peak; ++$i) {
161  '|',
162  'foreground(yellow)'
163  );
164  }
165 
166  for (; $i < $max; ++$i) {
167  $outmm .= ' ';
168  }
169 
171  '|',
172  'foreground(red)'
173  );
174 
175  for (++$i; $i < 40; ++$i) {
176  $outmm .= ' ';
177  }
178 
179  $outmm .=
180  ' ' .
182  number_format($m['memory_allocated'] / 1024) . 'Kb',
183  'foreground(green)'
184  ) . ' ' .
186  number_format($m['memory_allocated_peak'] / 1024) . 'Kb',
187  'foreground(yellow)'
188  ) . ' ' .
190  number_format($m['memory_peak'] / 1024) . 'Kb',
191  'foreground(red)'
192  );
193 
194  echo $outmm . "\n";
195  }
196 
197  echo
198  "\n", $t,
199  ' shared worker', ($t > 1 ? 's are' : ' is'), ' running.', "\n";
200 
201  return;
202  }
static getInstance()
Definition: Core.php:193
static columnize(Array $line, $alignement=self::ALIGN_LEFT, $horizontalPadding=2, $verticalPadding=0, $separator=null)
Definition: Text.php:126
getOption(&$optionValue, $short=null)
Definition: Kit.php:104
resolveOptionAmbiguity(Array $solutions)
Definition: Kit.php:190
static colorize($text, $attributesBefore, $attributesAfter= 'normal')
Definition: Text.php:83

Here is the call graph for this function:

Hoa\Worker\Bin\Status::usage ( )

The command usage.

Returns
void

Definition at line 209 of file Status.php.

210  {
211  echo
212  'Usage : worker:status <options>', "\n",
213  'Options :', "\n",
214  $this->makeUsageOptionsList([
215  'run' => 'Define hoa://Data/Variable/Run/ path.',
216  'help' => 'This help.'
217  ]), "\n",
218  'Legend: ',
220  'allocated',
221  'foreground(green)'
222  ), ', ',
224  'allocated peak',
225  'foreground(yellow)'
226  ), ', ',
228  'peak',
229  'foreground(red)'
230  ), '.', "\n";
231 
232  return;
233  }
makeUsageOptionsList(Array $definitions=[])
Definition: Kit.php:149
static colorize($text, $attributesBefore, $attributesAfter= 'normal')
Definition: Text.php:83

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

Hoa\Worker\Bin\Status::$options
protected
Initial value:

Definition at line 58 of file Status.php.


The documentation for this class was generated from the following file: