Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
# This workflow will install Python dependencies, run tests and lint with a
# variety of Python versions. For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Check PR

'on':
push:
branches:
- master
pull_request:
branches:
- master

jobs:
unittest:
name: ${{ matrix.container }}
strategy:
matrix:
os:
- 'ubuntu-latest'
container:
- 'ubuntu:18.04'
- 'ubuntu:22.04'
- 'fedora:37'
- 'fedora:38'
runs-on: ${{ matrix.os }}
container: ${{ matrix.container}}
steps:
- uses: actions/checkout@v3

- name: Install test dependencies
run: |
case ${{ matrix.container }} in
ubuntu:*)
export DEBIAN_FRONTEND=noninteractive
apt update -y
apt install -y cmake libunwind-dev libpcre3-dev make build-essential
;;
centos:*|fedora:*)
yum update -y
dnf group install -y "C Development Tools and Libraries" "Development Tools"
yum install -y cmake libunwind-devel pcre-devel make
;;
macos:*)
brew install cmake
;;
esac

- name: Build and install
run: |
cmake . -DCMAKE_INSTALL_PREFIX=$PWD/sw -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-g -O3 -U_FORTIFY_SOURCE -Wno-attributes -Wunused-result"
make -j 20
make install
export PATH=$PWD/sw/bin:$PATH
export LD_LIBRARY_PATH=$PWD/sw/lib:$LD_LIBRARY_PATH
igprof -o ls.gz -mp ls >/dev/null && igprof-analyse -r MEM_TOTAL ls.gz
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ ENDIF()
SET(CMAKE_C_FLAGS "${CMAKE_ANSI_FLAGS} ${CMAKE_C_FLAGS}")
SET(CMAKE_REQUIRED_FLAGS ${CMAKE_ANSI_FLAGS})
IF(CMAKE_COMPILER_IS_GNUCC)
ADD_DEFINITIONS(-ansi -pedantic -W -Wall -Wno-long-long -Werror)
ADD_DEFINITIONS(-ansi -W -Wall -Wno-long-long -Werror -Wno-unused-result -Wno-error=cast-function-type -Wno-error=pedantic -std=c++11)
ENDIF()

IF(UNIX)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The Ignominous Profiler

Have a look at https://igprof.org for detailed instructions.
6 changes: 3 additions & 3 deletions src/analyse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1209,12 +1209,12 @@ symlookup(FileInfo *file, int fileoff, std::string& symname, bool useGdb)
char buffer[1024];
if (file->NAME == "<dynamically generated>")
{
sprintf(buffer, "@?0x%x{<dynamically-generated>}", fileoff);
snprintf(buffer, 1024, "@?0x%x{<dynamically-generated>}", fileoff);
result = buffer;
}
else
{
sprintf(buffer, "+%d}",fileoff);
snprintf(buffer, 1024, "+%d}",fileoff);
// Finds the filename by looking up for the last / in the path
// and picking up only the remaining.
// Notice that this works also in the case / is not found
Expand Down Expand Up @@ -4072,7 +4072,7 @@ IgProfAnalyzerApplication::generateFlatReport(ProfileInfo & /* prof */,
}

char rankBuffer[256];
sprintf(rankBuffer, "[%d]", mainRow.rank());
snprintf(rankBuffer, 256, "[%d]", mainRow.rank());
printf("%-8s", rankBuffer);

if (m_showLocalityMetrics || m_showPageRanges)
Expand Down
6 changes: 3 additions & 3 deletions src/analyse.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ thousands(double value, int leftPadding, int decimalPositions)
assert(decimalPositions < 63);
char buffer[64];
double decimal = fabs(value-int64_t(value));
sprintf(buffer+1, "%.2f", decimal);
snprintf(buffer+1, 63, "%.2f", decimal);
buffer[decimalPositions+3] = 0;
return result + &buffer[2];
}
Expand All @@ -231,7 +231,7 @@ std::string
toString(int64_t value)
{
char buffer[1024];
sprintf(buffer,"%" PRIi64, value);
snprintf(buffer, 1024, "%" PRIi64, value);
return buffer;
}

Expand Down Expand Up @@ -262,7 +262,7 @@ class FractionPrinter
{
printf("%*s", m_size, n.c_str());
char denBuffer[256];
sprintf(denBuffer, " / %%-%ds", m_size);
snprintf(denBuffer, 256, " / %%-%ds", m_size);
printf(denBuffer, d.c_str());
}

Expand Down
2 changes: 1 addition & 1 deletion src/igprof
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ while [ "$#" != 0 ]; do
[ -z "$FINST" ] && FINST="finst"; shift ;;

-j | --jemalloc )
IGPROF_MALLOC_LIB='libjemalloc.so.1'; shift ;;
IGPROF_MALLOC_LIB='libjemalloc.so.2'; shift ;;

