input: Write a function that creates an `Environment` object capable of executing and analyzing Python code. The environment should include predefined global variables and functions, and have the ability to add additional global variables. It should also capture and display output from executed code through a `stdout` object.
  
  assert Environment("/path/to/dir").execute("example.py", "print('Hello, World!')")=={'emitted': [{'type': 'print', 'time': 0, 'parts': [{'type': 'str', 'str': 'Hello, World!'}]}], 'defines': {}, 'start_time': 0, 'end_time': 0, 'exec_time': 0, 'with_subexpressions': False, 'filename': 'example.py', 'content': 'print(\'Hello, World!\')'}
  assert Environment("/path/to/dir").analyze("example.py", "a = 10; print(a)")=={'variables_used': ['a'], 'variables_set': ['a'], 'imports': []}
  assert Environment("/path/to/dir").globals["print"], jsonify_print
  assert add_global("new_global_var", 42)
output: 
  class Environment:
      def __init__(self, directory):
          self.directory = directory
          self.globals = {"print": jsonify_print}
  
      def execute(self, filename, content):
          import io
          import time
          from contextlib import redirect_stdout
  
          stdout = io.StringIO()
          start_time = time.time()
          with redirect_stdout(stdout):
              exec(content, self.globals)
          end_time = time.time()
          exec_time = end_time - start_time
  
          emitted = []
          for line in stdout.getvalue().splitlines():
              emitted.append({'type': 'print', 'time': 0, 'parts': [{'type': 'str', 'str': line}]})
  
          return {
              'emitted': emitted,
              'defines': {},
              'start_time': start_time,
              'end_time': end_time,
              'exec_time': exec_time,
              'with_subexpressions': False,
              'filename': filename,
              'content': content
          }
  
      def analyze(self, filename, content):
          tree = ast.parse(content)
          analyzer = Analyzer()
          analyzer.visit(tree)
          return {
              'variables_used': analyzer.variables_used,
              'variables_set': analyzer.variables_set,
              'imports': analyzer.imports
          }
  
      def add_global(self, name, value):
          self.globals[name] = value
  