| Conditions | 9 |
| Paths | 20 |
| Total Lines | 67 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 70 | } |
||
| 71 | |||
| 72 | function analyze_nvidia() { |
||
| 73 | $hosts_total = 0; // number of hosts 6.2 or better |
||
| 74 | $hosts_gpu = 0; // number with an nvidia gpu |
||
| 75 | $rac_total =0; |
||
| 76 | $rac_gpu = 0; |
||
| 77 | $linux_total = 0; |
||
| 78 | $linux_gpus = 0; |
||
| 79 | $windows_total = 0; |
||
| 80 | $windows_gpus = 0; |
||
| 81 | $model = array(); // name -> count |
||
| 82 | $ram = array(); // size -> count |
||
| 83 | $driver = array(); // vers -> count |
||
| 84 | $ngpus = array(); // ngpus -> count |
||
| 85 | |||
| 86 | $hosts = BoincHost::enum("expavg_credit > 10 and serialnum<>''"); |
||
| 87 | foreach($hosts as $host) { |
||
| 88 | $boinc_vers = parse_vers($host->serialnum); |
||
| 89 | if (!$boinc_vers) continue; |
||
| 90 | if ($boinc_vers->major < 6) continue; |
||
| 91 | $is_linux = false; |
||
| 92 | if (strstr($host->os_name, "Linux")) { |
||
| 93 | $linux_total++; |
||
| 94 | $is_linux = true; |
||
| 95 | } else if (strstr($host->os_name, "Windows")) { |
||
| 96 | $windows_total++; |
||
| 97 | } else { |
||
| 98 | continue; |
||
| 99 | } |
||
| 100 | $hosts_total++; |
||
| 101 | $rac_total += $host->expavg_credit; |
||
| 102 | $gpu = parse_cuda($host->serialnum); |
||
| 103 | if (!$gpu) { |
||
| 104 | continue; |
||
| 105 | } |
||
| 106 | $hosts_gpu++; |
||
| 107 | $rac_gpu += $host->expavg_credit; |
||
| 108 | if ($is_linux) { |
||
| 109 | $linux_gpus++; |
||
| 110 | } else { |
||
| 111 | $windows_gpus++; |
||
| 112 | } |
||
| 113 | inc($model, $gpu->model); |
||
| 114 | inc($ram, $gpu->ram); |
||
| 115 | inc($driver, $gpu->driver); |
||
| 116 | inc($ngpus, $gpu->ngpus); |
||
| 117 | } |
||
| 118 | |||
| 119 | $pct = 100*($hosts_gpu/$hosts_total); |
||
| 120 | echo "ntotal: $hosts_total ngpus: $hosts_gpu ($pct %)\n"; |
||
| 121 | $pct = 100*($windows_gpus/$windows_total); |
||
| 122 | echo "Windows: total $windows_total gpus $windows_gpus ($pct %)\n"; |
||
| 123 | $pct = 100*($linux_gpus/$linux_total); |
||
| 124 | echo "Linux: total $linux_total gpus $linux_gpus ($pct %)\n"; |
||
| 125 | |||
| 126 | $rac_non_gpu = $rac_total - $rac_gpu; |
||
| 127 | $hosts_non_gpu = $hosts_total - $hosts_gpu; |
||
| 128 | $a = $rac_gpu/$hosts_gpu; |
||
| 129 | $b = $rac_non_gpu/$hosts_non_gpu; |
||
| 130 | echo "Avg RAC: GPU: $a non-GPU: $b\n"; |
||
| 131 | |||
| 132 | arsort($model); |
||
| 133 | foreach($model as $m=>$c) { |
||
| 134 | echo "$m $c\n"; |
||
| 135 | } |
||
| 136 | print_r($ram); |
||
| 137 | print_r($driver); |
||
| 165 |