-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathservice_mprof.h
69 lines (58 loc) · 1.53 KB
/
service_mprof.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
#pragma once
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <string>
#include <map>
#include <unordered_map>
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>
#include <execinfo.h>
#include <assert.h>
extern "C" {
#include "skynet.h"
#include "skynet_socket.h"
#include "skynet_server.h"
}
extern int mprof_notify_fd; // defined in malloc_hook.c
extern uint32_t mprof_svc_handle; // defined in malloc_hook.c
static const uint8_t MAX_FUNC_NAME_SIZE = 80;
static const int MAX_STACK_SIZE = 32;
static const int BUCK_HASH_SIZE = 179999;
static const int HEADER_LEN = 2;
struct bucket {
int alloc_objs;
int alloc_bytes;
int free_objs;
int free_bytes;
int depth;
void* stack[MAX_STACK_SIZE];
uint64_t hash;
size_t size;
struct bucket* next;
struct bucket* allnext;
};
class mprof_app {
public:
mprof_app();
~mprof_app();
void init_pipe();
void handle_cmd(const char* msg, int sz);
void handle_socket_msg(const struct skynet_socket_message* message);
void build_func_symbol_table();
void dump_mem_records(char* filename);
public:
struct bucket* m_buckhash[BUCK_HASH_SIZE];
struct bucket* m_bucklist;
std::unordered_map<std::string, void*> m_func_name2Id;
std::unordered_map<void*, std::string> m_func_Id2name;
std::unordered_map<void*, struct bucket*> m_mem2buck;
std::string m_recv_buf;
struct skynet_context* m_ctx;
int m_mem_prof_rate;
int m_records_num;
int m_bucks_num;
int m_socketId;
};