]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ProfStats.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / ProfStats.cc
index 8ea82a64d5d747462bd4190bd54158780850e557..7ed97b69438e5634a026842b48ef4020afd76459 100644 (file)
@@ -1,44 +1,20 @@
-
 /*
- * $Id$
- *
- * 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"
 
 #if USE_XPROF_STATS
 
-#include "CacheManager.h"
 #include "event.h"
+#include "mgr/Registration.h"
+#include "profiler/Profiler.h"
 #include "SquidMath.h"
 #include "Store.h"
 
@@ -86,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);
@@ -100,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;
@@ -153,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;
 
@@ -195,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;
@@ -270,8 +247,7 @@ xprof_chk_overhead(int samples)
 static void
 xprofRegisterWithCacheManager(void)
 {
-    CacheManager::GetInstance()->
-    registerAction("cpu_profile", "CPU Profiling Stats", xprof_summary, 0, 1);
+    Mgr::RegisterAction("cpu_profile", "CPU Profiling Stats", xprof_summary, 0, 1);
 }
 
 // FIXME:
@@ -298,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;
@@ -332,3 +308,4 @@ xprof_event(void *data)
 }
 
 #endif /* USE_XPROF_STATS */
+