1 | # RTEMS Tools Project (http://www.rtems.org/) |
---|
2 | # Copyright 2010-2015 Chris Johns (chrisj@rtems.org) |
---|
3 | # All rights reserved. |
---|
4 | # |
---|
5 | # This file is part of the RTEMS Tools package in 'rtems-tools'. |
---|
6 | # |
---|
7 | # Redistribution and use in source and binary forms, with or without |
---|
8 | # modification, are permitted provided that the following conditions are met: |
---|
9 | # |
---|
10 | # 1. Redistributions of source code must retain the above copyright notice, |
---|
11 | # this list of conditions and the following disclaimer. |
---|
12 | # |
---|
13 | # 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
14 | # this list of conditions and the following disclaimer in the documentation |
---|
15 | # and/or other materials provided with the distribution. |
---|
16 | # |
---|
17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
20 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
---|
21 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
22 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
23 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
24 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
25 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
26 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
27 | # POSSIBILITY OF SUCH DAMAGE. |
---|
28 | # |
---|
29 | |
---|
30 | # |
---|
31 | # RTEMS Time Support |
---|
32 | # |
---|
33 | |
---|
34 | import gdb |
---|
35 | |
---|
36 | class time(): |
---|
37 | |
---|
38 | def __init__(self, time_, ticks = False, scaler = 1000000000): |
---|
39 | self.ticks = ticks |
---|
40 | self.scaler = scaler |
---|
41 | if time_.type.code == gdb.TYPE_CODE_PTR: |
---|
42 | self.reference = time_ |
---|
43 | self.time = time_.dereference() |
---|
44 | else: |
---|
45 | self.time = time_ |
---|
46 | self.reference = time_.address |
---|
47 | if self.time.type.strip_typedefs().tag == 'timespec': |
---|
48 | self.timespecs = True |
---|
49 | else: |
---|
50 | self.timespecs = False |
---|
51 | |
---|
52 | def __str__(self): |
---|
53 | return self.tostring() |
---|
54 | |
---|
55 | def get(self): |
---|
56 | if self.timespecs: |
---|
57 | return (long(self.time['tv_sec']) * 1000000000) + long(self.time['tv_nsec']) |
---|
58 | else: |
---|
59 | return long(self.time) * self.scaler |
---|
60 | |
---|
61 | def tostring(self): |
---|
62 | if self.ticks: |
---|
63 | return '%d ticks' % (self.time) |
---|
64 | nsecs = self.get() |
---|
65 | secs = nsecs / 1000000000 |
---|
66 | nsecs = nsecs % 1000000000 |
---|
67 | minutes = secs / 60 |
---|
68 | secs = secs % 60 |
---|
69 | hours = minutes / 60 |
---|
70 | minutes = minutes % 60 |
---|
71 | days = hours / 24 |
---|
72 | hours = hours % 24 |
---|
73 | t = '' |
---|
74 | if days: |
---|
75 | t = '%dd ' % (days) |
---|
76 | if hours or minutes or secs: |
---|
77 | t += '%02d:%02d:%02d ' % (hours, minutes, secs) |
---|
78 | t += '%d nsec' % (nsecs) |
---|
79 | return t |
---|