Skip to content

Commit

Permalink
Merge pull request #812 from GorilaMond/develop
Browse files Browse the repository at this point in the history
Stack_Analyzer:simplify ready and finish func for eBPF progs
  • Loading branch information
chenamy2017 authored May 29, 2024
2 parents befef7c + 0886adf commit 649b2dd
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 330 deletions.
37 changes: 15 additions & 22 deletions .github/workflows/ebpf_stack_analyser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,31 @@ jobs:

- name: Install native lib dependencies
run: |
git submodule update --init --recursive
git submodule update --init --recursive eBPF_Supermarket/Stack_Analyser/ MagicEyes/
sudo apt install clang libelf1 libelf-dev zlib1g-dev
- name: Run app with native lib
- name: Compile test examples
run: |
cd eBPF_Supermarket/Stack_Analyser/testdir
gcc -o ./usdt_pthread -lpthread ./usdt_pthread.c
gcc -o ./uprobe_malloc ./uprobe_malloc.c
- name: Compile and run app with native lib
run: |
cd eBPF_Supermarket/Stack_Analyser
make
make -j$(nproc)
sudo ./stack_analyzer on_cpu off_cpu memleak io readahead llc_stat probe "vfs_open" probe "t:sched:sched_switch" -d 5
gcc -o ./testdir/usdt_pthread ./testdir/usdt_pthread.c
sudo ./stack_analyzer probe "u:pthread:pthread_create" -c "./testdir/usdt_pthread" -d 5
gcc -o ./testdir/uprobe_malloc ./testdir/uprobe_malloc.c
sudo ./stack_analyzer probe "c:malloc" -c "./testdir/uprobe_malloc" -d 5
magic-eyes-build-and-test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

- name: Install native lib dependencies
run: |
git submodule update --init --recursive
sudo apt install clang libelf1 libelf-dev zlib1g-dev
- name: Run app with native lib
- name: Compile and run MagicEyes app with native lib
run: |
mkdir -p MagicEyes/build
cd MagicEyes/build
cmake -DBUILD_STACK_ANALYZER=ON ..
make
sudo ./src/backend/system_diagnosis/stack_analyzer/stack_analyzer on_cpu off_cpu memleak io readahead llc_stat probe vfs_open -d 5
sudo ./src/backend/system_diagnosis/stack_analyzer/stack_analyzer probe "p::vfs_open" probe "t:sched:sched_switch" -d 5
sudo ./src/backend/system_diagnosis/stack_analyzer/stack_analyzer probe "c:malloc" -c "../../eBPF_Supermarket/Stack_Analyser/testdir/uprobe_malloc" -d 5
make -j$(nproc)
sudo ./src/backend/system_diagnosis/stack_analyzer/stack_analyzer on_cpu off_cpu memleak io readahead llc_stat probe "p::vfs_open" probe "t:sched:sched_switch" -d 5
sudo ./src/backend/system_diagnosis/stack_analyzer/stack_analyzer probe "u:pthread:pthread_create" -c "../../eBPF_Supermarket/Stack_Analyser/testdir/usdt_pthread" -d 5
sudo ./src/backend/system_diagnosis/stack_analyzer/stack_analyzer probe "c:malloc" -c "../../eBPF_Supermarket/Stack_Analyser/testdir/uprobe_malloc" -d 5
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,8 @@ class StackCollector
StackCollector();
operator std::string();

/// @brief 负责ebpf程序的加载、参数设置和打开操作
/// @param 无
/// @return 成功则返回0,否则返回负数
virtual int load(void) = 0;

/// @brief 将ebpf程序挂载到跟踪点上
/// @param 无
/// @return 成功则返回0,否则返回负数
virtual int attach(void) = 0;

/// @brief 断开ebpf的跟踪点和处理函数间的连接
/// @param 无
virtual void detach(void) = 0;

/// @brief 卸载ebpf程序
/// @param 无
virtual void unload(void) = 0;
virtual int ready(void) = 0;
virtual void finish(void) = 0;

/// @brief 激活eBPF程序
/// @param 无
Expand Down
6 changes: 2 additions & 4 deletions eBPF_Supermarket/Stack_Analyser/include/bpf_wapper/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ class IOStackCollector : public StackCollector

