forked from bloomberg/pystack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythread.h
More file actions
86 lines (72 loc) · 2.35 KB
/
pythread.h
File metadata and controls
86 lines (72 loc) · 2.35 KB
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
#pragma once
#include "memory"
#include <memory>
#include <sys/types.h>
#include <vector>
#include "mem.h"
#include "native_frame.h"
#include "process.h"
#include "pyframe.h"
namespace pystack {
class Thread
{
public:
Thread(pid_t pid, pid_t tid);
pid_t Tid() const;
const std::vector<NativeFrame>& NativeFrames() const;
// Methods
void populateNativeStackTrace(const std::shared_ptr<const AbstractProcessManager>& manager);
protected:
// Data members
pid_t d_pid;
pid_t d_tid;
std::vector<NativeFrame> d_native_frames;
};
class PyThread : public Thread
{
public:
// Enums
enum GilStatus { UNKNOWN = -1, NOT_HELD = 0, HELD = 1 };
enum GCStatus { COLLECTING_UNKNOWN = -1, NOT_COLLECTING = 0, COLLECTING = 1 };
// Constructors
PyThread(const std::shared_ptr<const AbstractProcessManager>& manager, remote_addr_t addr);
// Getters
std::shared_ptr<FrameObject> FirstFrame() const;
std::shared_ptr<PyThread> NextThread() const;
// Methods
GilStatus isGilHolder() const;
GCStatus isGCCollecting() const;
// Static Methods
static remote_addr_t getFrameAddr(
const std::shared_ptr<const AbstractProcessManager>& manager,
Structure<py_thread_v>& ts);
private:
// Data members
unsigned long d_pthread_id;
GilStatus d_gil_status;
GCStatus d_gc_status;
remote_addr_t d_addr;
remote_addr_t d_next_addr;
std::shared_ptr<PyThread> d_next;
std::shared_ptr<FrameObject> d_first_frame;
// Methods
GilStatus calculateGilStatus(
Structure<py_thread_v>& ts,
const std::shared_ptr<const AbstractProcessManager>& manager) const;
GCStatus calculateGCStatus(
Structure<py_thread_v>& ts,
const std::shared_ptr<const AbstractProcessManager>& manager) const;
// Static Methods
static int inferTidFromPThreadStructure(
const std::shared_ptr<const AbstractProcessManager>& manager,
unsigned long pthread_id);
static int getThreadTid(
const std::shared_ptr<const AbstractProcessManager>& manager,
Structure<py_thread_v>& ts,
unsigned long pthread_id);
};
std::shared_ptr<PyThread>
getThreadFromInterpreterState(
const std::shared_ptr<const AbstractProcessManager>& manager,
remote_addr_t addr);
} // namespace pystack