forked from ajclinto/memview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoader.h
158 lines (127 loc) · 4.27 KB
/
Loader.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
This file is part of memview, a real-time memory trace visualization
application.
Copyright (C) 2013 Andrew Clinton
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307, USA.
The GNU General Public License is contained in the file COPYING.
*/
#ifndef Loader_H
#define Loader_H
#include <QThread>
#include "mv_ipc.h"
#include "Math.h"
#include "IntervalMap.h"
#include <unordered_map>
#include <memory>
#include <sys/types.h>
#include <signal.h>
class MemoryState;
typedef std::shared_ptr<MemoryState> MemoryStateHandle;
class Loader : public QThread {
public:
Loader(MemoryState *state,
StackTraceMap *stack,
MMapMap *mmapmap,
const std::string &path);
~Loader();
bool openPipe(int argc, char *argv[]);
void setZoomState(MemoryState *state)
{
QMutexLocker lock(&myPendingLock);
myPendingState.reset(state);
}
void clearZoomState()
{
QMutexLocker lock(&myPendingLock);
myPendingClear = true;
}
// Regulates the interval between stack traces
void setBlockSize(int size)
{
myBlockSize = SYSclamp(size, 1, MV_BlockSize);
}
MemoryState *getBaseState() const { return myState; }
uint64 getTotalEvents() const { return myTotalEvents; }
bool isComplete() const { return myAbort; }
pid_t getChild() const { return myChild; }
protected:
void run();
private:
bool initSharedMemory();
void writeToken(int token);
bool waitForInput(int timeout_ms);
bool loadFromLackey(int max_read);
bool loadFromPipe();
bool loadFromSharedMemory();
template <bool with_stacks>
bool loadFromTest();
bool loadFromTestExtrema();
bool loadBlock(const MV_TraceBlock &block);
void loadMMap(const MV_Header &header, const char *buf);
void timerEvent(QTimerEvent *event);
private:
typedef std::unordered_map<std::string, int> MMapNameMap;
MemoryState *myState;
MemoryStateHandle myZoomState;
StackTraceMap *myStackTrace;
MMapMap *myMMapMap;
MMapNameMap myMMapNames;
uint64 myTotalEvents;
std::string myPath;
QMutex myPendingLock;
std::unique_ptr<MemoryState> myPendingState;
bool myPendingClear;
int myBlockSize;
// Child process
pid_t myChild;
int myPipeFD;
FILE *myPipe;
int myOutPipeFD;
FILE *myOutPipe;
std::string mySharedName;
MV_SharedData *mySharedData;
int myIdx;
int myNextToken;
// What are we loading from?
enum LoadSource {
NONE,
LACKEY,
MEMVIEW_PIPE,
PIN,
TEST
};
LoadSource mySource;
int myTestType;
bool myAbort;
};
// Extract the option with the given prefix, removing it from argc/argv.
static const char *
extractOption(int &argc, char *argv[], const char *prefix)
{
const int len = strlen(prefix);
for (int i = 0; i < argc; i++)
{
if (!strncmp(argv[i], prefix, len))
{
const char *opt = argv[i] + len;
// Shorten the argument list
argc--;
for (; i < argc; i++)
argv[i] = argv[i+1];
return opt;
}
}
return 0;
}
#endif