| 100 | public: |
| 101 | PollCallbackFunction() {} |
| 102 | WasmEdge::Expect<int32_t> body(const WasmEdge::Runtime::CallingFrame &Frame, |
| 103 | uint32_t __attribute__((unused)) ctx, |
| 104 | uint32_t data, uint32_t data_sz) { |
| 105 | using namespace std; |
| 106 | using WasmEdge::unlikely; |
| 107 | auto *memory = Frame.getMemoryByIndex(0); |
| 108 | if (unlikely(!memory)) { |
| 109 | return WasmEdge::Unexpect(WasmEdge::ErrCode::Value::HostFuncError); |
| 110 | } |
| 111 | if (data_sz < static_cast<uint32_t>(sizeof(event))) { |
| 112 | return WasmEdge::Unexpect(WasmEdge::ErrCode::Value::HostFuncError); |
| 113 | } |
| 114 | const event *dataPtr = memory->getSpan<const event>(data, 1).data(); |
| 115 | if (unlikely(!dataPtr)) { |
| 116 | return WasmEdge::Unexpect(WasmEdge::ErrCode::Value::HostFuncError); |
| 117 | } |
| 118 | auto nowTime = chrono::system_clock::now(); |
| 119 | if (dataPtr->exit_event == 1) { |
| 120 | fmt::print("{:%H:%M:%S} EXIT {:<16} {:<7} {:<7} [{}]"sv, nowTime, |
| 121 | dataPtr->comm, dataPtr->pid, dataPtr->ppid, |
| 122 | dataPtr->exit_code); |
| 123 | if (dataPtr->duration_ns != 0) { |
| 124 | fmt::print(" ({})"sv, dataPtr->duration_ns / 1000000); |
| 125 | } |
| 126 | fmt::print("\n"sv); |
| 127 | } else { |
| 128 | fmt::print("{:%H:%M:%S} EXEC {:<16} {:<7} {:<7} {}\n"sv, nowTime, |
| 129 | dataPtr->comm, dataPtr->pid, dataPtr->ppid, dataPtr->filename); |
| 130 | } |
| 131 | return 0; |
| 132 | } |
| 133 | }; |
| 134 | |
| 135 | TEST(WasmBpfTest, RunBpfProgramWithPolling) { |