How Cool Request’s New Trace Feature Lets You Measure Any Method’s Execution Time
The latest update of the Cool Request IDEA plugin introduces a powerful Trace function that automatically records execution times for any method—including Spring @Scheduled and xxl‑job tasks—offers customizable latency coloring, MyBatis SQL timing, call‑count indicators, and scriptable environment variables for seamless token handling and JSON parsing.
Introduction
The Cool Request plugin for IntelliJ IDEA has received a major update that adds a comprehensive Trace capability, allowing developers to measure the execution time of arbitrary methods directly within the IDE.
What Is Cool Request?
Cool Request is an interface‑testing plugin for IDEA. Besides basic HTTP requests, it supports reflection calls that can bypass interceptors, making it useful for invoking methods annotated with @Scheduled or managed by xxl‑job.
What Is Trace?
Trace records the execution duration of any non‑Java package method (Java packages are excluded to avoid instability). When enabled, Trace automatically starts from the controller method of a request. The depth setting controls how deep the tracing goes:
Depth 1 – only the controller method.
Depth 2 – controller and its direct callees.
Depth 3 – controller, its callees, and their callees, and so on.
If a method is invoked via an interface, static analysis may not resolve the concrete implementation, so manual addition of methods is possible via right‑click.
Automatic MyBatis Function Tracing
Trace can selectively monitor MyBatis execution functions—the final methods that run the SQL statements. The UI shows the exact time taken, e.g., a query completing in 7 ms. Users familiar with the source code can add any method they wish to trace.
Displaying Call Counts
The left‑hand side of the trace panel shows a "+100" indicator, meaning the method was called 100 times during the trace. Currently, per‑method latency is not aggregated.
Customizable Latency Coloring
Users can set a threshold (e.g., 5 ms) in the settings; any method exceeding this threshold is highlighted in red, making performance bottlenecks instantly visible.
Scriptable Environment Operations
When a request requires authentication tokens or other headers, developers can write a script under the request to fetch the token, store it in an environment variable, and automatically attach it to subsequent requests. This eliminates manual token handling.
The response body is typically JSON; the script environment also supports JSON parsing, allowing easy extraction of fields.
Calling Project Classes from Scripts
Cool Request can invoke any class available in the project, including third‑party libraries such as Gson, Fastjson, or Spring Boot’s ObjectMapper. This enables powerful, in‑IDE data processing without leaving the IDE.
Code Example
public void handlerResponse(ILog log, HTTPResponse response, IEnv env) {
String body = new String(response.getResponseBody());
log.println(body);
User user = JSON.parseObject(body, User.class);
log.println(user.getAge() + "");
}Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Tech Enthusiast
Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
