This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
END | |
{ | |
printf("\nThread state analysis:\n"); | |
printf("%-16s %-6s %6s %6s %6s %6s %6s %6s %6s \n", "COMM", "PID", "CPU", "RUNQ", "SLP", "USL", "SUS", "LCK", "DEA"); | |
// Convert nanoseconds to milliseconds | |
$ms = (uint64) 1000000; | |
for ($kv : @cpu) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tracepoint:lock:contention_begin | |
{ | |
@lock_ts[tid] = nsecs; | |
} | |
// Track futex wake operations (lock release) | |
tracepoint:lock:contention_end | |
/has_key(@lock_ts, tid)/ | |
{ | |
@lck[comm, tid] = sum(nsecs - @lock_ts[tid]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The futex states as defined in uapi/linux/futex.h | |
#define FUTEX_WAIT 0 | |
#define FUTEX_WAIT_BITSET 9 | |
#define FUTEX_PRIVATE_FLAG 128 | |
#define FUTEX_WAIT_PRIVATE (FUTEX_WAIT | FUTEX_PRIVATE_FLAG) | |
#define FUTEX_WAIT_BITSET_PRIVATE (FUTEX_WAIT_BITSET | FUTEX_PRIVATE_FLAG) | |
// Track futex wait operations (lock attempts) | |
tracepoint:syscalls:sys_enter_futex | |
/args->op == FUTEX_WAIT || args->op == FUTEX_WAIT_BITSET || args->op == FUTEX_WAIT_PRIVATE || args->op == FUTEX_WAIT_BITSET_PRIVATE / |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bpftrace | |
#include <linux/sched.h> | |
tracepoint:sched:sched_switch | |
{ | |
$prev_pid = args->prev_pid; | |
$next_pid = args->next_pid; | |
$prev_state = args->prev_state; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tracepoint:sched:sched_switch | |
{ | |
$prev_pid = args->prev_pid; | |
$next_pid = args->next_pid; | |
$prev_state = args->prev_state; | |
// Record on-CPU time for previous task | |
if (has_key(@start, $prev_pid)) | |
{ | |
@cpu[comm, $prev_pid] = sum(nsecs - @start[$prev_pid]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// On-CPU time tracking tracking | |
tracepoint:sched:sched_switch | |
{ | |
$prev_pid = args->prev_pid; | |
$next_pid = args->next_pid; | |
$prev_state = args->prev_state; | |
// Record on-CPU time for previous task | |
if (has_key(@start, $prev_pid)) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use cache_size::l1_cache_line_size; | |
/// Returns the result of a matrix multiplication. | |
/// Uses loop tiling to optimize the matrix multiplication. | |
/// The function relies on cache_size crate to get the cache line size. | |
/// | |
/// # Arguments | |
/// | |
/// * `n` - The dimension of the matrix. | |
pub fn optimized_tiled(n: usize) -> Vec<Vec<f64>> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// # Arguments | |
/// | |
/// * `n` - The dimension of the matrix. | |
/// | |
/// # Returns a matrix with values from 0 to n - 1. | |
/// Initializes a matrix with values from 0 to n - 1. | |
pub fn generate_matrix(n: usize) -> Vec<Vec<f64>> { | |
let mut matrix = vec![vec![0.0; n]; n]; | |
let mut value = 0.0; | |
for r in 0..n { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Returns the result of the matrix multiplication. | |
/// | |
/// # Arguments | |
/// | |
/// * `n` - The dimension of the matrix. | |
pub fn non_optimized(n: usize) -> Vec<Vec<f64>> { | |
let m1 = generate_matrix(n); | |
let m2 = m1.clone(); | |
let mut res = vec![vec![0.0; n]; n]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Returns an initialized matrix. The matrix is initialized in a standard way. | |
/// | |
/// # Arguments | |
/// | |
/// * `n` - The dimension of the matrix. | |
pub fn standard_initialize(n: usize) -> Vec<Vec<i32>> { | |
let mut data = vec![vec![0i32; n]; n]; | |
for r in 0..n { | |
for c in 0..n { |
NewerOlder