public:
IOStackCollector();
virtual int load(void);
virtual int attach(void);
virtual void detach(void);
virtual void unload(void);
virtual int ready(void);
virtual void finish(void);
virtual void activate(bool tf);
virtual const char *getName(void);
};
Expand Down
6 changes: 2 additions & 4 deletions eBPF_Supermarket/Stack_Analyser/include/bpf_wapper/llc_stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ class LlcStatStackCollector : public StackCollector

public:
LlcStatStackCollector();
virtual int load(void);
virtual int attach(void);
virtual void detach(void);
virtual void unload(void);
virtual int ready(void);
virtual void finish(void);
virtual void activate(bool tf);
virtual const char *getName(void);
void setScale(uint64_t period);
Expand Down
6 changes: 2 additions & 4 deletions eBPF_Supermarket/Stack_Analyser/include/bpf_wapper/memleak.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ class MemleakStackCollector : public StackCollector
public:
MemleakStackCollector();

virtual int load(void);
virtual int attach(void);
virtual void detach(void);
virtual void unload(void);
virtual int ready(void);
virtual void finish(void);
virtual void activate(bool tf);
virtual const char *getName(void);

Expand Down
6 changes: 2 additions & 4 deletions eBPF_Supermarket/Stack_Analyser/include/bpf_wapper/off_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ class OffCPUStackCollector : public StackCollector

public:
OffCPUStackCollector();
virtual int load(void);
virtual int attach(void);
virtual void detach(void);
virtual void unload(void);
virtual int ready(void);
virtual void finish(void);
virtual void activate(bool tf);
virtual const char *getName(void);
};
Expand Down
6 changes: 2 additions & 4 deletions eBPF_Supermarket/Stack_Analyser/include/bpf_wapper/on_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ class OnCPUStackCollector : public StackCollector
public:
void setScale(uint64_t freq);
OnCPUStackCollector();
virtual int load(void);
virtual int attach(void);
virtual void detach(void);
virtual void unload(void);
virtual int ready(void);
virtual void finish(void);
virtual void activate(bool tf);
virtual const char *getName(void);
};
Expand Down
6 changes: 2 additions & 4 deletions eBPF_Supermarket/Stack_Analyser/include/bpf_wapper/probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ class ProbeStackCollector : public StackCollector
public:
void setScale(std::string probe);
ProbeStackCollector();
virtual int load(void);
virtual int attach(void);
virtual void detach(void);
virtual void unload(void);
virtual int ready(void);
virtual void finish(void);
virtual void activate(bool tf);
virtual const char *getName(void);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ class ReadaheadStackCollector : public StackCollector

public:
ReadaheadStackCollector();
virtual int load(void);
virtual int attach(void);
virtual void detach(void);
virtual void unload(void);
virtual int ready(void);
virtual void finish(void);
virtual void activate(bool tf);
virtual const char *getName(void);
};
Expand Down
6 changes: 2 additions & 4 deletions eBPF_Supermarket/Stack_Analyser/include/bpf_wapper/template.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ class TemplateClass : public StackCollector

public:
TemplateClass();
virtual int load(void);
virtual int attach(void);
virtual void detach(void);
virtual void unload(void);
virtual int ready(void);
virtual void finish(void);
virtual void activate(bool tf);
virtual const char *getName(void);
};
Expand Down
16 changes: 4 additions & 12 deletions eBPF_Supermarket/Stack_Analyser/src/bpf_wapper/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,16 @@ IOStackCollector::IOStackCollector()
};
};

int IOStackCollector::load(void)
int IOStackCollector::ready(void)
{
EBPF_LOAD_OPEN_INIT();
return 0;
}

int IOStackCollector::attach(void)
{
ATTACH_PROTO;
return 0;
}

void IOStackCollector::detach(void)
void IOStackCollector::finish(void)
{
DETACH_PROTO;
}

void IOStackCollector::unload(void)
{
UNLOAD_PROTO;
}

Expand All @@ -63,6 +54,7 @@ void IOStackCollector::activate(bool tf)
ACTIVE_SET(tf);
}

const char *IOStackCollector::getName(void) {
const char *IOStackCollector::getName(void)
{
return "IOStackCollector";
}
22 changes: 6 additions & 16 deletions eBPF_Supermarket/Stack_Analyser/src/bpf_wapper/llc_stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,12 @@ uint64_t *LlcStatStackCollector::count_values(void *data)
};
};

