3 # if this chart is called X.chart.sh, then all functions and global variables
6 cpufreq_sys_dir="/sys/devices"
8 cpufreq_source_update=1
10 # _update_every is a special variable - it holds the number of seconds
11 # between the calls of the _update() function
13 cpufreq_priority=10000
15 cpufreq_find_all_files() {
16 find $1 -maxdepth $cpufreq_sys_depth -name scaling_cur_freq 2>/dev/null
19 # _check is called once, to find out if this chart should be enabled or not
23 # - 0 to enable the chart
24 # - 1 to disable the chart
26 [ -z "$( cpufreq_find_all_files $cpufreq_sys_dir )" ] && return 1
30 # _create is called once, to create the charts
32 local dir= file= id= i=
34 # we create a script with the source of the
35 # cpufreq_update() function
36 # - the highest speed we can achieve -
37 [ $cpufreq_source_update -eq 1 ] && echo >$TMP_DIR/cpufreq.sh "cpufreq_update() {"
39 echo "CHART cpu.cpufreq '' 'CPU Clock' 'MHz' 'cpufreq' '' line $[cpufreq_priority + 1] $cpufreq_update_every"
40 echo >>$TMP_DIR/cpufreq.sh "echo \"BEGIN cpu.cpufreq \$1\""
43 for file in $( cpufreq_find_all_files $cpufreq_sys_dir | sort -u )
46 dir=$( dirname $file )
49 [ -f $dir/affected_cpus ] && cpu=$( cat $dir/affected_cpus )
50 [ -z "$cpu" ] && cpu="$i.a"
52 id="$( fixid "cpu$cpu" )"
54 echo >&2 "charts.d: cpufreq: on file='$file', dir='$dir', cpu='$cpu', id='$id'"
56 echo "DIMENSION $id '$id' absolute 1 1000"
57 echo >>$TMP_DIR/cpufreq.sh "printf \"SET $id = \"; cat $file "
59 echo >>$TMP_DIR/cpufreq.sh "echo END"
61 [ $cpufreq_source_update -eq 1 ] && echo >>$TMP_DIR/cpufreq.sh "}"
62 # cat >&2 $TMP_DIR/cpufreq.sh
64 # ok, load the function cpufreq_update() we created
65 [ $cpufreq_source_update -eq 1 ] && . $TMP_DIR/cpufreq.sh
70 # _update is called continiously, to collect the values
72 # the first argument to this function is the microseconds since last update
73 # pass this parameter to the BEGIN statement (see bellow).
75 # do all the work to collect / calculate the values
77 # remember: KEEP IT SIMPLE AND SHORT
79 [ $cpufreq_source_update -eq 0 ] && . $TMP_DIR/cpufreq.sh $1