[1cac98]: testsuite / lib / op_util.exp  Maximize  Restore  History

Download this file

164 lines (138 with data), 4.8 kB

# op_util.exp
#   Copyright (C) 2006 Red Hat, Inc.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#


# globals which might change, perhaps?
set op_proc_prefix "/dev/oprofile"
set op_var_prefix "/var/lib/oprofile"

proc found_error {msg} {
    print "ERROR:  $msg"
    opcontrol_exit
    exit 1
}

# read contents of file and return
proc op_get_file_contents {fname} {
    set fd [open $fname]
    set res [read $fd]
    close $fd
    return $res
}

# cycle-waster routine
proc op_spin {count} {
    verbose "spinning cpu for $count \"work units\""
    set j 23523
    set k 15431
    set m 73141
    set n 93802
    for {set i 0} {$i < $count} {incr i} {
	set j [expr {($k * $m - ($n >> 2)) % 4294967296}]
	set k [expr {($m + $n * ($j ^ $k)) % 4294967296}]
	set m [expr {($n * $j - ($k << 2)) % 4294967296}]
	set n [expr {($j + $k * ($m ^ $k)) % 4294967296}]
    }
    local_exec "dd bs=16 if=/dev/urandom of=/dev/null count=$count" "" "" 10
}

proc op_daemon_delete_any_samples {} {
    set cmd "opcontrol --reset"
    set result [local_exec $cmd "" "" 100]

    if {[lindex $result 0] == 0} {
	verbose "OProfile reset successfully deleted all samples"
    } else {
	found_error "OProfile --reset FAILED"
    }
}

# If the processor is i386/arch_perfmon, it could be a variant.
proc op_intel_perf_arch {cpu_type} {
    if {[regexp "i386/arch_perfmon" $cpu_type dummy] != 1} {
	return $cpu_type
    }

    #get information from /proc/cpuinfo
    set cpuinfo [ local_exec "cat /proc/cpuinfo" "" "" 100 ]
    if { [ regexp -line "model\t\t: \[0-9\]+" $cpuinfo line] != 1 } {
	return $cpu_type
    }

    if {[regexp "\[0-9]+" $line model] == 1} {
	switch -exact "$model" {
	    15 {set cpu_type i386/core_2}
	    22 {set cpu_type i386/core_2}
	    23 {set cpu_type i386/core_2}
	    29 {set cpu_type i386/core_2}
	    26 {set cpu_type i386/core_i7}
	    30 {set cpu_type i386/core_i7}
	    31 {set cpu_type i386/core_i7}
	    46 {set cpu_type i386/core_i7}
	    28 {set cpu_type i386/atom}
	    37 {set cpu_type i386/westmere}
	    44 {set cpu_type i386/westmere}
	    47 {set cpu_type i386/westmere}
	    42 {set cpu_type i386/sandybridge}
	    45 {set cpu_type i386/sandybridge}
	    58 {set cpu_type i386/ivybridge}
	    62 {set cpu_type i386/ivybridge}
	    60 {set cpu_type i386/haswell}
	    63 {set cpu_type i386/haswell}
	    66 {set cpu_type i386/haswell}
	    70 {set cpu_type i386/haswell}
	    71 {set cpu_type i386/haswell}
	}
    }

    verbose "arch_perfmon variant is $cpu_type"
    return $cpu_type
}

# detect CPU type
proc op_cpu_type {} {

    global op_proc_prefix
    set type rtc
    set cpu_type [op_get_file_contents "$op_proc_prefix/cpu_type"]

    # Do additional mappings for Intel architected performance counters
    set cpu_type [ op_intel_perf_arch "$cpu_type"]

    set cpu_events [select_cpu_events $cpu_type]

    return $cpu_events
}

proc check_user {} {
    global user_is_root

    set result [ local_exec "whoami" "" "" 100 ]

    if {[regexp "root" $result] == 1} {
	verbose "Running as root"
	set user_is_root 1
    } else {
	verbose "Not running as root"
	set user_is_root 0
    }
}

proc compile_workload {workload_src compile_options } {

    # Ideally the TCL command target_compile should be used.  However,
    # target_compile is ignoring the compiler options argument.

    set compiler "cc"
    set extension [lindex [split $workload_src "."] 1]
    set workload_exc [ lindex [split $workload_src "."] 0]_bin

    if { [string compare $extension "c"] == 0 } {
	# workload is a C program, see if it needs to be compiled.
	set test [local_exec "ls $workload_exc" "" "" 10]

	if { [lindex $test 0] == 1 } {
	    # workload has not been compiled
	    set result [local_exec "$compiler -o $workload_exc $workload_src $compile_options" "" "" 10 ]
	    if { [lindex $result 0] == 1 } {
		print "\nERROR compiling workload: $workload_src"
		print "Compiler error message: $result\n"
	    }
	}
	return [ lindex [split $workload_src "."] 0]_bin
    }

    # Assume the workload is a script, set the executable
    # name to the same as the source name.
    return $workload_src
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks