citrun

watch C/C++ source code execute
Log | Files | Refs | LICENSE

commit fdc0e7a42daee7ea7063916e296be015a8808420
parent a4b4c5427e525ffed94c3a6c051460a4202b5c94
Author: Kyle Milz <kyle@0x30.net>
Date:   Wed, 11 Jan 2017 18:27:08 -0700

t: rename memory module

Diffstat:
Mt/lib_deadcount.t | 4++--
Mt/lib_header.t | 4++--
Mt/lib_livecount.t | 4++--
Mt/lib_size.t | 6+++---
Mt/lib_transunit.t | 4++--
At/mem.pm | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mt/mem_unix.pm | 2+-
Mt/mem_win32.pm | 2+-
Dt/shm.pm | 87-------------------------------------------------------------------------------
9 files changed, 100 insertions(+), 100 deletions(-)

diff --git a/t/lib_deadcount.t b/t/lib_deadcount.t @@ -5,7 +5,7 @@ use strict; use warnings; -use t::shm; +use t::mem; use t::utils; plan tests => 8; @@ -18,7 +18,7 @@ is( $dir->stderr, '', 'is instrumented program stderr silent' ); is( $? >> 8, 0, "is instrumented program exit code 0" ); my $shm_file_path = get_one_shmfile( $ENV{CITRUN_PROCDIR} ); -my $shm = t::shm->new( $shm_file_path ); +my $shm = t::mem->new( $shm_file_path ); my %tus = %{ $shm->{trans_units} }; my ($tu1, $tu2, $tu3) = sort keys %tus; diff --git a/t/lib_header.t b/t/lib_header.t @@ -4,7 +4,7 @@ use strict; use warnings; -use t::shm; +use t::mem; use t::utils; plan tests => 19; @@ -17,7 +17,7 @@ is( $dir->stderr, '', 'is instrumented program stderr empty' ); is( $? >> 8, 0, 'is instrumented program exit code 0' ); my $shm_file_path = get_one_shmfile( $ENV{CITRUN_PROCDIR} ); -my $shm = t::shm->new( $shm_file_path ); +my $shm = t::mem->new( $shm_file_path ); is( $shm->{magic}, 'ctrn', 'is file magic correct' ); is( $shm->{major}, 0, 'is major 0' ); diff --git a/t/lib_livecount.t b/t/lib_livecount.t @@ -5,7 +5,7 @@ use strict; use warnings; use Time::HiRes qw( time usleep ); -use t::shm; +use t::mem; use t::utils; plan tests => 23; @@ -20,7 +20,7 @@ if ($child_pid == 0) { usleep 500 * 1000; my $shm_path = get_one_shmfile( $ENV{CITRUN_PROCDIR} ); -my $shm = t::shm->new( $shm_path ); +my $shm = t::mem->new( $shm_path ); my %trans_units = %{ $shm->{trans_units} }; diff --git a/t/lib_size.t b/t/lib_size.t @@ -4,7 +4,7 @@ use strict; use warnings; -use t::shm; +use t::mem; use t::utils; plan tests => 6; @@ -17,6 +17,6 @@ is( $dir->stderr, '', 'is instrumented program stderr silent' ); is( $? >> 8, 0, 'is instrumented program exit code 0' ); my $shm_file_path = get_one_shmfile( $ENV{CITRUN_PROCDIR} ); -my $procfile = t::shm->new( $shm_file_path ); +my $procfile = t::mem->new( $shm_file_path ); -is( $procfile->{size}, $t::shm::os_allocsize * 4, 'is file 4 allocation units' ); +is( $procfile->{size}, $t::mem::os_allocsize * 4, 'is file 4 allocation units' ); diff --git a/t/lib_transunit.t b/t/lib_transunit.t @@ -4,7 +4,7 @@ use strict; use warnings; -use t::shm; +use t::mem; use t::utils; plan tests => 14; @@ -17,7 +17,7 @@ is( $dir->stderr, '', 'is instrumented program stderr silent' ); is( $? >> 8, 0, "is instrumented program exit code 0" ); my $shm_file_path = get_one_shmfile( $ENV{CITRUN_PROCDIR} ); -my $shm = t::shm->new( $shm_file_path ); +my $shm = t::mem->new( $shm_file_path ); my %tus = %{ $shm->{trans_units} }; my ($tu1, $tu2, $tu3) = sort keys %tus; diff --git a/t/mem.pm b/t/mem.pm @@ -0,0 +1,87 @@ +package t::mem; + +use strict; +use warnings; + +use Inline 'C'; +use POSIX; +use if $^O eq 'MSWin32', 't::mem_win32'; +use if $^O ne 'MSWin32', 't::mem_unix'; +use autodie; + +sub new { + my ($class, $procfile) = @_; + + my $self = {}; + bless($self, $class); + + get_mem( $self, $procfile ); + + # These functions proved by C code at the end of this file. + my $header_size = citrun_header_size(); + my $node_fixed_size = citrun_node_size(); + + ( $self->{magic}, + $self->{major}, $self->{minor}, + $self->{pids}[0], $self->{pids}[1], $self->{pids}[2], + $self->{units}, + $self->{loc}, + $self->{done}, + $self->{progname}, + $self->{cwd} + ) = unpack("Z4I8Z1024Z1024", $self->{mem}); + + my %trans_units; + my $node_start = get_aligned_size($header_size); + + while ($node_start < $self->{size}) { + # Struct field ordering controlled by lib.h. + my $data = substr($self->{mem}, $node_start, $node_fixed_size); + my @struct_fields = unpack("IZ1024Z1024", $data); + + # Store a hash of information we just found. + my $buf_size = $struct_fields[0]; + $trans_units{ $struct_fields[2] } = { + size => $buf_size, + comp_file_name => $struct_fields[1], + exec_buf_pos => $node_start + $node_fixed_size + }; + + # Calculate where the end of this node is. + my $node_end = $node_start + $node_fixed_size + ($buf_size * 8); + $node_start = get_aligned_size($node_end); + } + $self->{trans_units} = \%trans_units; + + return $self; +} + +sub get_aligned_size { + my ($unaligned_size) = @_; + + my $page_mask = $t::mem::os_allocsize - 1; + return ($unaligned_size + $page_mask) & ~$page_mask; +} + +sub get_buffers { + my ($self, $tu_key) = @_; + + my $tu = $self->{trans_units}->{$tu_key}; + my $data = substr($self->{mem}, $tu->{exec_buf_pos}, $tu->{size} * 8); + my @execs = unpack("Q$tu->{size}", $data); + + return \@execs; +} + +1; +__DATA__ +__C__ +#include "../lib.h" + +size_t citrun_header_size() { + return sizeof(struct citrun_header); +} + +size_t citrun_node_size() { + return sizeof(struct citrun_node); +} diff --git a/t/mem_unix.pm b/t/mem_unix.pm @@ -1,4 +1,4 @@ -package t::shm; +package t::mem; use strict; use warnings; diff --git a/t/mem_win32.pm b/t/mem_win32.pm @@ -1,4 +1,4 @@ -package t::shm; +package t::mem; use strict; use warnings; diff --git a/t/shm.pm b/t/shm.pm @@ -1,87 +0,0 @@ -package t::shm; - -use strict; -use warnings; - -use Inline 'C'; -use POSIX; -use if $^O eq 'MSWin32', 't::mem_win32'; -use if $^O ne 'MSWin32', 't::mem_unix'; -use autodie; - -sub new { - my ($class, $procfile) = @_; - - my $self = {}; - bless($self, $class); - - get_mem( $self, $procfile ); - - # These functions proved by C code at the end of this file. - my $header_size = citrun_header_size(); - my $node_fixed_size = citrun_node_size(); - - ( $self->{magic}, - $self->{major}, $self->{minor}, - $self->{pids}[0], $self->{pids}[1], $self->{pids}[2], - $self->{units}, - $self->{loc}, - $self->{done}, - $self->{progname}, - $self->{cwd} - ) = unpack("Z4I8Z1024Z1024", $self->{mem}); - - my %trans_units; - my $node_start = get_aligned_size($header_size); - - while ($node_start < $self->{size}) { - # Struct field ordering controlled by lib.h. - my $data = substr($self->{mem}, $node_start, $node_fixed_size); - my @struct_fields = unpack("IZ1024Z1024", $data); - - # Store a hash of information we just found. - my $buf_size = $struct_fields[0]; - $trans_units{ $struct_fields[2] } = { - size => $buf_size, - comp_file_name => $struct_fields[1], - exec_buf_pos => $node_start + $node_fixed_size - }; - - # Calculate where the end of this node is. - my $node_end = $node_start + $node_fixed_size + ($buf_size * 8); - $node_start = get_aligned_size($node_end); - } - $self->{trans_units} = \%trans_units; - - return $self; -} - -sub get_aligned_size { - my ($unaligned_size) = @_; - - my $page_mask = $t::shm::os_allocsize - 1; - return ($unaligned_size + $page_mask) & ~$page_mask; -} - -sub get_buffers { - my ($self, $tu_key) = @_; - - my $tu = $self->{trans_units}->{$tu_key}; - my $data = substr($self->{mem}, $tu->{exec_buf_pos}, $tu->{size} * 8); - my @execs = unpack("Q$tu->{size}", $data); - - return \@execs; -} - -1; -__DATA__ -__C__ -#include "../lib.h" - -size_t citrun_header_size() { - return sizeof(struct citrun_header); -} - -size_t citrun_node_size() { - return sizeof(struct citrun_node); -}