From 84ae60a3b34d92930a74e9207bf39e6335e307a0 Mon Sep 17 00:00:00 2001
From: Mnikolenko Productengine <mnikolenko@productengine.com>
Date: Fri, 16 Jul 2021 16:32:12 +0300
Subject: SL-15581 Add the function to get median FPS

---
 indra/llcommon/lltracerecording.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

(limited to 'indra/llcommon')

diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h
index d0b4a842a6..2af5273d70 100644
--- a/indra/llcommon/lltracerecording.h
+++ b/indra/llcommon/lltracerecording.h
@@ -580,6 +580,31 @@ namespace LLTrace
 			return typename RelatedTypes<T>::fractional_t(getPeriodMeanPerSec(static_cast<const StatType<CountAccumulator>&>(stat), num_periods));
 		}
 
+        template <typename T>
+        typename RelatedTypes<typename T::value_t>::fractional_t getPeriodMedianPerSec(const StatType<T>& stat, S32 num_periods = S32_MAX)
+        {
+            num_periods = llmin(num_periods, getNumRecordedPeriods());
+
+            std::vector <typename RelatedTypes<typename T::value_t>::fractional_t> buf;
+            for (S32 i = 1; i <= num_periods; i++)
+            {
+                Recording& recording = getPrevRecording(i);
+                if (recording.getDuration() > (F32Seconds)0.f)
+                {
+                    buf.push_back(recording.getPerSec(stat));
+                }
+            }
+            std::sort(buf.begin(), buf.end());
+
+            return typename RelatedTypes<T>::fractional_t((buf.size() % 2 == 0) ? (buf[buf.size() / 2 - 1] + buf[buf.size() / 2]) / 2 : buf[buf.size() / 2]);
+        }
+
+        template<typename T>
+        typename RelatedTypes<T>::fractional_t getPeriodMedianPerSec(const CountStatHandle<T>& stat, S32 num_periods = S32_MAX)
+        {
+            return typename RelatedTypes<T>::fractional_t(getPeriodMedianPerSec(static_cast<const StatType<CountAccumulator>&>(stat), num_periods));
+        }
+
 		//
 		// PERIODIC STANDARD DEVIATION
 		//
-- 
cgit v1.2.3


From b42e468b48471e29387b660e30ea3b6cc3a8979a Mon Sep 17 00:00:00 2001
From: Mnikolenko Productengine <mnikolenko@productengine.com>
Date: Mon, 14 Mar 2022 20:40:39 +0200
Subject: merge fix

---
 indra/llcommon/tests/llprocess_test.cpp | 66 ++++++++++-----------------------
 1 file changed, 20 insertions(+), 46 deletions(-)

(limited to 'indra/llcommon')

diff --git a/indra/llcommon/tests/llprocess_test.cpp b/indra/llcommon/tests/llprocess_test.cpp
index 54a1c55a2d..81449b4a42 100644
--- a/indra/llcommon/tests/llprocess_test.cpp
+++ b/indra/llcommon/tests/llprocess_test.cpp
@@ -356,24 +356,17 @@ namespace tut
 
         // Create a script file in a temporary place.
         NamedTempFile script("py",
-			"from __future__ import print_function" EOL
+            "from __future__ import print_function" EOL
             "import sys" EOL
             "import time" EOL
             EOL
             "time.sleep(2)" EOL
-<<<<<<< HEAD
             "print('stdout after wait',file=sys.stdout)" EOL
             "sys.stdout.flush()" EOL
             "time.sleep(2)" EOL
             "print('stderr after wait',file=sys.stderr)" EOL
-=======
-            "print('stdout after wait', file=sys.stdout)" EOL
-            "sys.stdout.flush()" EOL
-            "time.sleep(2)" EOL
-            "print('stderr after wait', file=sys.stderr)" EOL
->>>>>>> 6ca09a94554ec01f5c94ec60fffd01d7e33f3546
             "sys.stderr.flush()" EOL
-            );
+        );
 
         // Arrange to track the history of our interaction with child: what we
         // fetched, which pipe it came from, how many tries it took before we
@@ -869,11 +862,8 @@ namespace tut
         set_test_name("'bogus' test");
         CaptureLog recorder;
         PythonProcessLauncher py(get_test_name(),
-<<<<<<< HEAD
-                                 "from __future__ import print_function\n"
-=======
->>>>>>> 6ca09a94554ec01f5c94ec60fffd01d7e33f3546
-                                 "print('Hello world')\n");
+            "from __future__ import print_function\n"
+            "print('Hello world')\n");
         py.mParams.files.add(LLProcess::FileParam("bogus"));
         py.mPy = LLProcess::create(py.mParams);
         ensure("should have rejected 'bogus'", ! py.mPy);
