Challenge - 5 Problems
Flask Profiling Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Flask profiling snippet?
Consider this Flask app snippet using the built-in Werkzeug profiler middleware. What will be the visible effect when accessing the '/' route in a browser?
Flask
from flask import Flask from werkzeug.middleware.profiler import ProfilerMiddleware app = Flask(__name__) app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30]) @app.route('/') def index(): return 'Hello, profiling!' if __name__ == '__main__': app.run(debug=True)
Attempts:
2 left
💡 Hint
ProfilerMiddleware wraps the app and prints profiling info to the console, not the browser.
✗ Incorrect
ProfilerMiddleware adds profiling output to the server console logs, while the browser still receives the normal response.
📝 Syntax
intermediate2:00remaining
Which option correctly enables Flask profiling with cProfile?
You want to profile your Flask app using Python's cProfile module. Which code snippet correctly runs the app with profiling enabled?
Attempts:
2 left
💡 Hint
cProfile.run() takes a string with the code to run.
✗ Incorrect
Option D correctly calls cProfile.run() with the string to run the Flask app. Other options misuse cProfile or Flask parameters.
🔧 Debug
advanced2:00remaining
Why does this Flask profiling setup not show any profiling output?
You added this code to profile your Flask app but see no profiling output in the console. What is the likely cause?
Flask
from flask import Flask from werkzeug.middleware.profiler import ProfilerMiddleware app = Flask(__name__) @app.route('/') def index(): return 'Hello!' if __name__ == '__main__': app.wsgi_app = ProfilerMiddleware(app.wsgi_app) app.run()
Attempts:
2 left
💡 Hint
Check the order of statements in the main block.
✗ Incorrect
app.run() starts the server and blocks, so code after it is never executed. ProfilerMiddleware must wrap the app before running.
❓ state_output
advanced2:00remaining
What is the effect of adding restrictions=[10] to ProfilerMiddleware?
Given this Flask app snippet, what will be the effect of the restrictions parameter?
Flask
from flask import Flask from werkzeug.middleware.profiler import ProfilerMiddleware app = Flask(__name__) app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[10]) @app.route('/') def index(): return 'Restricted profiling' if __name__ == '__main__': app.run()
Attempts:
2 left
💡 Hint
restrictions controls how many lines of profiling stats are printed.
✗ Incorrect
The restrictions parameter limits the number of lines shown in the profiling report to the top N functions.
🧠 Conceptual
expert3:00remaining
Which profiling approach best isolates Flask route performance without external noise?
You want to profile only the execution time of a specific Flask route handler function, excluding middleware and server overhead. Which approach is best?
Attempts:
2 left
💡 Hint
Think about isolating only the route function's execution time.
✗ Incorrect
A custom decorator measuring time inside the route function isolates its performance without external overhead.