-np | --energy-profiler )
[ -z "$NRG" ] && NRG="nrg"; shift ;;
Expand Down
10 changes: 5 additions & 5 deletions src/profile-energy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ enableSignalHandler(void)

struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_handler = (sighandler_t) &profileSignalHandler;
sa.sa_sigaction = &profileSignalHandler;
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sigaction(s_signal, &sa, 0);
}
Expand Down Expand Up @@ -390,15 +390,15 @@ dopthread_sigmask(IgHook::SafeData<igprof_dopthread_sigmask_t> &hook,
&& (how == SIG_BLOCK || how == SIG_SETMASK)
&& sigismember(newmask, s_signal)
&& sigaction(s_signal, 0, &cursig) == 0
&& cursig.sa_handler
&& cursig.sa_sigaction
&& getitimer(s_itimer, &curtimer) == 0
&& (curtimer.it_interval.tv_sec || curtimer.it_interval.tv_usec))
{
igprof_debug("pthread_sigmask(): prevented profiling signal"
" %d from being blocked in thread 0x%lx"
" [handler 0x%lx, interval %.0f us]\n",
s_signal, (unsigned long) pthread_self(),
(unsigned long) cursig.sa_handler,
(unsigned long) cursig.sa_sigaction,
1e6 * curtimer.it_interval.tv_sec
+ curtimer.it_interval.tv_usec);
sigdelset(newmask, s_signal);
Expand All @@ -415,13 +415,13 @@ dosigaction(IgHook::SafeData<igprof_dosigaction_t> &hook,
struct sigaction sa;
if (signum == s_signal
&& act
&& act->sa_handler != (sighandler_t) &profileSignalHandler)
&& act->sa_sigaction != &profileSignalHandler)
{
igprof_debug("sigaction(): prevented profiling signal"
" %d from being overridden in thread 0x%lx\n",
s_signal, (unsigned long) pthread_self());
sigemptyset(&sa.sa_mask);
sa.sa_handler = (sighandler_t) &profileSignalHandler;
sa.sa_sigaction = &profileSignalHandler;
sa.sa_flags = SA_RESTART | SA_SIGINFO;
act = &sa;
}
Expand Down
10 changes: 10 additions & 0 deletions src/profile-mem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
#include <cstring>
#include <cstdio>
#include <pthread.h>
#if __APPLE__
#include <malloc/malloc.h>
#else
#include <malloc.h>
#endif
#include <unistd.h>
#include <new>

Expand Down Expand Up @@ -124,7 +128,13 @@ add(void *ptr, size_t size)

if (UNLIKELY(s_overhead != OVERHEAD_NONE))
{
#ifdef __linux__
size_t actual = malloc_usable_size(ptr);
#elif defined(__APPLE__)
size_t actual = malloc_size(ptr);
#else
size_t actual = size;
#endif
if (s_overhead == OVERHEAD_DELTA)
{
if ((size = actual - size) == 0)
Expand Down
6 changes: 3 additions & 3 deletions src/profile-perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ enableSignalHandler(void)

struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_handler = (sighandler_t) &profileSignalHandler;
sa.sa_sigaction = &profileSignalHandler;
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sigaction(s_signal, &sa, 0);
}
Expand Down Expand Up @@ -255,13 +255,13 @@ dosigaction(IgHook::SafeData<igprof_dosigaction_t> &hook,
struct sigaction sa;
if (signum == s_signal
&& act
&& act->sa_handler != (sighandler_t) &profileSignalHandler)
&& act->sa_sigaction != &profileSignalHandler)
{
igprof_debug("sigaction(): prevented profiling signal"
" %d from being overridden in thread 0x%lx\n",
s_signal, (unsigned long) pthread_self());
sigemptyset(&sa.sa_mask);
sa.sa_handler = (sighandler_t) &profileSignalHandler;
sa.sa_sigaction = &profileSignalHandler;
sa.sa_flags = SA_RESTART | SA_SIGINFO;
act = &sa;
}
Expand Down
14 changes: 7 additions & 7 deletions src/profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ LIBHOOK(2, int, doclock_getres, _main,
"clock_getres", 0, "libc.so.6")

LIBHOOK(1, int, dosigreturn, _main,
(unsigned long __unused),
(__unused),
(unsigned long __dummy),
(__dummy),
"sigreturn", 0, "libc.so.6")
#endif /* defined(__aarch64__) */

Expand Down Expand Up @@ -199,7 +199,7 @@ dumpOneProfile(IgProfDumpInfo &info, IgProfTrace::Stack *frame)

if (UNLIKELY(! symname || ! *symname))
{
symlen = sprintf(symgen, "@?%p", sym->address);
symlen = snprintf(symgen, 32, "@?%p", sym->address);
symname = symgen;
ASSERT(symlen <= sizeof(symgen));
}
Expand Down Expand Up @@ -328,7 +328,7 @@ dumpAllProfiles(void *arg)

timeval tv;
gettimeofday(&tv, 0);
sprintf(outname, "|gzip -c>igprof.%.100s.%ld.%f.gz",
snprintf(outname, MAX_FNAME, "|gzip -c>igprof.%.100s.%ld.%f.gz",
progname, (long) getpid(), tv.tv_sec + 1e-6*tv.tv_usec);
tofile = outname;
}
Expand All @@ -343,7 +343,7 @@ dumpAllProfiles(void *arg)
else
{
char clockres[32];
size_t clockreslen = sprintf(clockres, "%f", s_clockres);
size_t clockreslen = snprintf(clockres, 32, "%f", s_clockres);
size_t prognamelen = strlen(program_invocation_name);
info->io.attach(fileno(info->output));
info->io.put("P=(HEX ID=").put(getpid())
Expand Down Expand Up @@ -689,10 +689,10 @@ doclock_getres(IgHook::SafeData<igprof_doclock_getres_t> &hook,

static int
dosigreturn(IgHook::SafeData<igprof_dosigreturn_t> &hook,
unsigned long __unused)
unsigned long __dummy)
{
igprof_disable();
int ret = hook.chain(__unused);
int ret = hook.chain(__dummy);
igprof_enable();

return ret;
Expand Down
2 changes: 1 addition & 1 deletion src/trace-mem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ domalloc(IgHook::SafeData<igprof_domalloc_t> &hook, size_t size)
if (IgTrace::filter(0, stack, depth))
{
char buf[1024];
write(2, buf, sprintf(buf,
write(2, buf, snprintf(buf, 1024,
"*** MALLOC %ld bytes => %p, by %.500s [thread %lu pid %ld]\n",
(unsigned long) size, result, IgTrace::program(),
(unsigned long) pthread_self(), (long) getpid()));
Expand Down
4 changes: 2 additions & 2 deletions src/trace-mmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ munmapreport(void *addr, size_t len)
char hexsym[32];
if (! sym || ! *sym)
{
sprintf(hexsym, "@?%p", symaddr);
snprintf(hexsym, 32, "@?%p", symaddr);
sym = hexsym;
}
else if (s_demangle && sym[0] == '_' && sym[1] == 'Z')
Expand Down Expand Up @@ -402,7 +402,7 @@ mmapreport(const char *sz, void *addr, size_t len, int prot, int flags, int fd,
char hexsym[32];
if (! sym || ! *sym)
{
sprintf(hexsym, "@?%p", symaddr);
snprintf(hexsym, 32, "@?%p", symaddr);
sym = hexsym;
}
else if (s_demangle && sym[0] == '_' && sym[1] == 'Z')
Expand Down
8 changes: 4 additions & 4 deletions src/trace-throw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ dothrow(IgHook::SafeData<igprof_dothrow_t> &hook,
s_demanglehere = demangled;
}

write(2, buf, sprintf(buf,
write(2, buf, snprintf(buf, 2048,
"*** THROW by %.500s [thread %lu pid %ld]:\n"
" Exception of type %.500s (address %p)\n",
IgTrace::program(),
Expand All @@ -129,7 +129,7 @@ dothrow(IgHook::SafeData<igprof_dothrow_t> &hook,
if (demangled && demangled != s_demanglehere)
s_demanglehere = demangled;
}
write(2, buf, sprintf(buf, " Destructor %.500s (%p)\n Stack:\n",
write(2, buf, snprintf(buf, 2048, " Destructor %.500s (%p)\n Stack:\n",
(sym ? sym : "unknown function"),
__extension__ (void *) dest));

Expand All @@ -143,7 +143,7 @@ dothrow(IgHook::SafeData<igprof_dothrow_t> &hook,
char hexsym[32];
if (! sym || ! *sym)
{
sprintf(hexsym, "@?%p", symaddr);
snprintf(hexsym, 32, "@?%p", symaddr);
sym = hexsym;
}
else if (s_demangle)
Expand All @@ -158,7 +158,7 @@ dothrow(IgHook::SafeData<igprof_dothrow_t> &hook,
if (! lib)
lib = "<unknown library>";

write(2, buf, sprintf(buf,
write(2, buf, snprintf(buf, 2048,
" %3d: %-10p %.500s %s %ld [%.500s %s %ld]\n",
i-1, stack[i], sym, (symoff < 0 ? "-" : "+"),
labs(symoff), lib, (liboff < 0 ? "-" : "+"),
Expand Down