docstr: Generate a .c file for a separate extension module that calls the
  module init function of the original module.  This makes sure that the
  PGO profiler sees the correct .o file of the final module, but it still
  allows us to import the module under a different name for profiling,
  before recompiling it into the PGO optimised module.  Overwriting and
  reimporting the same shared library is not portable.
docstr_tok: ["Generate","a",".c","file","for","a","separate","extension","module","that","calls","the","module","init","function","of","the","original","module",".","This","makes","sure","that","the","PGO","profiler","sees","the","correct",".o","file","of","the","final","module",",","but","it","still","allows","us","to","import","the","module","under","a","different","name","for","profiling",",","before","recompiling","it","into","the","PGO","optimised","module",".","Overwriting","and","reimporting","the","same","shared","library","is","not","portable","."]
code: def _profile_pgo_wrapper(self, extension, lib_dir):
      """
      Generate a .c file for a separate extension module that calls the
      module init function of the original module.  This makes sure that the
      PGO profiler sees the correct .o file of the final module, but it still
      allows us to import the module under a different name for profiling,
      before recompiling it into the PGO optimised module.  Overwriting and
      reimporting the same shared library is not portable.
      """
      extension = copy.copy(
          extension
      )  # shallow copy, do not modify sources in place!
      module_name = extension.name
      pgo_module_name = "_pgo_" + module_name
      pgo_wrapper_c_file = os.path.join(lib_dir, pgo_module_name + ".c")
      with io.open(pgo_wrapper_c_file, "w", encoding="utf-8") as f:
          f.write(
              textwrap.dedent(
                  """
              #include "Python.h"
              #if PY_MAJOR_VERSION < 3
              extern PyMODINIT_FUNC init%(module_name)s(void);
              PyMODINIT_FUNC init%(pgo_module_name)s(void); /*proto*/
              PyMODINIT_FUNC init%(pgo_module_name)s(void) {
                  PyObject *sys_modules;
                  init%(module_name)s();  if (PyErr_Occurred()) return;
                  sys_modules = PyImport_GetModuleDict();  /* borrowed, no exception, "never" fails */
                  if (sys_modules) {
                      PyObject *module = PyDict_GetItemString(sys_modules, "%(module_name)s");  if (!module) return;
                      PyDict_SetItemString(sys_modules, "%(pgo_module_name)s", module);
                      Py_DECREF(module);
                  }
              }
              #else
              extern PyMODINIT_FUNC PyInit_%(module_name)s(void);
              PyMODINIT_FUNC PyInit_%(pgo_module_name)s(void); /*proto*/
              PyMODINIT_FUNC PyInit_%(pgo_module_name)s(void) {
                  return PyInit_%(module_name)s();
              }
              #endif
              """
                  % {
                      "module_name": module_name,
                      "pgo_module_name": pgo_module_name,
                  }
              )
          )
  
      extension.sources = extension.sources + [
          pgo_wrapper_c_file
      ]  # do not modify in place!
      extension.name = pgo_module_name
  
      self._build_extension(extension, lib_dir, pgo_step_name="gen")
  
      # import and execute module code to generate profile
      so_module_path = os.path.join(
          lib_dir, pgo_module_name + self.so_ext
      )
      load_dynamic(pgo_module_name, so_module_path)
  
imports: from __future__ import absolute_import, print_function
  import io
  import os
  import re
  import sys
  import time
  import copy
  import distutils.log
  import textwrap
  from distutils.core import Distribution, Extension
  from distutils.command.build_ext import build_ext
  from IPython.core import display
  from IPython.core import magic_arguments
  from IPython.core.magic import Magics, magics_class, cell_magic
  from IPython.utils.text import dedent
  from ..Shadow import __version__
  from ..Compiler.Errors import CompileError
  from .Inline import cython_inline, load_dynamic
  from .Dependencies import cythonize
label_desc: Use image node_id 6 for calling the CythonMagics obj's underlying member method code with example usage: obj._profile_pgo_wrapper(extension, lib_dir) without return types