summaryrefslogtreecommitdiff
path: root/ucoo/utils
diff options
context:
space:
mode:
authorNicolas Schodet2015-08-31 16:32:56 +0200
committerNicolas Schodet2019-10-07 00:44:50 +0200
commitddc7820ad411832e83ca0b7fe3b2e2a90a07c066 (patch)
tree8880ded20bcb70a8deb482917541e7c2ad7b06f5 /ucoo/utils
parentdf84a4f0d40981e9aab14af11a96af5ef8da8692 (diff)
ucoo/utils/trace: add timestamping
Diffstat (limited to 'ucoo/utils')
-rw-r--r--ucoo/utils/dtrace.py10
-rw-r--r--ucoo/utils/trace.hh76
-rw-r--r--ucoo/utils/trace.tcc91
3 files changed, 122 insertions, 55 deletions
diff --git a/ucoo/utils/dtrace.py b/ucoo/utils/dtrace.py
index 4180718..fc4cf57 100644
--- a/ucoo/utils/dtrace.py
+++ b/ucoo/utils/dtrace.py
@@ -11,16 +11,16 @@ class DTrace(gdb.Command):
return
trace = gdb.parse_and_eval(args[0])
- args_nb = trace['args_nb'];
- entries_nb = trace['entries_nb'];
index = trace['index'];
entries = trace['entries'];
+ entries_nb = entries.type.range()[1]
if entries[index]['str']:
r = range(index, entries_nb) + range(index)
else:
r = range(index)
+ last_timestamp = 0
for i in r:
entry = entries[i]
if not entry['str']:
@@ -35,6 +35,12 @@ class DTrace(gdb.Command):
if s.startswith('<'):
n = int(s[1:].partition('>')[0])
s = ' ' * (n * 10) + s
+ try:
+ timestamp = entry['timestamp']
+ print '[%+8d]' % (timestamp - last_timestamp),
+ last_timestamp = timestamp
+ except:
+ pass
print s
DTrace()
diff --git a/ucoo/utils/trace.hh b/ucoo/utils/trace.hh
index e2d33ac..dbbf442 100644
--- a/ucoo/utils/trace.hh
+++ b/ucoo/utils/trace.hh
@@ -26,8 +26,17 @@
namespace ucoo {
-/// Trace buffer to be read with debugger, no initialisation, should be
-/// instantiated in BSS.
+/// Used when there is no timestamp.
+struct NoTimestamp
+{
+ /// Information added to entry.
+ struct Entry { };
+ /// Fill an entry with current timestamp.
+ void operator () (Entry &) { }
+};
+
+/// Trace buffer to be read with debugger.
+template<typename Timestamp = NoTimestamp>
class TraceBuffer
{
/// Maximum number of arguments.
@@ -35,6 +44,8 @@ class TraceBuffer
/// Maximum number of trace entries.
static const int entries_nb = 32;
public:
+ /// Constructor.
+ TraceBuffer (const Timestamp &timestamp = Timestamp ());
/// Trace without argument.
inline void operator() (const char *str);
/// Trace with N arguments...
@@ -44,7 +55,7 @@ class TraceBuffer
inline void operator() (const char *str, int a0, int a1, int a2, int a3);
private:
/// Trace entry, contains all given parameters.
- struct Entry
+ struct Entry : public Timestamp::Entry
{
const char *str;
int args[args_nb];
@@ -53,6 +64,8 @@ class TraceBuffer
Entry entries[entries_nb];
/// Index of next entry to be written in entries array.
unsigned int index;
+ /// Time stamping object.
+ Timestamp timestamp_;
};
/// Dummy trace, trace nothing.
@@ -68,66 +81,23 @@ class TraceDummy
/// Conditional trace, whether it trace or not depends on the template
/// argument.
-template<bool ENABLED>
+template<bool ENABLED, typename Timestamp = NoTimestamp>
class Trace
{
};
-template<>
-class Trace<true> : public TraceBuffer
+template<typename Timestamp>
+class Trace<true, Timestamp> : public TraceBuffer<Timestamp>
{
};
-template<>
-class Trace<false> : public TraceDummy
+template<typename Timestamp>
+class Trace<false, Timestamp> : public TraceDummy
{
};
-inline void
-TraceBuffer::operator() (const char *str)
-{
- entries[index].str = str;
- index = (index + 1) % entries_nb;
-}
-
-inline void
-TraceBuffer::operator() (const char *str, int a0)
-{
- entries[index].str = str;
- entries[index].args[0] = a0;
- index = (index + 1) % entries_nb;
-}
-
-inline void
-TraceBuffer::operator() (const char *str, int a0, int a1)
-{
- entries[index].str = str;
- entries[index].args[0] = a0;
- entries[index].args[1] = a1;
- index = (index + 1) % entries_nb;
-}
-
-inline void
-TraceBuffer::operator() (const char *str, int a0, int a1, int a2)
-{
- entries[index].str = str;
- entries[index].args[0] = a0;
- entries[index].args[1] = a1;
- entries[index].args[2] = a2;
- index = (index + 1) % entries_nb;
-}
-
-inline void
-TraceBuffer::operator() (const char *str, int a0, int a1, int a2, int a3)
-{
- entries[index].str = str;
- entries[index].args[0] = a0;
- entries[index].args[1] = a1;
- entries[index].args[2] = a2;
- entries[index].args[3] = a3;
- index = (index + 1) % entries_nb;
-}
-
} // namespace ucoo
+#include "ucoo/utils/trace.tcc"
+
#endif // ucoo_utils_trace_hh
diff --git a/ucoo/utils/trace.tcc b/ucoo/utils/trace.tcc
new file mode 100644
index 0000000..e48c5d8
--- /dev/null
+++ b/ucoo/utils/trace.tcc
@@ -0,0 +1,91 @@
+#ifndef ucoo_utils_trace_tcc
+#define ucoo_utils_trace_tcc
+// ucoolib - Microcontroller object oriented library. {{{
+//
+// Copyright (C) 2015 Nicolas Schodet
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+//
+// }}}
+
+namespace ucoo {
+
+template<typename Timestamp>
+TraceBuffer<Timestamp>::TraceBuffer (const Timestamp &timestamp)
+ : entries{}, index (0), timestamp_ (timestamp)
+{
+}
+
+template<typename Timestamp>
+inline void
+TraceBuffer<Timestamp>::operator() (const char *str)
+{
+ timestamp_ (entries[index]);
+ entries[index].str = str;
+ index = (index + 1) % entries_nb;
+}
+
+template<typename Timestamp>
+inline void
+TraceBuffer<Timestamp>::operator() (const char *str, int a0)
+{
+ timestamp_ (entries[index]);
+ entries[index].str = str;
+ entries[index].args[0] = a0;
+ index = (index + 1) % entries_nb;
+}
+
+template<typename Timestamp>
+inline void
+TraceBuffer<Timestamp>::operator() (const char *str, int a0, int a1)
+{
+ timestamp_ (entries[index]);
+ entries[index].str = str;
+ entries[index].args[0] = a0;
+ entries[index].args[1] = a1;
+ index = (index + 1) % entries_nb;
+}
+
+template<typename Timestamp>
+inline void
+TraceBuffer<Timestamp>::operator() (const char *str, int a0, int a1, int a2)
+{
+ timestamp_ (entries[index]);
+ entries[index].str = str;
+ entries[index].args = { a0, a1, a2 };
+ index = (index + 1) % entries_nb;
+}
+
+template<typename Timestamp>
+inline void
+TraceBuffer<Timestamp>::operator() (const char *str, int a0, int a1, int a2,
+ int a3)
+{
+ timestamp_ (entries[index]);
+ entries[index].str = str;
+ entries[index].args[0] = a0;
+ entries[index].args[1] = a1;
+ entries[index].args[2] = a2;
+ entries[index].args[3] = a3;
+ index = (index + 1) % entries_nb;
+}
+
+} // namespace ucoo
+
+#endif // ucoo_utils_trace_tcc