Excellent question. It gets to the core of how Linux handles performance data.
The short answer is no, CPU utilization per process is not logged to a persistent file by default in any standard Linux distribution, including NixOS.
Here’s the detailed breakdown of why, what is available, and what tools you need.
Why Isn't This Logged by Default?
The Linux kernel continuously tracks resource usage (CPU, memory, I/O) for every active process. This information is exposed in a "live" state, primarily through the /proc virtual filesystem (e.g., in /proc/[pid]/stat).
However, writing this data to a log file for every process, every second, would create a massive amount of data and incur significant performance overhead (I/O and CPU). For a system with thousands of short-lived processes, this log would be enormous and mostly filled with noise.
Therefore, Linux provides the mechanism to get the data, but leaves the act of logging it to user-space tools that you can enable if you need them.
How to Log CPU Usage Per Process (The Solutions)
You need to enable a service or use a third-party tool to collect and store this data. Here are the most common solutions, from traditional to modern, with specific instructions for NixOS.
1. The Classic: Process Accounting (psacct or acct)
This is the traditional Unix/Linux way to log information about every single process that terminates.
2. The Standard: System Statistics (sysstat)
This is the most common tool for historical system performance monitoring. It provides the sar (System Activity Reporter) command.
3. The Power User's Tool: atop
atop is like top on steroids, with a crucial logging feature. It is an excellent middle-ground solution.
4. The Modern Observability Stack: Prometheus + Exporters
For continuous, high-resolution monitoring, the modern solution is a time-series database like Prometheus.
Summary & Recommendation
| Tool | Best For | How it Works | NixOS Setup |
|---|
psacct | Forensic Auditing: Finding out what ran in the past. | Logs every process on termination. | services.psacct.enable = true; |
sysstat/sar | Long-Term Trends: General system health over weeks/months. | Low-overhead snapshots of system-wide stats. | services.sysstat.enable = true; |
atop | Debugging Past Incidents: Finding which process caused a CPU spike 2 hours ago. | Detailed process snapshots at regular intervals. | Add atop package, enable service. |
| Prometheus | Live Dashboards & Alerting: Modern, real-time observability. | Scrapes metrics from specialized exporters. | Complex; services.prometheus.enable = true; |
For your use case, I would recommend starting with atop. It provides the best balance of detail, ease of setup, and powerful analysis for investigating per-process CPU usage after the fact.