Debian Codegraph @

w4/status.c

raw
1 /* File: status.c
2 * Author: Jean Thierry-Mieg ([email protected])
3 * Copyright (C) J Thierry-Mieg and R Durbin, 1991
4 * -------------------------------------------------------------------
5 * Acedb is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
19 * -------------------------------------------------------------------
20 * This file is part of the ACEDB genome database package, written by
21 * Richard Durbin (MRC LMB, UK) [email protected], and
22 * Jean Thierry-Mieg (CRBM du CNRS, France) [email protected]
23 *
24 * Description: get status of program memory and acedb kernel
25 * Exported functions:
26 * tStatus - output status info freeOut
27 * HISTORY:
28 * Last edited: Feb 5 12:29 2003 (edgrif)
29 * * May 12 13:27 1999 (fw): moved out all code to statusdisp.c
30 * moved all non-graphical status code here
31 * * Dec 3 14:43 1998 (edgrif): Change calls to new interface to aceversion.
32 * Created: Fri Nov 29 12:20:30 1991 (mieg)
33 * CVS info: $Id: status.c,v 1.37 2003/02/05 13:25:50 edgrif Exp $
34 *-------------------------------------------------------------------
35 */
36
37 #include <wh/acedb.h>
38 #include <wh/aceio.h>
39 #include <wh/lex.h> /* for lexavail */
40 #include <wh/disk.h> /* for diskavail */
41 #include <wh/block.h> /* for blockavail() */
42 #include <wh/bs.h> /* for BSstatus BTstatus */
43 #include <wh/session.h> /* for isWriteAccess */
44 #include <wh/dbpath.h>
45 #include <wh/bindex.h> /* for bIndexVersion */
46 #include <wh/a.h> /* for aStatus */
47 #include <wh/status.h>
48
49 /*************************************************************/
50
51 typedef enum _STATUS_LINE_TYPE {LINE_SUBHEAD,
52 LINE_START, LINE_CONT, LINE_END} STATUS_LINE_TYPE ;
53
54
55 enum {STATUS_TITLE_INDENT = 1, STATUS_MIN_INDENT = 5, STATUS_JUSTIFY = 20} ;
56
57 /* For holding mapping of cmdline strings to option flags. */
58 typedef struct _StatusRequest
59 {
60 StatusType type ;
61 char *string ;
62 } StatusRequest ;
63
64
65 /*************************************************************/
66
67 static void doTitle(ACEOUT fo, char *text) ;
68 static void doSimpleLine(ACEOUT fo, char *text) ;
69 static void doSingleLine(ACEOUT fo, char *label, char *value) ;
70 static void doLine(ACEOUT fo, char *label, char *value, STATUS_LINE_TYPE type) ;
71 static void myText (ACEOUT fo, char *cp, int indent, BOOL startline, BOOL endline) ;
72
73 /*************************************************************/
74
75 /* Keep in step with StatusType and STATUS_OPTIONS_STRING in status.h */
76 /* */
77 static StatusRequest status_types_G[] =
78 {
79 {STATUS_CODE, "-code"},
80 {STATUS_DATABASE, "-database"},
81 {STATUS_DISK, "-disk"},
82 {STATUS_LEXIQUES, "-lexiques"},
83 {STATUS_HASHES, "-hash"},
84 {STATUS_INDEXING, "-index"},
85 {STATUS_CACHE, "-cache"},
86 {STATUS_CACHE1, "-cache1"},
87 {STATUS_CACHE2, "-cache2"},
88 {STATUS_ARRAYS, "-array"},
89 {STATUS_MEMORY, "-memory"},
90 #ifdef ACEMBLY
91 {STATUS_DNA, "-dna"},
92 #endif
93 {STATUS_ALL, "-all"}
94 } ;
95
96 static int status_num_G = UtArraySize(status_types_G) ;
97
98
99 /*************************************************************/
100
101 /* Print all possible stats. */
102 /* */
103 void tStatus(ACEOUT fo)
104 {
105 tStatusSelect(fo, STATUS_ALL) ;
106
107 return ;
108 }
109
110 /* Check a given cmdline flag of form "-XXXX" and if its recognised then set */
111 /* the supplied flag and return TRUE, else return FALSE. */
112 /* */
113 BOOL tStatusSetOption(char *cmdline_option, StatusType *flag)
114 {
115 BOOL result = FALSE ;
116 int i ;
117
118 for (i = 0 ; i < status_num_G && result == FALSE ; i++)
119 {
120 if (strcmp(cmdline_option, status_types_G[i].string) == 0)
121 {
122 result = TRUE ;
123 *flag |= status_types_G[i].type ;
124 }
125 }
126
127 return result ;
128 }
129
130 /* Print a selected subset of stats as specified by the value of "flag" */
131 /* */
132 void tStatusSelect(ACEOUT fo, StatusType flag)
133 {
134 char *db_name ;
135 char *main_window ;
136 char *last_save_time ;
137 extern int blockMax (void) ;
138 extern int NII, NIC, NWC, NWF, NWG; /* in lexsubs, hash statistics */
139 unsigned long keynum,keynum2, vocnum,vocspace,hspace,tspace ;
140 int
141 n,
142 dused, dfree, plus, minus,
143 bsused, bsalloc, btused, btalloc,
144 aUsed, aMade, aAlloc, aReal,
145 nmessalloc, messalloctot,
146 bused, bpinned, bfree, bmodif,bsmemory,
147 indexT, indexKb, indexV,
148 cacheused, cachel, cachek, cachemod,
149 ndread, ndwrite,nc1r,nc1w,ncc1r, ncc1w, naread,nawrite,nc2read,nc2write,nccr,nccw;
150 STORE_HANDLE handle = handleCreate();
151 #ifdef ACEMBLY
152 int dnaMade = 0, dnaTotal = 0 ;
153 monDnaReport (&dnaMade, &dnaTotal) ;
154 #endif
155
156 if (fo == NULL)
157 messcrash("Internal Logic Error: ACEOUT ptr to tStatus() was NULL") ;
158
159 if ((db_name = sessionDbName()) == NULL)
160 db_name = "<undefined>" ;
161 if ((main_window = sessionDBTitle()) == NULL)
162 main_window = "<undefined>" ;
163 last_save_time = sessionLastSaveTime() ;
164
165 ndwrite = 123 ; diskavail (&dfree,&dused, &plus, &minus,&ndread,&ndwrite) ;
166 lexavail (&vocnum,&keynum,&keynum2,&vocspace, &hspace,&tspace);
167 BSstatus (&bsused, &bsalloc, &n) ; bsmemory = n ;
168 BTstatus (&btused, &btalloc, &n) ; bsmemory += n ;
169 arrayStatus (&aMade, &aUsed, &aAlloc, &aReal) ;
170 aStatus (&naread, &nawrite) ;
171 nmessalloc = messAllocStatus (&messalloctot) ;
172 blockavail(&bused,&bpinned,&bfree,&bmodif) ;
173 indexV = bIndexStatus (&indexT, &indexKb) ;
174 blockStatus (&nc1r, &nc1w, &ncc1r, &ncc1w) ;
175 cacheStatus(&cacheused,&cachel,&cachek,&cachemod,&nc2read,&nc2write,&nccr,&nccw) ;
176
177 /* title and datestamp */
178 doSimpleLine(fo, "************************************************") ;
179 doSimpleLine(fo, messprintf("AceDB status at %s", timeShow(timeNow()))) ;
180 doSimpleLine(fo, "") ;
181
182 /* Info. about the acedb program itself. */
183 if ((flag & STATUS_ALL) || (flag & STATUS_CODE))
184 {
185 doTitle(fo, "Code") ;
186 doSingleLine(fo, "Program", messGetErrorProgram()) ;
187 doSingleLine(fo, "Version", aceGetVersionString()) ;
188 doSingleLine(fo, "Build", aceGetLinkDate()) ;
189 }
190
191 /* Database name/version info. */
192 if ((flag & STATUS_ALL) || (flag & STATUS_DATABASE))
193 {
194 doTitle(fo, "Database") ;
195 doSingleLine(fo, "Title", main_window) ;
196 doSingleLine(fo, "Name", db_name) ;
197 doSingleLine(fo, "Release", messprintf("%d_%d",
198 thisSession.mainDataRelease, thisSession.subDataRelease)) ;
199 doSingleLine(fo, "Directory", dbPathMakeFilName("", "", "", handle)) ;
200 doSingleLine(fo, "Session", messprintf("%d", thisSession.session)) ;
201 doSingleLine(fo, "User", getLogin(TRUE)) ;
202 doSingleLine(fo, "Last Save", last_save_time) ;
203 doSingleLine(fo, "Write Access", (isWriteAccess() ? "Yes" : "No" )) ;
204 doSingleLine(fo, "Global Address", messprintf("%d", thisSession.gAddress)) ;
205 }
206 /* Disk blocks. */
207 if ((flag & STATUS_ALL) || (flag & STATUS_DISK))
208 {
209 doTitle(fo, "Disk blocks") ;
210 doLine(fo, "Used", messprintf("%d", dused), LINE_START) ;
211 doLine(fo, "Available", messprintf("%d", dfree), LINE_END) ;
212 doLine(fo, "This Session", "", LINE_SUBHEAD) ;
213 doLine(fo, "allocated", messprintf("%d", plus), LINE_CONT) ;
214 doLine(fo, "freed", messprintf("%d", minus), LINE_END) ;
215 }
216
217 if ((flag & STATUS_ALL) || (flag & STATUS_LEXIQUES))
218 {
219 doTitle(fo, "Lexiques") ;
220 doLine(fo, "classes", messprintf("%lu", vocnum), LINE_START) ;
221 doLine(fo, "allocated (kb)", messprintf("%lu", tspace), LINE_END) ;
222
223 doLine(fo, "keys", messprintf("%lu", keynum), LINE_START) ;
224 doLine(fo, "keys in lex2", messprintf("%lu", keynum2), LINE_CONT) ;
225 doLine(fo, "names (kb)", messprintf("%lu", vocspace/1024), LINE_CONT) ;
226 doLine(fo, "hashing keys", messprintf("%lu", hspace), LINE_END) ;
227 }
228
229 if ((flag & STATUS_ALL) || (flag & STATUS_HASHES))
230 {
231 doTitle(fo, "Hashes") ;
232 doLine(fo, "nii", messprintf("%d", NII), LINE_START) ;
233 doLine(fo, "nic", messprintf("%d", NIC), LINE_CONT) ;
234 doLine(fo, "nwc", messprintf("%d", NWC), LINE_CONT) ;
235 doLine(fo, "nwf", messprintf("%d", NWF), LINE_CONT) ;
236 doLine(fo, "nwg", messprintf("%d", NWG), LINE_END) ;
237 }
238
239 if ((flag & STATUS_ALL) || (flag & STATUS_INDEXING))
240 {
241 doTitle(fo, "Indexing") ;
242 if (!indexV)
243 doSingleLine(fo, "Not Available", "Please read models "
244 "and avoid using code prior to 4_7)") ;
245 else
246 {
247 doLine(fo, "version", messprintf("%d", indexV), LINE_START) ;
248 doLine(fo, "tables", messprintf("%d", indexT), LINE_CONT) ;
249 doLine(fo, "kb", messprintf("%d", indexKb), LINE_END) ;
250 }
251 }
252
253 if ((flag & STATUS_ALL) || (flag & STATUS_CACHE1))
254 {
255 doTitle(fo, "Cache 1") ;
256 blockavail(&bused, &bpinned, &bfree, &bmodif) ;
257 doSingleLine(fo, "Size", messprintf("%d",blockMax())) ;
258 doLine(fo, "Current Blocks", "", LINE_SUBHEAD) ;
259 doLine(fo, "used", messprintf("%d", bused), LINE_CONT) ;
260 doLine(fo, "modified", messprintf("%d", bmodif), LINE_CONT) ;
261 doLine(fo, "locked", messprintf("%d", bpinned), LINE_CONT) ;
262 doLine(fo, "free", messprintf("%d", bfree), LINE_END) ;
263 doLine(fo, "Current Objects", "", LINE_SUBHEAD) ;
264 doLine(fo, "served", messprintf("%d", nc1r), LINE_CONT) ;
265 doLine(fo, "saved", messprintf("%d", nc1w), LINE_CONT) ;
266 doLine(fo, "read from disk", messprintf("%d", ncc1r), LINE_CONT) ;
267 doLine(fo, "saved to disk", messprintf("%d", ncc1w), LINE_END) ;
268 }
269
270
271 if ((flag & STATUS_ALL) || (flag & STATUS_CACHE2))
272 {
273 doTitle(fo, "Cache 2") ;
274 doLine(fo, "slots", messprintf("%d", cacheused), LINE_START) ;
275 doLine(fo, "allocated (kb)", messprintf("%d", bsmemory/1024), LINE_END) ;
276
277 doLine(fo, "Current content (objs)", "", LINE_SUBHEAD) ;
278 doLine(fo, "locked", messprintf("%d", cachel), LINE_CONT) ;
279 doLine(fo, "known", messprintf("%d", cachek), LINE_CONT) ;
280 doLine(fo, "modified", messprintf("%d", cachemod), LINE_END) ;
281
282 doLine(fo, "Object Usage", "", LINE_SUBHEAD) ;
283 doLine(fo, "served", messprintf("%d", nc2read), LINE_CONT) ;
284 doLine(fo, "saved", messprintf("%d", nc2write), LINE_CONT) ;
285 doLine(fo, "read from cache1", messprintf("%d", nccr), LINE_CONT) ;
286 doLine(fo, "saved to cache1", messprintf("%d", nccw), LINE_END) ;
287
288 doLine(fo, "BS memory cells", "", LINE_SUBHEAD) ;
289 doLine(fo, "used", messprintf("%d", bsused), LINE_CONT) ;
290 doLine(fo, "allocated", messprintf("%d", bsalloc), LINE_END) ;
291 doLine(fo, "BT memory cells", "", LINE_SUBHEAD) ;
292 doLine(fo, "used", messprintf("%d", btused), LINE_CONT) ;
293 doLine(fo, "allocated", messprintf("%d", btalloc), LINE_END) ;
294 }
295
296 if ((flag & STATUS_ALL) || (flag & STATUS_ARRAYS))
297 {
298 doTitle(fo, "Arrays (Including the lexiques)") ;
299 doLine(fo, "made", messprintf("%d", aMade), LINE_START) ;
300 doLine(fo, "current", messprintf("%d", aUsed), LINE_CONT) ;
301 doLine(fo, "allocated (kb)", messprintf("%d", aAlloc/1024), LINE_CONT) ;
302 doLine(fo, "used (kb)", messprintf("%d", aReal/1024), LINE_END) ;
303 }
304
305 #ifdef ACEMBLY
306 if ((flag & STATUS_ALL) || (flag & STATUS_DNA))
307 {
308 doTitle(fo, "Acembly DNA Cache") ;
309 doLine(fo, "arrays", messprintf("%d", dnaMade), LINE_START) ;
310 doLine(fo, "total (kb)", messprintf("%d", dnaTotal/1024), LINE_END) ;
311 }
312 #endif
313
314 if ((flag & STATUS_ALL) || (flag & STATUS_CACHE))
315 {
316 doTitle(fo, "Cache statistics: each layer serves the known objects or asks the lower layer") ;
317 doLine(fo, "Array", "", LINE_SUBHEAD) ;
318 doLine(fo, "read from cache1", messprintf("%d", naread), LINE_CONT) ;
319 doLine(fo, "saved to cache1", messprintf("%d", nawrite), LINE_END) ;
320
321 doLine(fo, "Cache2", "", LINE_SUBHEAD) ;
322 doLine(fo, "served", messprintf("%d", nc2read), LINE_CONT) ;
323 doLine(fo, "saved", messprintf("%d", nc2write), LINE_CONT) ;
324 doLine(fo, "read from cache1", messprintf("%d", nccr), LINE_CONT) ;
325 doLine(fo, "saved to cache1", messprintf("%d", nccw), LINE_END) ;
326
327 doLine(fo, "Cache1", "", LINE_SUBHEAD) ;
328 doLine(fo, "served", messprintf("%d", nc1r), LINE_CONT) ;
329 doLine(fo, "saved", messprintf("%d", nc1w), LINE_CONT) ;
330 doLine(fo, "read from disk", messprintf("%d", ncc1r), LINE_CONT) ;
331 doLine(fo, "saved to disk", messprintf("%d", ncc1w), LINE_END) ;
332
333 doLine(fo, "Disk blocks", "", LINE_SUBHEAD) ;
334 doLine(fo, "served", messprintf("%d", ndread), LINE_CONT) ;
335 doLine(fo, "saved", messprintf("%d", ndwrite), LINE_END) ;
336 }
337
338 if ((flag & STATUS_ALL) || (flag & STATUS_MEMORY))
339 {
340 doTitle(fo, "Overall Memory Usage (caches 1 & 2 + arrays + various)") ;
341 if (messalloctot)
342 {
343 doLine(fo, "Messalloc", "", LINE_SUBHEAD) ;
344 doLine(fo, "blocks", messprintf("%d", nmessalloc), LINE_CONT) ;
345 doLine(fo, "allocated (kb)", messprintf("%d", messalloctot/1024), LINE_END) ;
346 }
347 else
348 doLine(fo, "Messalloc - blocks", messprintf("%d", nmessalloc), LINE_START) ;
349 }
350
351 doSimpleLine(fo, "") ;
352 doSimpleLine(fo, "************************************************\n") ;
353
354
355 handleDestroy(handle);
356 messfree(last_save_time) ;
357
358 return;
359 } /* tStatus */
360
361 /*********************************/
362
363
364 static void doTitle(ACEOUT fo, char *text)
365 {
366 char *msg_text = NULL ;
367
368 msg_text = hprintf(0, "- %s", text) ;
369 myText(fo, msg_text, STATUS_TITLE_INDENT, TRUE, TRUE) ;
370 messfree(msg_text) ;
371
372 return ;
373 }
374
375 static void doSimpleLine(ACEOUT fo, char *text)
376 {
377 char *msg_text = NULL ;
378
379 msg_text = hprintf(0, "%s", text) ;
380 myText(fo, msg_text, STATUS_TITLE_INDENT, TRUE, TRUE) ;
381 messfree(msg_text) ;
382
383 return ;
384 }
385
386
387 static void doSingleLine(ACEOUT fo, char *label, char *value)
388 {
389 int indent = 0 ;
390 char *msg_text = NULL ;
391
392 if ((indent = STATUS_JUSTIFY - strlen(label)) < STATUS_MIN_INDENT)
393 indent = STATUS_MIN_INDENT ;
394
395 msg_text = hprintf(0, "%s: %s", label, value) ;
396 myText(fo, msg_text, indent, TRUE, TRUE) ;
397 messfree(msg_text) ;
398
399 return ;
400 }
401
402
403 static void doLine(ACEOUT fo, char *label, char *value, STATUS_LINE_TYPE type)
404 {
405 int indent = 0 ;
406 BOOL start, end ;
407 char *separator = "" ;
408 char *msg_text = NULL ;
409
410 if (type == LINE_SUBHEAD || type == LINE_START)
411 {
412 start = TRUE ;
413 if ((indent = STATUS_JUSTIFY - strlen(label)) < STATUS_MIN_INDENT)
414 indent = STATUS_MIN_INDENT ;
415 }
416 else
417 {
418 start = FALSE ;
419 indent = 2 ;
420 }
421
422 if (type == LINE_END)
423 {
424 end = TRUE ;
425 separator = "" ;
426 }
427 else
428 {
429 end = FALSE ;
430 separator = "," ;
431 }
432
433 if (type == LINE_SUBHEAD)
434 {
435 msg_text = hprintf(0, "%s -", label) ;
436 myText(fo, msg_text, indent - 1, start, end) ;
437 }
438 else
439 {
440 msg_text = hprintf(0, "%s: %s%s", label, value, separator) ;
441 myText(fo, msg_text, indent, start, end) ;
442 }
443 messfree(msg_text) ;
444
445 return ;
446 }
447
448
449 static void myText(ACEOUT fo, char *cp, int indent, BOOL startline, BOOL endline)
450 {
451 char ww[1000] ;
452 int i = 990 ;
453 char *cq = &ww[0] ;
454
455 if (indent < 0)
456 indent = 0 ;
457
458 if (startline)
459 {
460 *cq++ = ' ' ; *cq++ = '/' ; *cq++ = '/' ;
461 }
462
463 while (indent--) *cq++ = ' ' ;
464 while (i-- && *cp) *cq++ = *cp++ ;
465
466 if (endline)
467 *cq++ = '\n' ;
468
469 *cq++ = 0 ;
470
471 aceOutPrint(fo, "%s", ww) ;
472
473 return;
474 }
475
476
477
478 /*************************** eof ****************************/