# CustomStackTrace

## class CustomStackTrace

template <typename T>
class `paddle::``CustomStackTrace`

  A ThreadLocal stack for tracing train/test process. (More details of ThreadLocal can be find in the comments of ThreadLocal class.)

  For example.

      paddle::CustomStackTrace<std::string> stack;
      for (auto& layer : layers){
        stack.push(layer->getName());
        layer->forward();
      }

      stack.pop("");  // mark under pop stage.

      for (auto it = layers.rbegin(); it != layers.rend(); ++it){
        auto& layer = *it;
        layer->backward(passType);
        stack.pop(layer->getName());
      }

  Public Types

  typedef std::function<void(const std::thread::id&, bool *, const T&)> `DumpCallback`

    DumpCallback Type. It will be invoked many times by dump method.

    The first parameter is stack thread id. The second parameter is the last action of stack is push or not. The third parameter is the item in stack.

  Public Functions

  void `pop`(const T &item)

    Pop out an item from the top of the stack if item == top. Else, just set status to popping.

  void `clear`()

    clear current thread stack.

  bool `empty`() const

    return true if all thread’s stack is empty.

    Return
      true if empty
  void `dump`(const DumpCallback &callback, bool onlyCurrentThread = false)

    Dump all thread stack, and all stack will be cleared.

  void `push`(const T &item)

    Push item to current thread stack.