]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ProfStats.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / ProfStats.cc
index 1e593ea2fb42d40a8f2e9313271bfcaab8ad23eb..7ed97b69438e5634a026842b48ef4020afd76459 100644 (file)
@@ -1,42 +1,21 @@
-
 /*
- * $Id: ProfStats.cc,v 1.7 2006/05/29 00:15:01 robertc Exp $
- *
- * DEBUG: section 81     CPU Profiling Routines
- * AUTHOR: Andres Kroonmaa
- *
- * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from the
- *  Internet community.  Development is led by Duane Wessels of the
- *  National Laboratory for Applied Network Research and funded by the
- *  National Science Foundation.  Squid is Copyrighted (C) 1998 by
- *  the Regents of the University of California.  Please see the
- *  COPYRIGHT file for full details.  Squid incorporates software
- *  developed and/or copyrighted by other sources.  Please see the
- *  CREDITS file for full details.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *  
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *  
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
  *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
+/* DEBUG: section 81    CPU Profiling Routines */
+
 #include "squid.h"
-#include "CacheManager.h"
 
-#ifdef USE_XPROF_STATS
+#if USE_XPROF_STATS
+
+#include "event.h"
+#include "mgr/Registration.h"
+#include "profiler/Profiler.h"
+#include "SquidMath.h"
 #include "Store.h"
 
 /* Private stuff */
@@ -83,12 +62,15 @@ xprof_move(xprof_stats_data * head, xprof_stats_data * hist)
 }
 
 static int
-xprof_comp(xprof_stats_node ** ii, xprof_stats_node ** jj)
+xprof_comp(const void *A, const void *B)
 {
-    if ((*ii)->hist.summ < (*jj)->hist.summ)
+    const xprof_stats_node *ii = *(static_cast<const xprof_stats_node * const *>(A));
+    const xprof_stats_node *jj = *(static_cast<const xprof_stats_node * const *>(B));
+
+    if (ii->hist.summ < jj->hist.summ)
         return (1);
 
-    if ((*ii)->hist.summ > (*jj)->hist.summ)
+    if (ii->hist.summ > jj->hist.summ)
         return (-1);
 
     return (0);
@@ -97,13 +79,11 @@ xprof_comp(xprof_stats_node ** ii, xprof_stats_node ** jj)
 static void
 xprof_sorthist(TimersArray * xprof_list)
 {
-    int i;
-
-    for (i = 0; i < XPROF_LAST; i++) {
+    for (int i = 0; i < XPROF_LAST; ++i) {
         sortlist[i] = xprof_list[i];
     }
 
-    qsort(&sortlist[XPROF_hash_lookup], XPROF_LAST - XPROF_hash_lookup, sizeof(xprof_stats_node *), (QS *) xprof_comp);
+    qsort(&sortlist[XPROF_PROF_UNACCOUNTED+1], XPROF_LAST - XPROF_PROF_UNACCOUNTED+1, sizeof(xprof_stats_node *), xprof_comp);
 }
 
 static double time_frame;
@@ -120,7 +100,7 @@ xprof_show_item(StoreEntry * sentry, const char *name, xprof_stats_data * hist)
                       hist->count ? hist->summ / hist->count : 0,
                       hist->worst,
                       hist->count / time_frame,
-                      dpercent((double) hist->summ, (double) hist->delta));
+                      Math::doublePercent((double) hist->summ, (double) hist->delta));
 }
 
 static void
@@ -150,7 +130,7 @@ xprof_summary_item(StoreEntry * sentry, char const *descr, TimersArray * list)
     storeAppendPrintf(sentry,
                       "Probe Name\t  Events\t cumulated time \t best case \t average \t worst case\t Rate / sec \t %% in int\n");
 
-    for (i = 0; i < XPROF_LAST; i++) {
+    for (i = 0; i < XPROF_LAST; ++i) {
         if (!hist[i]->name)
             continue;
 
@@ -192,10 +172,10 @@ xprof_average(TimersArray ** list, int secs)
 
     now = get_tick();
 
-    for (i = 0; i < XPROF_LAST; i++) {
+    for (i = 0; i < XPROF_LAST; ++i) {
         hist[i]->name = head[i]->name;
         hist[i]->accu.summ += head[i]->accu.summ;
-        hist[i]->accu.count += head[i]->accu.count;    /* accumulate multisec */
+        hist[i]->accu.count += head[i]->accu.count; /* accumulate multisec */
 
         if (!hist[i]->accu.best)
             hist[i]->accu.best = head[i]->accu.best;
@@ -264,6 +244,15 @@ xprof_chk_overhead(int samples)
     }
 }
 
+static void
+xprofRegisterWithCacheManager(void)
+{
+    Mgr::RegisterAction("cpu_profile", "CPU Profiling Stats", xprof_summary, 0, 1);
+}
+
+// FIXME:
+// this gets colled once per event. This doesn't seem to make much sense,
+// does it?
 static hrtime_t now;
 static void
 xprof_Init(void)
@@ -274,12 +263,8 @@ xprof_Init(void)
     xprof_delta = xprof_verystart = xprof_start_t = now;
 
     xprof_inited = 1;
-}
 
-void
-xprofRegisterWithCacheManager(CacheManager & manager)
-{
-    manager.registerAction("cpu_profile", "CPU Profiling Stats", xprof_summary, 0, 1);
+    xprofRegisterWithCacheManager(); //moved here so it's not double-init'ed
 }
 
 void
@@ -289,7 +274,7 @@ xprof_event(void *data)
     xprof_Init();
     xprof_delta = now - xprof_start_t;
     xprof_start_t = now;
-    xprof_events++;
+    ++xprof_events;
 
     if (!xprof_average_delta)
         xprof_average_delta = xprof_delta;
@@ -297,8 +282,6 @@ xprof_event(void *data)
     if (xprof_average_delta > (xprof_delta >> 1))
         xprof_average_delta = xprof_average_delta - (xprof_average_delta >> 8) + (xprof_delta >> 8);
 
-    xprof_nesting++;
-
     xprof_chk_overhead(2);
 
     xprof_average(&xprof_stats_avg24hour, 24 * 3600);
@@ -321,9 +304,8 @@ xprof_event(void *data)
 
     xprof_chk_overhead(30);
 
-    xprof_nesting--;
-
     eventAdd("cpuProfiling", xprof_event, NULL, 1.0, 1);
 }
 
 #endif /* USE_XPROF_STATS */
+