GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf-cpp/docs/perf-paranoid.md at dev · Liteom/perf-cpp

Expand file tree

/

perf-paranoid.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
63 lines (43 loc) · 2.42 KB
/

perf-paranoid.md

Copy path

File metadata and controls

63 lines (43 loc) · 2.42 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

Perf Paranoid

This section explains the perf paranoid setting in Linux, which controls access to performance monitoring features and can restrict unprivileged users from using performance counters.

Understanding Perf Paranoid

The perf paranoid level is defined in /proc/sys/kernel/perf_event_paranoid, with values ranging from highly restrictive to fully permissive:

Value Access Level
-1 No restrictions (full access).
0 Allow normal users access, but no raw tracepoint samples.
1 Allow user and kernel-level profiling (default before Linux 4.6).
>= 2 Only user-level measurements allowed (default since Linux 4.6).

If the setting is too restrictive, you may encounter errors like:

Cannot open perf counter: insufficient access rights to start the counter, 
e.g., profiling a not user-owned process or perf_event_paranoid value too high.

This can be resolved either by modifying the paranoid level or adjusting monitoring settings.

Setting the Perf Paranoid Value

To enable full access (if permitted by system policy), you can lower the paranoid value temporarily with:

sudo sysctl -w kernel.perf_event_paranoid=-1

For a persistent change, add the following line to /etc/sysctl.conf:

kernel.perf_event_paranoid = -1

Then apply changes with:

sudo sysctl --system

Adjusting Monitoring Configuration

If you cannot modify the paranoid level, you may still be able to record user-level events only. Use the perf::Config class to disable kernel/hypervisor-level measurements, which allows profiling under restrictive perf_event_paranoid settings (>= 2).

const auto counter_definitions = perf::CounterDefinition{};

auto config = perf::Config{};
config.include_kernel(false);       /// Disable kernel event sampling
config.include_hypervisor(false);   /// Disable hypervisor event sampling

auto event_counter = perf::EventCounter{ counter_definitions, config };
event_counter.add(...);

event_counter.start(); /// Will only record user-level events.

To further restrict monitoring exclude guest events:

config.include_guest(false);
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.