-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpathtracer.h
134 lines (109 loc) · 3.89 KB
/
pathtracer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Copyright 2012 Aarhus University
*
* Licensed under the GNU General Public License, Version 3 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl-3.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PATHTRACER_H
#define PATHTRACER_H
#include <string>
#include <inttypes.h>
#include <QObject>
#include <QList>
#include <QSharedPointer>
#include <QWebElement>
#include <QWebExecutionListener>
#include <QDateTime>
#include <QListIterator>
#include <QSource>
#include <QHash>
#include "runtime/options.h"
#include "runtime/input/baseinput.h"
#include "model/coverage/sourceinfo.h"
#include "model/coverage/coveragelistener.h"
namespace artemis
{
class PathTracer : public QObject
{
Q_OBJECT
public:
explicit PathTracer(PathTraceReport reportLevel, CoverageListenerPtr coverage);
void notifyStartingLoad();
void notifyStartingEvent(QSharedPointer<const BaseInput> inputEvent);
void write();
void writePathTraceHTML(bool linkWithCoverage, QString coveragePath, QString& pathToFile);
void writeStatistics();
private:
CoverageListenerPtr mCoverage; // used for printing urls without storing the entire URL
enum ItemType {FUNCALL, FUNRET, ALERT};
struct TraceItem {
ItemType type;
QString string;
// The following are not present in all item types.
uint lineInFile;
sourceid_t sourceID;
QString getUrl(CoverageListenerPtr coverage) {
return coverage->getSourceInfo(sourceID)->getURL();
}
QString getName() {
switch (type) {
case ALERT:
return "alert()";
default:
return string;
}
}
QString getMessage(CoverageListenerPtr coverage) {
switch (type) {
case FUNCALL:
return QString("File: %1, Line: %2.").arg(PathTracer::displayedUrl(getUrl(coverage))).arg(lineInFile);
case ALERT:
return string;
default:
return "";
}
}
uint hashcode() {
return (uint)type + qHash(string) * 7 + lineInFile * 31 + sourceID * 79;
}
};
/**
* We place all trace items in the trace item pool, such that items with identical contents are merged together.
*
* This is to reduce the high memory consumption resulting from a large number of very similar traces.
*/
typedef uint TraceItemReference;
QHash<TraceItemReference, TraceItem> mTraceItemPool;
unsigned int mTraceItemPoolUncompressedSize;
enum TraceType {OTHER, CLICK, LOAD, MOUSE};
struct PathTrace {
TraceType type;
QString description;
QList<TraceItemReference> items;
};
QList<PathTrace> mTraces;
const PathTraceReport mReportLevel;
void newPathTrace(QString description, TraceType type);
void appendItem(TraceItem item);
void appendItem(ItemType type, QString name);
static QString displayedUrl(QString url, bool fileNameOnly = false);
QString displayedFunctionName(QString name);
QString TraceClass(TraceType type);
public slots:
void slJavascriptFunctionCalled(QString functionName, size_t bytecodeSize, uint functionStartLine, uint sourceOffset, QSource* source);
void slJavascriptFunctionReturned(QString functionName);
void slEventListenerTriggered(QWebElement* elem, QString eventName);
void slJavascriptAlert(QWebFrame* frame, QString msg);
};
typedef QSharedPointer<PathTracer> PathTracerPtr;
}
#endif // PATHTRACER_H