bpo-33944: site: Add site-packages tracing in verbose mode (GH-12110)

diff --git a/Lib/site.py b/Lib/site.py
index e981a14..544306c 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -88,6 +88,11 @@
 USER_BASE = None
 
 
+def _trace(message):
+    if sys.flags.verbose:
+        print(message, file=sys.stderr)
+
+
 def makepath(*paths):
     dir = os.path.join(*paths)
     try:
@@ -156,6 +161,7 @@
     else:
         reset = False
     fullname = os.path.join(sitedir, name)
+    _trace(f"Processing .pth file: {fullname!r}")
     try:
         f = io.TextIOWrapper(io.open_code(fullname))
     except OSError:
@@ -190,6 +196,7 @@
 def addsitedir(sitedir, known_paths=None):
     """Add 'sitedir' argument to sys.path if missing and handle .pth files in
     'sitedir'"""
+    _trace(f"Adding directory: {sitedir!r}")
     if known_paths is None:
         known_paths = _init_pathinfo()
         reset = True
@@ -310,6 +317,7 @@
     """
     # get the per user site-package path
     # this call will also make sure USER_BASE and USER_SITE are set
+    _trace("Processing user site-packages")
     user_site = getusersitepackages()
 
     if ENABLE_USER_SITE and os.path.isdir(user_site):
@@ -354,6 +362,7 @@
 
 def addsitepackages(known_paths, prefixes=None):
     """Add site-packages to sys.path"""
+    _trace("Processing global site-packages")
     for sitedir in getsitepackages(prefixes):
         if os.path.isdir(sitedir):
             addsitedir(sitedir, known_paths)
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index 957e7a4..9f4a8bc 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -13,6 +13,7 @@
 import builtins
 import encodings
 import glob
+import io
 import os
 import re
 import shutil
@@ -320,6 +321,14 @@
             mock_addsitedir.assert_not_called()
             self.assertFalse(known_paths)
 
+    def test_trace(self):
+        message = "bla-bla-bla"
+        for verbose, out in (True, message + "\n"), (False, ""):
+            with mock.patch('sys.flags', mock.Mock(verbose=verbose)), \
+                    mock.patch('sys.stderr', io.StringIO()):
+                site._trace(message)
+                self.assertEqual(sys.stderr.getvalue(), out)
+
 
 class PthFile(object):
     """Helper class for handling testing of .pth files"""