]> git.lizzy.rs Git - minetest.git/blobdiff - src/util/timetaker.cpp
Fix memory leaks due to messed up memory handling for particles as well as their...
[minetest.git] / src / util / timetaker.cpp
index 42a248dc657571e8d8fecc827be623ed3980faa6..dcf07dc0d02f35df6912a6245fe269227b76f152 100644 (file)
@@ -1,6 +1,6 @@
 /*
 Minetest
-Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
@@ -23,19 +23,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "../log.h"
 #include <ostream>
 
-TimeTaker::TimeTaker(const char *name, u32 *result)
+TimeTaker::TimeTaker(const char *name, u32 *result, TimePrecision prec)
 {
        m_name = name;
        m_result = result;
        m_running = true;
-       m_time1 = getTimeMs();
+       m_precision = prec;
+       m_time1 = getTime(prec);
 }
 
 u32 TimeTaker::stop(bool quiet)
 {
        if(m_running)
        {
-               u32 time2 = getTimeMs();
+               u32 time2 = getTime(m_precision);
                u32 dtime = time2 - m_time1;
                if(m_result != NULL)
                {
@@ -43,8 +44,17 @@ u32 TimeTaker::stop(bool quiet)
                }
                else
                {
-                       if(quiet == false)
-                               infostream<<m_name<<" took "<<dtime<<"ms"<<std::endl;
+                       if (!quiet) {
+                               static const char* const units[] = {
+                                       "s"  /* PRECISION_SECONDS */,
+                                       "ms" /* PRECISION_MILLI */,
+                                       "us" /* PRECISION_MICRO */,
+                                       "ns" /* PRECISION_NANO */,
+                               };
+                               infostream << m_name << " took "
+                                          << dtime << units[m_precision]
+                                          << std::endl;
+                       }
                }
                m_running = false;
                return dtime;
@@ -52,9 +62,9 @@ u32 TimeTaker::stop(bool quiet)
        return 0;
 }
 
-u32 TimeTaker::getTime()
+u32 TimeTaker::getTimerTime()
 {
-       u32 time2 = getTimeMs();
+       u32 time2 = getTime(m_precision);
        u32 dtime = time2 - m_time1;
        return dtime;
 }