Annotation of parser3/src/types/pa_vstatus.C, revision 1.15
1.1 paf 1: /** @file
2: Parser: @b status class impl.
3:
1.15 ! paf 4: Copyright (c) 2001, 2003 ArtLebedev Group (http://www.artlebedev.com)
1.6 paf 5: Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.8 paf 6: */
1.1 paf 7:
1.15 ! paf 8: static const char* IDENT_VSTATUS_C="$Date: 2002/10/31 15:01:57 $";
1.1 paf 9:
10: #include "pa_vstatus.h"
11: #include "pa_cache_managers.h"
1.2 paf 12: #include "pa_vhash.h"
13: #include "pa_vdouble.h"
14:
15: #ifdef HAVE_SYS_RESOURCE_H
16: // rusage
17: #include <sys/resource.h>
18: #endif
1.1 paf 19:
1.14 paf 20: Value *VStatus::get_element(const String& aname, Value& /*aself*/, bool /*looking_up*/) {
1.1 paf 21: // getstatus
22: if(Cache_manager *manager=static_cast<Cache_manager *>(cache_managers->get(aname)))
23: return &manager->get_status(pool(), &aname);
24:
25: #ifdef HAVE_GETRUSAGE
26: // rusage
27: if(aname=="rusage") {
1.2 paf 28: VHash& rusage=*NEW VHash(pool());
1.1 paf 29: struct rusage u;
1.13 paf 30: if(getrusage(RUSAGE_SELF,&u)<0)
1.7 paf 31: throw Exception(0,
1.1 paf 32: &aname,
1.13 paf 33: "getrusage failed (#%d)", errno);
34:
35: #ifdef HAVE_GETTIMEOFDAY
36: struct timeval tp;
37: if(gettimeofday(&tp, NULL)<0)
38: throw Exception(0,
39: &aname,
40: "gettimeofday failed (#%d)", errno);
41: #endif
1.1 paf 42:
1.2 paf 43: Hash& hash=rusage.hash(&aname);
44: hash.put(*NEW String(pool(), "utime"), NEW VDouble(pool(),
1.4 paf 45: u.ru_utime.tv_sec+u.ru_utime.tv_usec/1000000.0));
1.2 paf 46: hash.put(*NEW String(pool(), "stime"), NEW VDouble(pool(),
1.4 paf 47: u.ru_stime.tv_sec+u.ru_stime.tv_usec/1000000.0));
1.2 paf 48: hash.put(*NEW String(pool(), "maxrss"), NEW VDouble(pool(), u.ru_maxrss));
49: hash.put(*NEW String(pool(), "ixrss"), NEW VDouble(pool(), u.ru_ixrss));
50: hash.put(*NEW String(pool(), "idrss"), NEW VDouble(pool(), u.ru_idrss));
51: hash.put(*NEW String(pool(), "isrss"), NEW VDouble(pool(), u.ru_isrss));
1.13 paf 52:
53: #ifdef HAVE_GETTIMEOFDAY
54: hash.put(*NEW String(pool(), "tv_sec"), NEW VDouble(pool(), tp.tv_sec));
55: hash.put(*NEW String(pool(), "tv_usec"), NEW VDouble(pool(), tp.tv_usec));
56: #endif
1.1 paf 57:
58: return &rusage;
59: }
60:
61: #endif
62:
63: return 0;
64: }
E-mail: