Skip to content

Commit

Permalink
process_metrics_linux.go: avoid calling os.Getpagesize() with every w…
Browse files Browse the repository at this point in the history
…riteProcessMetrics() call

It is enough to detect OS page size at the start and then use the detected value.
This removes syscall overhead from every writeProcessMetrics() call.

This is a follow-up for 7b14975
Updates #76
Updates VictoriaMetrics/VictoriaMetrics#6457
  • Loading branch information
valyala committed Jul 16, 2024
1 parent 7a44715 commit eba0da0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion process_metrics_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import (
// See https://github.com/prometheus/procfs/blob/a4ac0826abceb44c40fc71daed2b301db498b93e/proc_stat.go#L40 .
const userHZ = 100

// Different environments may have different page size.
//
// See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6457
var pageSizeBytes = uint64(os.Getpagesize())

// See http://man7.org/linux/man-pages/man5/proc.5.html
type procStat struct {
State byte
Expand Down Expand Up @@ -80,7 +85,7 @@ func writeProcessMetrics(w io.Writer) {
WriteCounterUint64(w, "process_major_pagefaults_total", uint64(p.Majflt))
WriteCounterUint64(w, "process_minor_pagefaults_total", uint64(p.Minflt))
WriteGaugeUint64(w, "process_num_threads", uint64(p.NumThreads))
WriteGaugeUint64(w, "process_resident_memory_bytes", uint64(p.Rss)*uint64(os.Getpagesize()))
WriteGaugeUint64(w, "process_resident_memory_bytes", uint64(p.Rss)*pageSizeBytes)
WriteGaugeUint64(w, "process_start_time_seconds", uint64(startTimeSeconds))
WriteGaugeUint64(w, "process_virtual_memory_bytes", uint64(p.Vsize))
writeProcessMemMetrics(w)
Expand Down

0 comments on commit eba0da0

Please sign in to comment.