OSDN Git Service

* testsuite/testsuite_performance.h (__FreeBSD__): Add fake mallinfo.
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / testsuite_performance.h
index b9b76cd..625de57 100644 (file)
 // invalidate any other reasons why the executable file might be covered by
 // the GNU General Public License.
 
-#ifndef _GLIBCPP_PERFORMANCE_H
-#define _GLIBCPP_PERFORMANCE_H
+#ifndef _GLIBCXX_PERFORMANCE_H
+#define _GLIBCXX_PERFORMANCE_H
 
 #include <sys/times.h>
 #include <sys/resource.h>
-#include <malloc.h>
+#include <cstdlib>
 #include <string>
 #include <fstream>
 #include <iomanip>
 
-namespace __gnu_cxx_test
+#ifdef __linux__
+#include <malloc.h>
+#elif defined (__FreeBSD__)
+extern "C"
+{
+  struct mallinfo { int uordblks; };
+  struct mallinfo mallinfo(void)
+    { struct mallinfo m = { (((size_t) sbrk (0) + 1023) / 1024) }; return m; }
+}
+#else
+extern "C"
+{
+  struct mallinfo { int uordblks; };
+  struct mallinfo empty = { 0 };
+  struct mallinfo mallinfo(void) { return empty; }
+}
+#endif
+
+namespace __gnu_test
 {
   class time_counter
   {
@@ -107,6 +125,7 @@ namespace __gnu_cxx_test
     { 
       if (getrusage(who, &rusage_begin) != 0 )
        memset(&rusage_begin, 0, sizeof(rusage_begin));
+      malloc(0); // Needed for some implementations.
       allocation_begin = mallinfo();
     }
     
@@ -120,7 +139,7 @@ namespace __gnu_cxx_test
 
     int
     allocated_memory() const
-    { return allocation_end.arena - allocation_begin.arena; }
+    { return allocation_end.uordblks - allocation_begin.uordblks; }
     
     long 
     hard_page_fault() const
@@ -158,7 +177,7 @@ namespace __gnu_cxx_test
   {
     const char space = ' ';
     const char tab = '\t';
-    const char* name = "libstdc++-v3.performance";
+    const char* name = "libstdc++-v3-performance.sum";
     std::string::const_iterator i = file.begin() + file.find_last_of('/') + 1;
     std::string testname(i, file.end());
 
@@ -172,13 +191,13 @@ namespace __gnu_cxx_test
     out << std::setw(4) << t.real_time() << "r" << space;
     out << std::setw(4) << t.user_time() << "u" << space;
     out << std::setw(4) << t.system_time() << "s" << space;
-    //    out << std::setw(4) << r.allocated_memory() << "mem" << space;
+    out << std::setw(4) << r.allocated_memory() << "mem" << space;
     out << std::setw(4) << r.hard_page_fault() << "pf" << space;
     
     out << std::endl;
     out.close();
   }
-}; // namespace __gnu_cxx_test
+}; // namespace __gnu_test
 
-#endif // _GLIBCPP_PERFORMANCE_H
+#endif // _GLIBCXX_PERFORMANCE_H