OSDN Git Service

2011-11-07 Paolo Carlini <paolo.carlini@oracle.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / profile / impl / profiler_node.h
index 3dafff6..dfaff8c 100644 (file)
@@ -1,6 +1,6 @@
 // -*- C++ -*-
 //
-// Copyright (C) 2009 Free Software Foundation, Inc.
+// Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the terms
 
 // Written by Lixia Liu and Silvius Rus.
 
-#ifndef PROFCXX_PROFILER_NODE_H__
-#define PROFCXX_PROFILER_NODE_H__ 1
+#ifndef _GLIBCXX_PROFILE_PROFILER_NODE_H
+#define _GLIBCXX_PROFILE_PROFILER_NODE_H 1
+
+#include <cstdio> // FILE, fprintf
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
-#include <cstdio>
-#include <cstdint>
-#include <cstring>
-#else
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-#endif
 #include <vector>
-#if defined HAVE_EXECINFO_H
+#if defined _GLIBCXX_HAVE_EXECINFO_H
 #include <execinfo.h>
 #endif
 
 namespace __gnu_profile
 {
-typedef const void* __object_t;
-typedef void* __instruction_address_t;
-typedef std::_GLIBCXX_STD_PR::vector<__instruction_address_t> __stack_npt;
-typedef __stack_npt* __stack_t;
+  typedef const void* __object_t;
+  typedef void* __instruction_address_t;
+  typedef std::_GLIBCXX_STD_C::vector<__instruction_address_t> __stack_npt;
+  typedef __stack_npt* __stack_t;
 
-size_t __stack_max_depth();
+  std::size_t __stack_max_depth();
 
-inline __stack_t __get_stack()
-{
-#if defined HAVE_EXECINFO_H
-  size_t __max_depth = __stack_max_depth();
-  if (__max_depth == 0)
-    return NULL;
-  __stack_npt __buffer(__max_depth);
-  int __depth = backtrace(&__buffer[0], __max_depth);
-  __stack_t __stack = new __stack_npt(__depth);
-  memcpy(&(*__stack)[0], &__buffer[0], __depth * sizeof(__object_t));
-  return __stack;
+  inline __stack_t
+  __get_stack()
+  {
+#if defined _GLIBCXX_HAVE_EXECINFO_H
+    std::size_t __max_depth = __stack_max_depth();
+    if (__max_depth == 0)
+      return 0;
+    __stack_npt __buffer(__max_depth);
+    int __depth = backtrace(&__buffer[0], __max_depth);
+    __stack_t __stack = new __stack_npt(__depth);
+    __builtin_memcpy(&(*__stack)[0], &__buffer[0],
+                    __depth * sizeof(__object_t));
+    return __stack;
 #else
-  return NULL;
-#endif
-}
-
-inline __size(const __stack_t& __stack)
-{
-  if (!__stack) {
     return 0;
-  } else {
-    return __stack->size();
-  }
-}
-
-inline void __write(FILE* __f, const __stack_t __stack)
-{
-  if (!__stack) {
-    return;
-  }
-
-  __stack_npt::const_iterator __it;
-  for (__it = __stack->begin(); __it != __stack->end(); ++__it) {
-    fprintf(__f, "%p ", *__it);
+#endif
   }
-}
 
-/** @brief Hash function for summary trace using call stack as index.  */
-class __stack_hash 
-{
- public:
-  size_t operator()(const __stack_t __s) const
+  inline std::size_t
+  __size(__stack_t __stack)
   {
-    if (!__s) {
+    if (!__stack)
       return 0;
-    }
+    else
+      return __stack->size();
+  }
 
-    uintptr_t __index = 0;
+  // XXX
+  inline void
+  __write(FILE* __f, __stack_t __stack)
+  {
+    if (!__stack)
+      return;
+  
     __stack_npt::const_iterator __it;
-    for (__it = __s->begin(); __it != __s->end(); ++__it) {
-      __index += reinterpret_cast<uintptr_t>(*__it);
-    } 
-    return __index;
+    for (__it = __stack->begin(); __it != __stack->end(); ++__it)
+      std::fprintf(__f, "%p ", *__it);
   }
 
-  bool operator() (const __stack_t __stack1, const __stack_t __stack2) const
+  /** @brief Hash function for summary trace using call stack as index.  */
+  class __stack_hash 
   {
-    if (!__stack1 && !__stack2) return true;
-    if (!__stack1 || !__stack2) return false;
-    if (__stack1->size() != __stack2->size()) return false;
-
-    size_t __byte_size = __stack1->size() * sizeof(__stack_npt::value_type);
-    return memcmp(&(*__stack1)[0], &(*__stack2)[0], __byte_size) == 0;
-  }
-};
+  public:
+    std::size_t
+    operator()(__stack_t __s) const
+    {
+      if (!__s) 
+       return 0;
+
+      std::size_t __index = 0;
+      __stack_npt::const_iterator __it;
+      for (__it = __s->begin(); __it != __s->end(); ++__it)
+       __index += reinterpret_cast<std::size_t>(*__it);
+      return __index;
+    }
 
-/** @brief Base class for a line in the object table.  */
-class __object_info_base
-{
- public:
-  __object_info_base() {}
-  __object_info_base(__stack_t __stack);
-  __object_info_base(const __object_info_base& o);
-  virtual ~__object_info_base() {}
-  bool __is_valid() const { return _M_valid; }
-  __stack_t __stack() const { return _M_stack; }
-  virtual void __write(FILE* f) const = 0;
-
- protected:
-  __stack_t _M_stack;
-  bool _M_valid;
-};
-
-inline __object_info_base::__object_info_base(__stack_t __stack)
-{
-  _M_stack = __stack;
-  _M_valid = true;
-}
+    bool operator() (__stack_t __stack1, __stack_t __stack2) const
+    {
+      if (!__stack1 && !__stack2)
+       return true;
+      if (!__stack1 || !__stack2)
+       return false;
+      if (__stack1->size() != __stack2->size())
+       return false;
+
+      std::size_t __byte_size
+       = __stack1->size() * sizeof(__stack_npt::value_type);
+      return __builtin_memcmp(&(*__stack1)[0], &(*__stack2)[0],
+                             __byte_size) == 0;
+    }
+  };
 
-inline __object_info_base::__object_info_base(const __object_info_base& __o)
-{
-  _M_stack = __o._M_stack;
-  _M_valid = __o._M_valid;
-}
 
-/** @brief Base class for a line in the stack table.  */
-template<typename __object_info>
-class __stack_info_base
-{
- public:
-  __stack_info_base() {}
-  __stack_info_base(const __object_info& __info) = 0;
-  virtual ~__stack_info_base() {}
-  void __merge(const __object_info& __info) = 0;
-  virtual float __magnitude() const = 0;
-  virtual const char* __get_id() const = 0;
-};
+  /** @brief Base class for a line in the object table.  */
+  class __object_info_base
+  {
+  public:
+    __object_info_base() { }
+
+    __object_info_base(__stack_t __stack)
+    : _M_stack(__stack), _M_valid(true) { }
+
+    __object_info_base(const __object_info_base& __o)
+    : _M_stack(__o._M_stack), _M_valid(__o._M_valid) { }
+
+    virtual ~__object_info_base() { }
+
+    bool
+    __is_valid() const 
+    { return _M_valid; }
+    
+    __stack_t
+    __stack() const
+    { return _M_stack; }
+    
+    virtual void __write(FILE* __f) const = 0;
+
+  protected:
+    __stack_t _M_stack;
+    bool _M_valid;
+  };
+
+
+  /** @brief Base class for a line in the stack table.  */
+  template<typename __object_info>
+    class __stack_info_base
+    {
+    public:
+      __stack_info_base() { }
+      __stack_info_base(const __object_info& __info) = 0;
+      virtual ~__stack_info_base() {}
+      void __merge(const __object_info& __info) = 0;
+      virtual float __magnitude() const = 0;
+      virtual const char* __get_id() const = 0;
+    };
 
 } // namespace __gnu_profile
-#endif /* PROFCXX_PROFILER_NODE_H__ */
+#endif /* _GLIBCXX_PROFILE_PROFILER_NODE_H */