Skip to content

Commit

Permalink
[feat] add support for recording traced data and reporting it later
Browse files Browse the repository at this point in the history
  • Loading branch information
jyf111 committed Oct 6, 2023
1 parent cf64242 commit f11c1a4
Show file tree
Hide file tree
Showing 21 changed files with 1,437 additions and 500 deletions.
4 changes: 2 additions & 2 deletions eBPF_Supermarket/User_Function_Tracer/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ file(GLOB_RECURSE srcs CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
list(REMOVE_ITEM srcs ${CMAKE_CURRENT_SOURCE_DIR}/${app_stem}.bpf.c ${CMAKE_CURRENT_SOURCE_DIR}/${app_stem}.c)
add_executable(${app_stem} ${app_stem}.c ${srcs})

target_compile_options(${app_stem} PUBLIC -Wall -Wextra -fsanitize=address -g)
target_compile_options(${app_stem} PUBLIC -Wall -Wextra)

target_link_options(${app_stem} PUBLIC -lstdc++ -lelf -fsanitize=address)
target_link_options(${app_stem} PUBLIC -lstdc++ -lelf)
target_link_libraries(${app_stem} PUBLIC ${app_stem}_skel)
55 changes: 55 additions & 0 deletions eBPF_Supermarket/User_Function_Tracer/src/env.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2023 The LMP Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://github.com/linuxkerneltravel/lmp/blob/develop/LICENSE
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// author: [email protected]
//
// Save command line arguments info

#ifndef UTRACE_ENV_H
#define UTRACE_ENV_H

#include <stdio.h> // for FILE*

#include "report.h"
#include "vector.h"

struct env {
char *argv[12]; /**< -c/-commond */
bool avg_self; /**< --avg-self */
bool avg_total; /**< --avg-total */
bool flat; /**< --flat */
enum FORMAT format; /**< --format */
char *func_pattern; /**< -f/--function */
char *lib_pattern; /**< -l/--lib */
bool show_libname; /**< --libname */
unsigned int max_depth; /**< --max-depth */
char *nest_lib_pattern; /**< --nest-lib */
char *no_func_pattern; /**< --no-function */
char *no_lib_pattern; /**< --no-lib */
bool no_aslr; /**< --no-randomize-addr */
FILE *out; /**< -o/--output */
bool percent_self; /**< --percent-self */
bool percent_total; /**< --percent-total */
pid_t pid; /**< -p/--pid */
bool do_record; /**< --record */
bool do_report; /**< --report */
unsigned long long sample_time_ns; /**< --sample-time */
bool show_tid; /**< --tid */
struct vector *tids; /**< --tid-filter */
bool show_timestamp; /**< --timestamp */
unsigned long long min_duration; /**< --time-filter */
char *user; /**< -u/--user */
};

#endif // UTRACE_ENV_H
23 changes: 15 additions & 8 deletions eBPF_Supermarket/User_Function_Tracer/src/glob.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
#include <stdlib.h>
#include <string.h>

/**
* @brief regular glob match
*/
static bool glob_match(const char *text, const char *pattern) {
bool matched;
bool complemented;

while (*text != '\0' && *pattern != '\0') {
switch (*pattern) {
case '?':
case '?': // match any single char
++pattern;
++text;
break;
Expand All @@ -48,7 +51,7 @@ static bool glob_match(const char *text, const char *pattern) {
}
if (*pattern == '\0') return false;

char ch = *pattern; // ch may be ']' or '-', just treat it normally
char ch = *pattern; // `ch` may be ']' or '-', just treat it normally
matched |= (ch == *text);
++pattern;

Expand Down Expand Up @@ -108,14 +111,18 @@ static bool glob_match(const char *text, const char *pattern) {
bool glob_match_ext(const char *text, const char *pattern) {
char *dup_pattern = strdup(pattern);
char *glob_pattern = strtok(dup_pattern, ",");

bool matched = false;
while (glob_pattern) {
if (glob_match(text, glob_pattern)) {
matched = true;
break;
if (!glob_pattern) { // pattern is empty
matched = !strlen(text);
} else {
while (glob_pattern) { // split `pattern` by ',', and try to match each regular glob_pattern
// with `text`
if (glob_match(text, glob_pattern)) {
matched = true;
break;
}
glob_pattern = strtok(NULL, ",");
}
glob_pattern = strtok(NULL, ",");
}
free(dup_pattern);
return matched;
Expand Down
208 changes: 0 additions & 208 deletions eBPF_Supermarket/User_Function_Tracer/src/log.c

This file was deleted.

Loading

0 comments on commit f11c1a4

Please sign in to comment.