When a Perl process pins a CPU core at 100%, the cause is usually buried in a hot code path. We profiled a live, unmodified Perl process with OpenResty XRay and traced the CPU usage to regex matching inside Services::Processor::scan (line 14, Dancer2 framework) — specifically the Perl_fbm_instr C function that implements Fast Boyer-Moore string search.

This walkthrough shows the complete profiling process — from observing the Perl high CPU usage to pinpointing the exact source file and line number responsible.

Observing 100% CPU Usage in a Perl Process

The top command shows a Perl process consuming 100% of a CPU core.

top command showing a Perl process consuming 100% of a CPU core

The ps command confirms this is the standard Perl binary executable shipped with the Linux distribution.

ps command displaying the full command line of the Perl process

Profiling Perl CPU Usage with OpenResty XRay

We use OpenResty XRay to analyze this unmodified process in real time — no code changes, no restarts required. In the web console, navigate to Guided Analysis and select High CPU Usage as the problem type. OpenResty XRay auto-discovers running applications on the target machine. Select the Perl application from the dropdown.

OpenResty XRay auto-discovering Go, Python, and Perl applications on the target machine

Select the specific process consuming 99% CPU — the same one we observed in top.

Selecting PID 868535 (perl) at CPU 99% and RSS 159MB for analysis

OpenResty XRay can analyze multiple language levels at the same time. We keep both Perl and C selected.

Language level set to Perl and C, maximum analysis time 300 seconds

After starting the analysis, the system keeps performing different rounds of analysis. Two rounds are enough for this case.

C-Level CPU Flame Graph Analysis

We can see it automatically creates a report.

Automatically generated analysis report

This is the hottest C code path for CPU.

Hottest C code path for CPU in the analysis report

This is a C function named Perl_fbm_instr in the Perl VM runtime. It uses the FBM (Fast Boyer-Moore) algorithm to search strings for regular expression matching.

Perl_fbm_instr function highlighted as the top CPU consumer

The C function here indicates that it is indeed performing regular expression matching.

C function in the call stack indicating regex matching

The perl_run function means that the Perl VM is currently executing Perl code.

perl_run function indicating Perl VM code execution

Perl-Level CPU Flame Graph Analysis

After checking the hottest C code path, we then look at the hottest Perl code paths.

Switching to view the hottest Perl code paths

This C function is still Perl_fbm_instr we just discussed.

Perl_fbm_instr C function in the Perl-level analysis

This is a Perl function named scan. It is part of the business logic and it’s in the Services::Processor package.

Services::Processor::scan Perl function identified as the hotspot

These two caller Perl functions give more context in the business-level code base.

Caller Perl functions providing business-logic context

And this Perl function belongs to the Dancer2 Perl web framework.

Dancer2 web framework function in the call chain

This is the second hottest Perl code path.

Second hottest Perl code path

The only difference is this Glibc function, memchr. It searches a character in a memory buffer using the Intel AVX2 instruction set. It is also part of the regular expression matching operation. The Perl function call chain is exactly the same.

memchr function for AVX2 string search in the second code path

Pinpointing the Perl Source File and Line Number

Click “More” to see details about the #1 hottest Perl code path.

Clicking More to see detailed analysis of the hottest code path

The code path was automatically derived from this Perl-land CPU flame graph.

Perl-level CPU flame graph generated by OpenResty XRay

Below are more detailed explanations and suggestions regarding the current issue.

Detailed explanations and suggestions for the CPU hotspot

It talks about the Perl_fbm_instr C function we saw earlier.

Report discussing the Perl_fbm_instr C function

It mentions that this function uses the “Fast Boyer-Moore” string search algorithm.

Report mentioning the Fast Boyer-Moore string search algorithm

And it also covers the Perl function scan.

Report identifying the Perl scan function

It mentions that this function is in the Services::Processor package.

Report showing the Services::Processor package

Hover the mouse over the green box for the Perl function named scan. We can see the Perl source file of the scan function, and its full path for the Processor.pm file in the tooltip.

