~mixxxdevelopers/mixxx/engine-control-refactor

« back to all changes in this revision

Viewing changes to mixxx/src/util/trace.h

  • Committer: RJ Ryan
  • Date: 2013-06-04 00:41:29 UTC
  • mfrom: (2890.22.101 mixxx)
  • Revision ID: rryan@mixxx.org-20130604004129-8jjxkicsb3givu4a
MergingĀ fromĀ lp:mixxx.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef TRACE_H
 
2
#define TRACE_H
 
3
 
 
4
#include <QString>
 
5
#include <QTime>
 
6
 
 
7
#include "util/cmdlineargs.h"
 
8
#include "util/stat.h"
 
9
 
 
10
class Trace {
 
11
  public:
 
12
    explicit Trace(const QString& tag, bool stdout=true, bool time=false)
 
13
            : m_tag(tag),
 
14
              m_stdout(stdout),
 
15
              m_time(time) {
 
16
        if (m_time) {
 
17
            m_timer.start();
 
18
        }
 
19
        if (m_stdout) {
 
20
            qDebug() << "START [" << m_tag << "]";
 
21
        }
 
22
        Stat::track(m_tag + "_enter", Stat::TRACE_START, Stat::COUNT, 0);
 
23
 
 
24
    }
 
25
    virtual ~Trace() {
 
26
        int elapsed = m_time ? m_timer.elapsed() : 0;
 
27
        if (m_stdout) {
 
28
            if (m_time) {
 
29
                qDebug() << "END [" << m_tag << "]"
 
30
                         << QString("elapsed: %1ms").arg(elapsed);
 
31
            } else {
 
32
                qDebug() << "END [" << m_tag << "]";
 
33
            }
 
34
        }
 
35
 
 
36
        Stat::track(m_tag + "_exit", Stat::TRACE_FINISH, Stat::COUNT, 0);
 
37
        if (m_time) {
 
38
            Stat::track(
 
39
                m_tag + "_duration",
 
40
                Stat::DURATION_MSEC,
 
41
                Stat::COUNT | Stat::AVERAGE | Stat::SAMPLE_VARIANCE | Stat::MAX | Stat::MIN,
 
42
                elapsed);
 
43
        }
 
44
    }
 
45
 
 
46
  private:
 
47
    const QString m_tag;
 
48
    const bool m_stdout, m_time;
 
49
    QTime m_timer;
 
50
 
 
51
};
 
52
 
 
53
class DebugTrace : public Trace {
 
54
  public:
 
55
    DebugTrace(const QString& tag, bool time=true)
 
56
    : Trace(tag, CmdlineArgs::Instance().getDeveloper(), time) {
 
57
    }
 
58
    virtual ~DebugTrace() {
 
59
    }
 
60
};
 
61
 
 
62
#endif /* TRACE_H */