int LlcStatStackCollector::load(void)
int LlcStatStackCollector::ready(void)
{
EBPF_LOAD_OPEN_INIT();
return 0;
};

int LlcStatStackCollector::attach(void)
{
const char *online_cpus_file = "/sys/devices/system/cpu/online";
bool *online_mask;
int num_online_cpus;
err = parse_cpu_mask_file(online_cpus_file, &online_mask, &num_online_cpus);
err = parse_cpu_mask_file("/sys/devices/system/cpu/online", &online_mask, &num_online_cpus);
CHECK_ERR_RN1(err, "Fail to get online CPU numbers");

num_cpus = libbpf_num_possible_cpus();
Expand Down Expand Up @@ -93,10 +87,10 @@ int LlcStatStackCollector::attach(void)
rlinks[cpu] = bpf_program__attach_perf_event(skel->progs.on_cache_ref, pefd);
CHECK_ERR_RN1(!rlinks[cpu], "Fail to attach bpf program");
}
return 0;
};
return 0;
}

void LlcStatStackCollector::detach(void)
void LlcStatStackCollector::finish(void)
{
for (int cpu = 0; cpu < num_cpus; cpu++)
{
Expand All @@ -111,12 +105,8 @@ void LlcStatStackCollector::detach(void)
free(rpefds);
mlinks = rlinks = NULL;
mpefds = rpefds = NULL;
};

void LlcStatStackCollector::unload(void)
{
UNLOAD_PROTO;
};
}

void LlcStatStackCollector::activate(bool tf)
{
Expand Down
16 changes: 4 additions & 12 deletions eBPF_Supermarket/Stack_Analyser/src/bpf_wapper/memleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ int MemleakStackCollector::attach_uprobes(struct memleak_bpf *skel)
return 0;
}

int MemleakStackCollector::load(void)
int MemleakStackCollector::ready(void)
{
EBPF_LOAD_OPEN_INIT(
if (kstack) {
Expand All @@ -122,28 +122,20 @@ int MemleakStackCollector::load(void)
} else disable_kernel_tracepoints(skel);
skel->rodata->wa_missing_free = wa_missing_free;
skel->rodata->page_size = sysconf(_SC_PAGE_SIZE););
return 0;
};

int MemleakStackCollector::attach(void)
{
if (!kstack)
CHECK_ERR_RN1(attach_uprobes(skel), "failed to attach uprobes");
err = skel->attach(skel);
CHECK_ERR_RN1(err, "Failed to attach BPF skeleton");
return 0;
};
}

void MemleakStackCollector::detach(void)
void MemleakStackCollector::finish(void)
{
DETACH_PROTO;
};

void MemleakStackCollector::unload(void)
{
UNLOAD_PROTO;
}


void MemleakStackCollector::activate(bool tf)
{
ACTIVE_SET(tf);
Expand Down
16 changes: 4 additions & 12 deletions eBPF_Supermarket/Stack_Analyser/src/bpf_wapper/off_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,9 @@ uint64_t *OffCPUStackCollector::count_values(void *data)
};
};

int OffCPUStackCollector::load(void)
int OffCPUStackCollector::ready(void)
{
EBPF_LOAD_OPEN_INIT();
return 0;
}

int OffCPUStackCollector::attach(void)
{
symbol sym;
sym.name = "finish_task_switch";
if (!g_symbol_parser.complete_kernel_symbol(sym))
Expand All @@ -52,13 +47,9 @@ int OffCPUStackCollector::attach(void)
return 0;
}

void OffCPUStackCollector::detach(void)
void OffCPUStackCollector::finish(void)
{
DETACH_PROTO;
}

void OffCPUStackCollector::unload(void)
{
UNLOAD_PROTO;
}

Expand All @@ -67,6 +58,7 @@ void OffCPUStackCollector::activate(bool tf)
ACTIVE_SET(tf);
}

const char *OffCPUStackCollector::getName(void) {
const char *OffCPUStackCollector::getName(void)
{
return "OffCPUStackCollector";
}
Loading

0 comments on commit 649b2dd

Please sign in to comment.