Skip to content

Commit

Permalink
Rename to libtraceio
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnZhong committed Feb 1, 2022
1 parent 5f882a0 commit 0755ab2
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 24 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
cmake_minimum_required(VERSION 3.16)
project(libcalltrace)
project(libtraceio)
set(CMAKE_CXX_STANDARD 20)

include(FetchContent)
FetchContent_Declare(fmt GIT_REPOSITORY https://github.com/fmtlib/fmt.git)
FetchContent_MakeAvailable(fmt)
set_property(TARGET fmt PROPERTY POSITION_INDEPENDENT_CODE ON)

add_library(calltrace SHARED calltrace.cpp calltrace.h resolver.cpp resolver.h)
target_link_libraries(calltrace PRIVATE dl fmt::fmt)
target_compile_options(calltrace PRIVATE -fno-instrument-functions -Wall -Wextra -Wsign-compare)
add_library(traceio SHARED traceio.cpp traceio.h resolver.cpp resolver.h)
target_link_libraries(traceio PRIVATE dl fmt::fmt)
target_compile_options(traceio PRIVATE -fno-instrument-functions -Wall -Wextra -Wsign-compare)

option(BUILD_SAMPLES "Build samples" OFF)
if (BUILD_SAMPLES)
add_subdirectory(sample)
foreach (target trace_basic trace_test trace_leveldb db_bench)
target_link_libraries(${target} calltrace)
target_link_libraries(${target} traceio)
endforeach ()
endif ()
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lib_target := calltrace
lib_target := traceio
sample_targets := trace_basic trace_test trace_leveldb db_bench

$(sample_targets): export CMAKE_ADDITIONAL_FLAGS := -DBUILD_SAMPLES=ON
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# libcalltrace
# libtraceio

A library for tracing function calls and I/O system calls.
A library for tracing I/O system calls and function call graph

## Usage

1. (Optional) Add the following flags to the compiler's command line:
1. (Optional but recommended) Add the following flags to the compiler's command
line:

```
-finstrument-functions \
Expand Down Expand Up @@ -69,18 +70,18 @@ A library for tracing function calls and I/O system calls.
- The `-g` flag enables the generation of debugging information, so that the
source file and line number can be obtained.

</details>
</details>

2. Run your program with `libcalltrace.so` loaded.
2. Run your program with `libtraceio.so` loaded.

## Example

Compile [sample/basic.cpp](sample/basic.cpp) and run it with `libcalltrace.so`
Compile [sample/basic.cpp](sample/basic.cpp) and run it with `libtraceio.so`:

```shell
g++ sample/basic.cpp -g -O3 -finstrument-functions -finstrument-functions-exclude-file-list=/usr/include -rdynamic
make # compile libcalltrace.so
TRACE_LOG_FN=1 TRACE_VERBOSE_FN=1 LD_PRELOAD=./build/libcalltrace.so ./a.out
make # compile libtraceio.so
TRACE_LOG_FN=1 TRACE_VERBOSE_FN=1 LD_PRELOAD=./build/libtraceio.so ./a.out
```

Output:
Expand Down Expand Up @@ -123,14 +124,14 @@ Output:
it.
- Source code: [sample/leveldb.cpp](sample/leveldb.cpp)
- Full trace: [traces/leveldb-full.txt](traces/leveldb-full.txt)
- I/O trace: [traces/leveldb-io.txt](traces/leveldb-io.txt)
- Full trace: [traces/leveldb-full.txt](traces/leveldb-full.txt)
```shell
make trace_leveldb
TRACE_LOG_FN=1 TRACE_LOG_FILE=traces/leveldb-full.txt ./build/sample/trace_leveldb
TRACE_LOG_FN=0 TRACE_LOG_FILE=traces/leveldb-io.txt ./build/sample/trace_leveldb
TRACE_LOG_FN=1 TRACE_LOG_FILE=traces/leveldb-full.txt ./build/sample/trace_leveldb
```

- LevelDB benchmark
Expand Down
4 changes: 2 additions & 2 deletions resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <map>
#include <memory>

namespace calltrace {
namespace traceio {

static auto bfd_so = dlopen("libbfd.so", RTLD_LAZY | RTLD_DEEPBIND);
static auto bfd_openr =
Expand Down Expand Up @@ -61,4 +61,4 @@ void resolve(void* address, Dl_info& info, const char*& fn_name,
}
}

} // namespace calltrace
} // namespace traceio
4 changes: 2 additions & 2 deletions resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <dlfcn.h>

namespace calltrace {
namespace traceio {
void resolve(void* address, Dl_info& info, const char*& fn_name,
const char*& filename, int& line);
} // namespace calltrace
} // namespace traceio
6 changes: 3 additions & 3 deletions calltrace.cpp → traceio.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#define _FORTIFY_SOURCE 2
#define __OPTIMIZE__ 1

#include "calltrace.h"
#include "traceio.h"

#include <cxxabi.h>
#include <dirent.h>
Expand All @@ -22,7 +22,7 @@

#include "resolver.h"

namespace calltrace {
namespace traceio {

static struct Config {
int indent = 1;
Expand Down Expand Up @@ -300,4 +300,4 @@ int madvise(void *addr, size_t len, int advice) {
print_exit_trace(this_fn);
}
}
} // namespace calltrace
} // namespace traceio
File renamed without changes.

0 comments on commit 0755ab2

Please sign in to comment.