| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- #include <iostream>
- #include <phpcpp.h>
- #include "bpf_module.h"
- #include "BPF.h"
- class BaseTable : public Php::Base {
- public:
- ebpf::BPF *bpf;
- std::string tb_name;
- BaseTable(ebpf::BPF *bpf_instance, const std::string &tb_name)
- : bpf(bpf_instance), tb_name(tb_name) {}
- virtual ~BaseTable() = default;
- void printName() { std::cout << "Table name: " << tb_name << std::endl; }
- };
- class PerfEventArrayTable : public BaseTable {
- private:
- std::string cb;
- public:
- using BaseTable::BaseTable;
- // ebpf::BPF *bpf;
- // std::string event_name;
- //
- // PerfEventArrayTable(ebpf::BPF *bpf_instance, const std::string &event_name)
- // : bpf(bpf_instance), event_name(event_name) {}
- // using BaseTable::BaseTable;
- virtual ~PerfEventArrayTable() = default;
- static void callbackfn(void *cookie, void *data, int data_size) {
- auto *instance = static_cast<PerfEventArrayTable *>(cookie);
- if (!instance) return;
- Php::Value phpData((const char *) data, data_size);
- Php::call(instance->cb.c_str(), nullptr, phpData, data_size);
- }
- void php_open_perf_buffer(Php::Parameters ¶ms) {
- this->cb = params[0].stringValue();
- auto res = this->bpf->open_perf_buffer(this->tb_name, callbackfn, nullptr, this);
- if (!res.ok()) {
- throw Php::Exception("open_perf_buffer error:" + res.msg());
- }
- // auto control_table_hdl = bpf->get_array_table<uint64_t>("counters");
- // uint64_t val;
- // auto res1 = control_table_hdl.get_value(0, val);
- // Php::out << "ok]" << res1.ok() << std::endl;
- // Php::out << "msg]" << res1.msg() << std::endl;
- // Php::out << "val]" << val << std::endl;
- }
- int perf_buffer_poll(int timeout_ms) {
- return bpf->poll_perf_buffer(this->tb_name, timeout_ms); // perf_reader_event_read
- }
- };
- class HashTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
- class ArrayTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- Php::Value Value(Php::Parameters ¶m) {
- auto index = param[0].numericValue();
- // todo val type
- uint64_t val;
- auto table = bpf->get_array_table<uint64_t>(tb_name);
- auto res = table.get_value(index, val);
- if (!res.ok()) {
- throw Php::Exception("Get value error in" + std::string(tb_name));
- }
- Php::Value phpValue = static_cast<int64_t>(val);
- return phpValue;
- }
- };
- class ProgArrayTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- void Value(Php::Parameters ¶m) {
- auto index = param[0].numericValue();
- // todo key type
- uint64_t val;
- auto table = bpf->get_array_table<uint64_t>(tb_name);
- auto res = table.get_value(index, val);
- printf("%d\n", val);
- }
- };
- class PerCpuHashTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
- class PerCpuArrayTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
- class LpmTrieTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
- class StackTraceTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
- class LruHashTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
- class LruPerCpuHashTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
- class CgroupArrayTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
- class DevMapTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
- class CpuMapTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
- class XskMapTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
- class MapInMapArrayTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
- class MapInMapHashTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
- class QueueStackTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
- class RingBufTable : public BaseTable {
- public:
- using BaseTable::BaseTable;
- };
|