Bird
0
0

You want to profile only the slowest 5 functions in your Flask app and save the results to files in a directory named 'profile'. Which code snippet correctly achieves this?

hard📝 Application Q15 of 15
Flask - Performance Optimization
You want to profile only the slowest 5 functions in your Flask app and save the results to files in a directory named 'profile'. Which code snippet correctly achieves this?
Afrom werkzeug.middleware.profiler import ProfilerMiddleware app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[5], profile_dir='./profile')
Bfrom werkzeug.middleware.profiler import ProfilerMiddleware app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[5], profile_dir='.')
Cfrom werkzeug.middleware.profiler import ProfilerMiddleware app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[5], profile_dir='profile.log')
Dfrom werkzeug.middleware.profiler import ProfilerMiddleware app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[5], profile_dir=None)
Step-by-Step Solution
Solution:
  1. Step 1: Understand restrictions parameter

    restrictions=[5] limits output to slowest 5 functions.
  2. Step 2: Set profile_dir correctly

    profile_dir must be a directory path, not a file name, to save profile files.
  3. Step 3: Choose correct directory path

    './profile' is a directory path suitable for saving logs.
  4. Final Answer:

    from werkzeug.middleware.profiler import ProfilerMiddleware app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[5], profile_dir='./profile') -> Option A
  5. Quick Check:

    restrictions=5 + directory path = from werkzeug.middleware.profiler import ProfilerMiddleware app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[5], profile_dir='./profile') [OK]
Quick Trick: profile_dir must be a folder, restrictions limits slowest funcs [OK]
Common Mistakes:
MISTAKES
  • Using file name instead of directory for profile_dir
  • Setting profile_dir to None disables saving
  • Misunderstanding restrictions parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes