```cpp
#ifndef PIPELINE_PIPELINE_H
#define PIPELINE_PIPELINE_H

#include <tuple>
#include <functional>
#include <queue>
#include <thread>
#include <vector>
#include <atomic>
#include "utils/data_queue.h"

namespace fast_pipeline {
// 获取类型列表中的第 I 个类型
template <size_t I, typename... Ts>
using Get = typename std::tuple_element<I, std::tuple<Ts...>>::type;

// 声明一个主模板 FunctionTraits
template <typename>
struct FunctionTraits;

// 对 FunctionTraits 进行部分特化，用于泛型类型 Function。
template <typename Function>
struct FunctionTraits : public FunctionTraits<decltype(&Function::operator())> {
};

// 针对成员函数指针类型的特化，匹配签名为 ReturnType (ClassType::*)(Argument) const 的函数。
template <typename ClassType, typename ReturnType, typename Argument>
struct FunctionTraits<ReturnType (ClassType::*)(Argument) const> {
    using ResultType = ReturnType;
    using ArgType = std::decay_t<Argument>;  // std::decay_t去掉引用和const
};

// Stage 结构体，包括函数和线程数
template <typename Func>
struct Stage {
    size_t threadNum;
    Func function;
    std::string name;

    Stage(Func func) : threadNum(1), function(func)
    {
    }

    Stage(size_t num, Func func) : threadNum(num), function(func)
    {
    }

    Stage(Func func, std::string name) : threadNum(1), function(func), name(std::move(name))
    {
    }

    Stage(size_t num, Func func, std::string name = "") : threadNum(num), function(func), name(std::move(name))
    {
    }
};

// 提取 Stage 特化
template <typename Func>
struct FunctionTraits<Stage<Func>> : public FunctionTraits<Func> {
};

// FastPipeline 类，接受多个 Stage
template <typename... Stages>
class FastPipeline {
    constexpr static size_t STAGE_NUM = sizeof...(Stages);

    using FirstInputType = typename FunctionTraits<Get<0, Stages...>>::ArgType;
    using LastReturnType = typename FunctionTraits<Get<STAGE_NUM - 1, Stages...>>::ResultType;
    template <size_t I>
    using GetIthType = Get<I, FirstInputType, typename FunctionTraits<Stages>::ResultType...>;

public:
    // 构造函数接受多个 Stage
    explicit FastPipeline(Stages... stages) : stages(stages...), stop(false)
    {
        StartPipelineHelper<0>();
    }

    ~FastPipeline()
    {
        Stop();
    }

    void Stop()
    {
        if (stop) {
            return;
        }

        stop = true;
        StopPipelineHelper<0>();
        for (auto& thread : threads) {
            thread.join();
        }
    }

    template <typename U>
    void Push(U&& data)
    {
        std::get<0>(queues).Push(std::forward<U>(data));
    }

    bool Pop(LastReturnType& result)
    {
        return std::get<STAGE_NUM>(queues).WaitAndPop(result);
    }

private:
    template <size_t I>
    void StartPipelineHelper()
    {
        if constexpr (I < STAGE_NUM) {
            const auto& stageI = std::get<I>(stages);
            stageStopCount[I] = 0;
            auto workFunction = [this, &stageI](int threadId) {
                GetIthType<I> input;
                while (true) {
                    bool res = std::get<I>(queues).WaitAndPop(input);
                    // ... 记录stageI.name(threadId)的wait性能数据
                    if (!res) {
                        break;
                    }
                    // 处理数据并推送到下一个阶段的队列
                    std::get<I + 1>(queues).Push(stageI.function(std::move(input)));
                    // ... 记录stageI.name(threadId)的call性能数据
                }
                stageStopCount[I]++;
            };

            // 启动工作线程
            for (size_t threadId = 0; threadId < stageI.threadNum; ++threadId) {
                threads.emplace_back(workFunction, threadId);
            }
            // 递归调用下一个阶段
            StartPipelineHelper<I + 1>();
        }
    }

    template <size_t I>
    void StopPipelineHelper()
    {
        if constexpr (I < STAGE_NUM) {
            // 开始销毁队列
            std::get<I>(queues).DestroyQueue();
            // 等StageI所有函数结束
            while (stageStopCount[I] != std::get<I>(stages).threadNum) {
                std::this_thread::sleep_for(std::chrono::milliseconds(1));
            }
            // 停止下个Stage
            StopPipelineHelper<I + 1>();
        }

        if constexpr (I == STAGE_NUM) {
            std::get<I>(queues).DestroyQueue();
        }
    }

    using QueuesTuple =
        std::tuple<DataQueue<FirstInputType>, DataQueue<typename FunctionTraits<Stages>::ResultType>...>;

    QueuesTuple queues;
    std::tuple<Stages...> stages;
    std::vector<std::thread> threads;
    std::atomic<bool> stop;
    std::atomic<int> stageStopCount[STAGE_NUM];
};
}  // namespace fast_pipeline
#endif  // PIPELINE_PIPELINE_H
```


我想扩展这个库实现性能分析模块，支持导出符合 chrome://tracing 可视化的 JSON 格式性能数据