@@ -888,11 +878,8 @@ namespace tut
         // Replace this test with one or more real 'file' tests when we
         // implement 'file' support
         PythonProcessLauncher py(get_test_name(),
-<<<<<<< HEAD
-                                 "from __future__ import print_function\n"
-=======
->>>>>>> 6ca09a94554ec01f5c94ec60fffd01d7e33f3546
-                                 "print('Hello world')\n");
+            "from __future__ import print_function\n"
+            "print('Hello world')\n");
         py.mParams.files.add(LLProcess::FileParam());
         py.mParams.files.add(LLProcess::FileParam("file"));
         py.mPy = LLProcess::create(py.mParams);
@@ -907,11 +894,8 @@ namespace tut
         // implement 'tpipe' support
         CaptureLog recorder;
         PythonProcessLauncher py(get_test_name(),
-<<<<<<< HEAD
-                                 "from __future__ import print_function\n"
-=======
->>>>>>> 6ca09a94554ec01f5c94ec60fffd01d7e33f3546
-                                 "print('Hello world')\n");
+            "from __future__ import print_function\n"
+            "print('Hello world')\n");
         py.mParams.files.add(LLProcess::FileParam());
         py.mParams.files.add(LLProcess::FileParam("tpipe"));
         py.mPy = LLProcess::create(py.mParams);
@@ -928,11 +912,8 @@ namespace tut
         // implement 'npipe' support
         CaptureLog recorder;
         PythonProcessLauncher py(get_test_name(),
-<<<<<<< HEAD
-                                 "from __future__ import print_function\n"
-=======
->>>>>>> 6ca09a94554ec01f5c94ec60fffd01d7e33f3546
-                                 "print('Hello world')\n");
+            "from __future__ import print_function\n"
+            "print('Hello world')\n");
         py.mParams.files.add(LLProcess::FileParam());
         py.mParams.files.add(LLProcess::FileParam());
         py.mParams.files.add(LLProcess::FileParam("npipe"));
@@ -1008,24 +989,20 @@ namespace tut
     {
         set_test_name("get*Pipe() validation");
         PythonProcessLauncher py(get_test_name(),
-<<<<<<< HEAD
-                                 "from __future__ import print_function\n"
-                                 "print('this output is expected')\n");
-=======
-                                 "print('this output is expected)'\n");
->>>>>>> 6ca09a94554ec01f5c94ec60fffd01d7e33f3546
+            "from __future__ import print_function\n"
+            "print('this output is expected')\n");
         py.mParams.files.add(LLProcess::FileParam("pipe")); // pipe for  stdin
         py.mParams.files.add(LLProcess::FileParam());       // inherit stdout
         py.mParams.files.add(LLProcess::FileParam("pipe")); // pipe for stderr
         py.run();
         TEST_getPipe(*py.mPy, getWritePipe, getOptWritePipe,
-                     LLProcess::STDIN,   // VALID
-                     LLProcess::STDOUT,  // NOPIPE
-                     LLProcess::STDERR); // BADPIPE
+            LLProcess::STDIN,   // VALID
+            LLProcess::STDOUT,  // NOPIPE
+            LLProcess::STDERR); // BADPIPE
         TEST_getPipe(*py.mPy, getReadPipe,  getOptReadPipe,
-                     LLProcess::STDERR,  // VALID
-                     LLProcess::STDOUT,  // NOPIPE
-                     LLProcess::STDIN);  // BADPIPE
+            LLProcess::STDERR,  // VALID
+            LLProcess::STDOUT,  // NOPIPE
+            LLProcess::STDIN);  // BADPIPE
     }
 
     template<> template<>
@@ -1152,11 +1129,8 @@ namespace tut
     {
         set_test_name("ReadPipe \"eof\" event");
         PythonProcessLauncher py(get_test_name(),
-<<<<<<< HEAD
-                                 "from __future__ import print_function\n"
-=======
->>>>>>> 6ca09a94554ec01f5c94ec60fffd01d7e33f3546
-                                 "print('Hello from Python!')\n");
+            "from __future__ import print_function\n"
+            "print('Hello from Python!')\n");
         py.mParams.files.add(LLProcess::FileParam()); // stdin
         py.mParams.files.add(LLProcess::FileParam("pipe")); // stdout
         py.launch();
-- 
cgit v1.2.3