1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
19 package compbio.engine.cluster.drmaa;
\r
21 import java.util.Date;
\r
22 import java.util.Map;
\r
24 import org.ggf.drmaa.DrmaaException;
\r
25 import org.ggf.drmaa.JobInfo;
\r
27 import compbio.util.Util;
\r
29 public class StatisticManager {
\r
31 private final Map<String, String> usage;
\r
32 final JobInfo jobinfo;
\r
33 private static String newLine = "\n";
\r
35 public StatisticManager(JobInfo status) throws DrmaaException {
\r
36 assert status != null;
\r
37 // TODO this is potentially unsafe may need reviewing
\r
38 this.jobinfo = status;
\r
39 Map<String, String> resourcesUsage = status.getResourceUsage();
\r
40 this.usage = resourcesUsage;
\r
43 public String getJobId() throws DrmaaException {
\r
44 return jobinfo.getJobId();
\r
47 public boolean hasExited() throws DrmaaException {
\r
48 return jobinfo.hasExited();
\r
51 public boolean hasSignaled() throws DrmaaException {
\r
52 return jobinfo.hasSignaled();
\r
55 public boolean hasDump() throws DrmaaException {
\r
56 return jobinfo.hasCoreDump();
\r
59 public String termSignal() throws DrmaaException {
\r
60 return jobinfo.getTerminatingSignal();
\r
63 public boolean wasAborted() throws DrmaaException {
\r
64 return jobinfo.wasAborted();
\r
67 public String getSubmissionTime() {
\r
68 return usage.get(submission_time);
\r
71 public String getVMem() {
\r
72 return usage.get(vmem);
\r
75 public String getMaxVMem() {
\r
76 return usage.get(maxvmem);
\r
79 public String getUsedSysTime() {
\r
80 return usage.get(ru_stime);
\r
83 public String getUsedUserTime() {
\r
84 return usage.get(ru_utime);
\r
87 public String getCalculationTime() {
\r
88 return usage.get(ru_wallclock);
\r
91 public String getEndTime() {
\r
92 return usage.get(end_time);
\r
95 public String getStartTime() {
\r
96 return usage.get(start_time);
\r
99 public String getIOWait() {
\r
100 return usage.get(iow);
\r
103 public String getCPUUsageTime() {
\r
104 return usage.get(cpu);
\r
107 public String getDataTransfered() {
\r
108 return usage.get(io);
\r
111 public String getJobPriority() {
\r
112 return usage.get(priority);
\r
115 public String getExitStatus() {
\r
116 return usage.get(exit_status);
\r
119 public String getAllStats() throws DrmaaException {
\r
121 String stats = "JobID: " + getJobId() + newLine;
\r
122 stats += getExecutionStat() + newLine;
\r
123 stats += getTimeStat() + newLine;
\r
124 stats += getCPUTimeStat() + newLine;
\r
125 stats += getMemoryStat() + newLine;
\r
130 public String getExecutionStat() throws DrmaaException {
\r
131 String stats = "Priority:" + getJobPriority() + newLine;
\r
132 /* report how job finished */
\r
133 if (wasAborted()) {
\r
134 stats += "job \"" + getJobId() + "\" was aborted (never ran)"
\r
136 } else if (hasExited()) {
\r
137 stats += "job \"" + getJobId()
\r
138 + "\" finished regularly with exit status "
\r
139 + getExitStatus() + newLine;
\r
140 } else if (hasSignaled()) {
\r
141 stats += "job \"" + getJobId() + "\" finished due to signal "
\r
142 + termSignal() + newLine;
\r
144 stats += "job \"" + getJobId()
\r
145 + "\" finished with unclear conditions" + newLine;
\r
147 stats += "Has Core Dump: " + hasDump() + newLine;
\r
151 public String getMemoryStat() {
\r
152 String stats = "Data transfered: " + getDataTransfered() + newLine;
\r
153 stats += "IO wait: " + getIOWait() + newLine;
\r
154 stats += "Max Virtual Memory: " + getMaxVMem() + newLine;
\r
155 stats += "Virtual Memory: " + getVMem() + newLine;
\r
159 public String getCPUTimeStat() {
\r
160 String stats = "CPU time (s): " + getCPUUsageTime() + newLine;
\r
161 stats += "Sys time (s): " + getUsedSysTime() + newLine;
\r
162 stats += "User time (s): " + getUsedUserTime() + newLine;
\r
166 public String getTimeStat() {
\r
167 String stats = "Submission time: " + formatTime(getSubmissionTime())
\r
169 stats += "Calculation time (s): " + getCalculationTime() + newLine;
\r
170 stats += "Start time: " + formatTime(getStartTime()) + newLine;
\r
171 stats += "End time: " + formatTime(getEndTime()) + newLine;
\r
175 public Map<String, String> getRawUsage() {
\r
180 public String toString() {
\r
183 stat = getAllStats();
\r
184 } catch (DrmaaException e) {
\r
185 // Should not happen
\r
186 throw new RuntimeException("exception during toString execution! ",
\r
193 * Convert grid engine time format End time: 1250701672.0000 to a readable
\r
194 * time representation as defined in Util.dataf
\r
196 String formatTime(String time) {
\r
197 int dotIdx = time.indexOf(".");
\r
199 // get rid of .0000 part
\r
200 time = time.substring(0, dotIdx);
\r
201 Date d = new Date();
\r
202 d.setTime(Long.parseLong(time + "000"));
\r
203 time = Util.datef.format(d);
\r
204 } // else do not know how to format
\r
209 * see man 5 accounting on sun grid engine installed workstation see also
\r
213 String signal = "signal";
\r
214 String submission_time = "submission_time"; // Submission time (GMT unix
\r
216 String vmem = "vmem";
\r
217 String maxvmem = "maxvmem"; // The maximum vmem size in bytes.
\r
218 String ru_stime = "ru_stime"; // system time used
\r
219 String ru_utime = "ru_utime"; // user time used
\r
220 String ru_wallclock = "ru_wallclock"; // Difference between end_time and
\r
222 String end_time = "end_time"; // End time (GMT unix time stamp).
\r
223 String start_time = "start_time"; // Start time (GMT unix time stamp).
\r
225 String iow = "iow"; // The io wait time in seconds.
\r
226 String cpu = "cpu"; // The cpu time usage in seconds.
\r
227 String io = "io"; // The amount of data transferred in input/output
\r
230 String priority = "priority";
\r
232 * Priority value assigned to the job corresponding to the priority
\r
233 * parameter in the queue configuration
\r
235 String exit_status = "exit_status";
\r
237 * Exit status of the job script (or Sun Grid Engine specific status in case
\r
238 * of certain error conditions). The exit status is determined by following
\r
239 * the normal shell conventions. If the command terminates normally the
\r
240 * value of the command is its exit status. However, in the case that the
\r
241 * command exits abnormally, a value of 0200 (octal), 128 (decimal) is added
\r
242 * to the value of the command to make up the exit status. For example: If a
\r
243 * job dies through signal 9 (SIGKILL) then the exit status becomes 128 + 9
\r
247 // Could not find a discription for these
\r
248 String acct_cpu = "acct_cpu";
\r
249 String acct_mem = "acct_mem";
\r
250 String acct_iow = "acct_iow";
\r
251 String acct_io = "acct_io";
\r
252 String acct_maxvmem = "acct_maxvmem";
\r
255 * Appears to be not reported String ru_idrss=0.000; // integral unshared
\r
256 * data size String ru_inblock=0.000; String ru_ismrss=0.0000 String
\r
257 * ru_majflt=0.0000 String ru_msgrcv=0.0000 String ru_isrss="ru_isrss" //
\r
258 * integral unshared stack size String ru_nswap=0.0000 String
\r
259 * ru_oublock=0.0000 String ru_msgsnd=0.0000 String ru_nsignals=0.0000
\r
260 * String ru_maxrss="ru_maxrss"; // maximum resident set size // Too
\r
261 * technical to be useful String ru_nivcsw=524.0000 // involuntary context
\r
262 * switches String ru_minflt=9668.0000 // page reclaims String
\r
263 * ru_nvcsw=97.0000 // voluntary context switches String
\r
264 * ru_ixrss="ru_ixrss"; // integral shared memory size String mem="mem"; //
\r
265 * The integral memory usage in Gbytes cpu seconds.
\r