Class: Profiler::MCP::Tools::GetProfileAjax
- Inherits:
-
Object
- Object
- Profiler::MCP::Tools::GetProfileAjax
- Defined in:
- lib/profiler/mcp/tools/get_profile_ajax.rb
Class Method Summary collapse
Class Method Details
.call(params) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/profiler/mcp/tools/get_profile_ajax.rb', line 9 def self.call(params) token = params["token"] unless token return [{ type: "text", text: "Error: token parameter is required" }] end storage = MCP::SlaveSupport.resolve_storage(params) profile = if token == "latest" storage.list(limit: 1).first else storage.load(token) end unless profile return [{ type: "text", text: "Profile not found: #{token}" }] end ajax_data = profile.collector_data("ajax") unless ajax_data && ajax_data["total_requests"].to_i > 0 return [{ type: "text", text: "No AJAX requests found in this profile" }] end [{ type: "text", text: format_ajax(profile, ajax_data) }] end |
.format_ajax(profile, ajax_data) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/profiler/mcp/tools/get_profile_ajax.rb', line 35 def self.format_ajax(profile, ajax_data) lines = [] lines << "# AJAX Analysis: #{profile.token}\n" lines << "**Request:** #{profile.method} #{profile.path}" lines << "**Total AJAX Requests:** #{ajax_data['total_requests']}" lines << "**Total Duration:** #{ajax_data['total_duration'].round(2)} ms\n" if ajax_data["by_method"] && !ajax_data["by_method"].empty? lines << "## By Method" ajax_data["by_method"].each { |method, count| lines << "- **#{method}**: #{count}" } lines << "" end if ajax_data["by_status"] && !ajax_data["by_status"].empty? lines << "## By Status" ajax_data["by_status"].each { |status, count| lines << "- **#{status}**: #{count}" } lines << "" end if ajax_data["requests"] && !ajax_data["requests"].empty? lines << "## Request List" ajax_data["requests"].each_with_index do |req, index| lines << "\n### Request #{index + 1}" lines << "- **Method:** #{req['method']}" lines << "- **Path:** #{req['path']}" lines << "- **Status:** #{req['status']}" lines << "- **Duration:** #{req['duration'].round(2)} ms" lines << "- **Token:** #{req['token']}" if req['token'] lines << "- **Started At:** #{req['started_at']}" if req['started_at'] end lines << "" end lines.join("\n") end |