Tooltip showing the Perl source file path for the scan function

The Perl source line number is 14.

Perl source line number 14 shown in the flame graph tooltip

Click the icon to copy the full Perl source file path for this function.

Copying the full Perl source file path from the flame graph

Use the vim editor and paste the file path we just copied to look at the corresponding business Perl code. You can use any editor you like.

Opening the Perl source file in vim editor

Go to line 14 as shown in the report tooltip.

Viewing line 14 of the Perl source file

We see that this Perl code line is indeed doing regular expression matching.

Perl source code at line 14 showing regex matching

It is also in the function scan as shown in the report.

The scan function definition in the Perl source file

Automatic Monitoring and Reports

For production workloads, OpenResty XRay monitors processes continuously and generates daily and weekly reports on the Insights page — no manual guided analysis required.

Insights page showing automatic daily report for the Perl application with CPU max 101% and 6 CPU findings including Perl_fbm_instr

FAQ

Why is my Perl process using 100% CPU?

A common cause of Perl high CPU usage is an expensive regex operation in a hot code path. In this case, OpenResty XRay traced the CPU bottleneck to Perl_fbm_instr — the C function implementing Fast Boyer-Moore string search for regex matching — called from Services::Processor::scan at line 14. CPU flame graphs reveal the full call chain from the Dancer2 framework down to the VM-level regex function.

How do I find the Perl code causing high CPU?

Use OpenResty XRay’s guided analysis to generate CPU flame graphs at both the C and Perl levels. The flame graph shows stacked function calls where width represents CPU time. Hover over a function box to see the source file path and line number, then open that file in any editor to inspect the exact code responsible.

Can regex patterns cause high CPU in Perl?

Yes. The Perl VM function Perl_fbm_instr implements Fast Boyer-Moore string search for regex matching, and it was the dominant CPU consumer in this case — appearing as the leaf function in both the #1 and #2 hottest C-land code paths. The associated memchr glibc function (using Intel AVX2 instructions) also contributed to the regex workload.

What is a CPU flame graph for Perl?

A CPU flame graph is a visualization of stacked function calls where the width of each box represents relative CPU time. OpenResty XRay generates both C-level and Perl-level CPU flame graphs, making it possible to trace CPU hotspots from the Perl VM internals (like Perl_fbm_instr) down to the exact Perl source file and line number.

What is OpenResty XRay

OpenResty XRay is a dynamic-tracing product that automatically analyzes your running applications to troubleshoot performance problems, behavioral issues, and security vulnerabilities with actionable suggestions. Under the hood, OpenResty XRay is powered by our Y language targeting various runtimes like Stap+, eBPF+, GDB, and ODB, depending on the contexts.

If you like this tutorial, please subscribe to this blog site and/or our YouTube channel. Thank you!

About The Author

Yichun Zhang (Github handle: agentzh), is the original creator of the OpenResty® open-source project and the CEO of OpenResty Inc..

Yichun is one of the earliest advocates and leaders of “open-source technology”. He worked at many internationally renowned tech companies, such as Cloudflare, Yahoo!. He is a pioneer of “edge computing”, “dynamic tracing” and “machine coding”, with over 22 years of programming and 16 years of open source experience. Yichun is well-known in the open-source space as the project leader of OpenResty®, adopted by more than 40 million global website domains.

OpenResty Inc., the enterprise software start-up founded by Yichun in 2017, has customers from some of the biggest companies in the world. Its flagship product, OpenResty XRay, is a non-invasive profiling and troubleshooting tool that significantly enhances and utilizes dynamic tracing technology. And its OpenResty Edge product is a powerful distributed traffic management and private CDN software product.

As an avid open-source contributor, Yichun has contributed more than a million lines of code to numerous open-source projects, including Linux kernel, Nginx, LuaJIT, GDB, SystemTap, LLVM, Perl, etc. He has also authored more than 60 open-source software libraries.