Pull request

-----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEhpWov9P5fNqsNXdanKSrs4Grc8gFAmDscqoACgkQnKSrs4Gr
 c8hNZQgAj1xKbVfdvxNhdDM/kYegP2HfRUZ2Sgnmr3OHXAb21Uwpknn5DpP/Gsen
 hIxxtjWkWMaKqUN0I4Vz4t2lKZbQE2SJWW7+JNq+1GykEfTUEePIj2+hw/0gb2QM
 whjze+8C0K6utg/IP1e8TM05glT9YenhrSCuF3qRufDMI3+zL2BylQzB5Vcq9nim
 ZesMmPjDSyUrSTABq/it1D4BwduZ99t2yIdnKrougKbaxkR1IqkXZFcoUHYInsO4
 IOW41PxbH90UTTzRaJlNv6y3CiXhbbfgYdMn1HPpGyr4HgWZ4FfmAsbF03z7WKSi
 rkgyFEWtkRMFGqNEy4R+Yjm/mhR73A==
 =dicD
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/stefanha-gitlab/tags/tracing-pull-request' into staging

Pull request

# gpg: Signature made Mon 12 Jul 2021 17:49:46 BST
# gpg:                using RSA key 8695A8BFD3F97CDAAC35775A9CA4ABB381AB73C8
# gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>" [full]
# gpg:                 aka "Stefan Hajnoczi <stefanha@gmail.com>" [full]
# Primary key fingerprint: 8695 A8BF D3F9 7CDA AC35  775A 9CA4 ABB3 81AB 73C8

* remotes/stefanha-gitlab/tags/tracing-pull-request:
  trace, lttng: require .pc files
  trace/simple: add st_init_group
  trace/simple: pass iter to st_write_event_mapping
  trace: add trace_event_iter_init_group
  trace: iter init tweaks
  qemu-trace-stap: changing SYSTEMTAP_TAPSET considered harmful.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2021-07-13 11:26:09 +01:00
commit 5e05c40ced
11 changed files with 88 additions and 54 deletions

18
configure vendored
View File

@ -3606,21 +3606,8 @@ fi
##########################################
# For 'ust' backend, test if ust headers are present
if have_backend "ust"; then
cat > $TMPC << EOF
#include <lttng/tracepoint.h>
int main(void) { return 0; }
EOF
if compile_prog "" "-Wl,--no-as-needed -ldl" ; then
if $pkg_config lttng-ust --exists; then
lttng_ust_libs=$($pkg_config --libs lttng-ust)
else
lttng_ust_libs="-llttng-ust -ldl"
fi
if $pkg_config liburcu-bp --exists; then
urcu_bp_libs=$($pkg_config --libs liburcu-bp)
else
urcu_bp_libs="-lurcu-bp"
fi
if $pkg_config lttng-ust --exists; then
lttng_ust_libs=$($pkg_config --libs lttng-ust)
else
error_exit "Trace backend 'ust' missing lttng-ust header files"
fi
@ -4773,7 +4760,6 @@ fi
if have_backend "ust"; then
echo "CONFIG_TRACE_UST=y" >> $config_host_mak
echo "LTTNG_UST_LIBS=$lttng_ust_libs" >> $config_host_mak
echo "URCU_BP_LIBS=$urcu_bp_libs" >> $config_host_mak
fi
if have_backend "dtrace"; then
echo "CONFIG_TRACE_DTRACE=y" >> $config_host_mak

View File

@ -319,10 +319,6 @@ lttng = not_found
if 'CONFIG_TRACE_UST' in config_host
lttng = declare_dependency(link_args: config_host['LTTNG_UST_LIBS'].split())
endif
urcubp = not_found
if 'CONFIG_TRACE_UST' in config_host
urcubp = declare_dependency(link_args: config_host['URCU_BP_LIBS'].split())
endif
pixman = not_found
if have_system or have_tools
pixman = dependency('pixman-1', required: have_system, version:'>=0.21.8',

View File

@ -1804,7 +1804,7 @@ void info_trace_events_completion(ReadLineState *rs, int nb_args, const char *st
TraceEventIter iter;
TraceEvent *ev;
char *pattern = g_strdup_printf("%s*", str);
trace_event_iter_init(&iter, pattern);
trace_event_iter_init_pattern(&iter, pattern);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
readline_add_completion(rs, trace_event_get_name(ev));
}
@ -1822,7 +1822,7 @@ void trace_event_completion(ReadLineState *rs, int nb_args, const char *str)
TraceEventIter iter;
TraceEvent *ev;
char *pattern = g_strdup_printf("%s*", str);
trace_event_iter_init(&iter, pattern);
trace_event_iter_init_pattern(&iter, pattern);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
readline_add_completion(rs, trace_event_get_name(ev));
}

View File

@ -55,11 +55,6 @@ def tapset_dir(binary):
return os.path.realpath(tapset)
def tapset_env(tapset_dir):
tenv = copy.copy(os.environ)
tenv["SYSTEMTAP_TAPSET"] = tapset_dir
return tenv
def cmd_run(args):
prefix = probe_prefix(args.binary)
tapsets = tapset_dir(args.binary)
@ -81,11 +76,11 @@ def cmd_run(args):
# We request an 8MB buffer, since the stap default 1MB buffer
# can be easily overflowed by frequently firing QEMU traces
stapargs = ["stap", "-s", "8"]
stapargs = ["stap", "-s", "8", "-I", tapsets ]
if args.pid is not None:
stapargs.extend(["-x", args.pid])
stapargs.extend(["-e", script])
subprocess.call(stapargs, env=tapset_env(tapsets))
subprocess.call(stapargs)
def cmd_list(args):
@ -101,10 +96,9 @@ def cmd_list(args):
if verbose:
print("Listing probes with name '%s'" % script)
proc = subprocess.Popen(["stap", "-l", script],
proc = subprocess.Popen(["stap", "-I", tapsets, "-l", script],
stdout=subprocess.PIPE,
universal_newlines=True,
env=tapset_env(tapsets))
universal_newlines=True)
out, err = proc.communicate()
if proc.returncode != 0:
print("No probes found, are the tapsets installed in %s" % tapset_dir(args.binary))

View File

@ -127,7 +127,7 @@ void trace_init_vcpu(CPUState *vcpu)
{
TraceEventIter iter;
TraceEvent *ev;
trace_event_iter_init(&iter, NULL);
trace_event_iter_init_all(&iter);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
if (trace_event_is_vcpu(ev) &&
trace_event_get_state_static(ev) &&

View File

@ -82,6 +82,10 @@ void trace_event_register_group(TraceEvent **events)
event_groups = g_renew(TraceEventGroup, event_groups, nevent_groups + 1);
event_groups[nevent_groups].events = events;
nevent_groups++;
#ifdef CONFIG_TRACE_SIMPLE
st_init_group(nevent_groups - 1);
#endif
}
@ -91,7 +95,7 @@ TraceEvent *trace_event_name(const char *name)
TraceEventIter iter;
TraceEvent *ev;
trace_event_iter_init(&iter, NULL);
trace_event_iter_init_all(&iter);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
if (strcmp(trace_event_get_name(ev), name) == 0) {
return ev;
@ -100,27 +104,46 @@ TraceEvent *trace_event_name(const char *name)
return NULL;
}
void trace_event_iter_init(TraceEventIter *iter, const char *pattern)
void trace_event_iter_init_all(TraceEventIter *iter)
{
iter->event = 0;
iter->group = 0;
iter->group_id = -1;
iter->pattern = NULL;
}
void trace_event_iter_init_pattern(TraceEventIter *iter, const char *pattern)
{
trace_event_iter_init_all(iter);
iter->pattern = pattern;
}
void trace_event_iter_init_group(TraceEventIter *iter, size_t group_id)
{
trace_event_iter_init_all(iter);
iter->group_id = group_id;
}
TraceEvent *trace_event_iter_next(TraceEventIter *iter)
{
while (iter->group < nevent_groups &&
event_groups[iter->group].events[iter->event] != NULL) {
TraceEvent *ev = event_groups[iter->group].events[iter->event];
size_t group = iter->group;
iter->event++;
if (event_groups[iter->group].events[iter->event] == NULL) {
iter->event = 0;
iter->group++;
}
if (!iter->pattern ||
g_pattern_match_simple(iter->pattern, trace_event_get_name(ev))) {
return ev;
if (iter->pattern &&
!g_pattern_match_simple(iter->pattern, trace_event_get_name(ev))) {
continue;
}
if (iter->group_id != -1 &&
iter->group_id != group) {
continue;
}
return ev;
}
return NULL;
@ -130,7 +153,7 @@ void trace_list_events(FILE *f)
{
TraceEventIter iter;
TraceEvent *ev;
trace_event_iter_init(&iter, NULL);
trace_event_iter_init_all(&iter);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
fprintf(f, "%s\n", trace_event_get_name(ev));
}
@ -150,7 +173,7 @@ static void do_trace_enable_events(const char *line_buf)
TraceEvent *ev;
bool is_pattern = trace_event_is_pattern(line_ptr);
trace_event_iter_init(&iter, line_ptr);
trace_event_iter_init_pattern(&iter, line_ptr);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
if (!trace_event_get_state_static(ev)) {
if (!is_pattern) {
@ -256,7 +279,7 @@ void trace_fini_vcpu(CPUState *vcpu)
trace_guest_cpu_exit(vcpu);
trace_event_iter_init(&iter, NULL);
trace_event_iter_init_all(&iter);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
if (trace_event_is_vcpu(ev) &&
trace_event_get_state_static(ev) &&

View File

@ -13,22 +13,44 @@
#include "event-internal.h"
typedef struct TraceEventIter {
/* iter state */
size_t event;
size_t group;
/* filter conditions */
size_t group_id;
const char *pattern;
} TraceEventIter;
/**
* trace_event_iter_init:
* trace_event_iter_init_all:
* @iter: the event iterator struct
* @pattern: optional pattern to filter events on name
*
* Initialize the event iterator struct @iter,
* optionally using @pattern to filter out events
* for all events.
*/
void trace_event_iter_init_all(TraceEventIter *iter);
/**
* trace_event_iter_init_pattern:
* @iter: the event iterator struct
* @pattern: pattern to filter events on name
*
* Initialize the event iterator struct @iter,
* using @pattern to filter out events
* with non-matching names.
*/
void trace_event_iter_init(TraceEventIter *iter, const char *pattern);
void trace_event_iter_init_pattern(TraceEventIter *iter, const char *pattern);
/**
* trace_event_iter_init_group:
* @iter: the event iterator struct
* @group_id: group_id to filter events by group.
*
* Initialize the event iterator struct @iter,
* using @group_id to filter for events in the group.
*/
void trace_event_iter_init_group(TraceEventIter *iter, size_t group_id);
/**
* trace_event_iter_next:

View File

@ -26,7 +26,7 @@ foreach dir : [ '.' ] + trace_events_subdirs
input: trace_events_file,
command: [ tracetool, group, '--format=ust-events-h', '@INPUT@', '@OUTPUT@' ],
depend_files: tracetool_depends)
trace_ss.add(trace_ust_h, lttng, urcubp)
trace_ss.add(trace_ust_h, lttng)
genh += trace_ust_h
endif
trace_ss.add(trace_h, trace_c)

View File

@ -55,7 +55,7 @@ static bool check_events(bool has_vcpu, bool ignore_unavailable, bool is_pattern
/* error for unavailable events */
TraceEventIter iter;
TraceEvent *ev;
trace_event_iter_init(&iter, name);
trace_event_iter_init_pattern(&iter, name);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
if (!ignore_unavailable && !trace_event_get_state_static(ev)) {
error_setg(errp, "event \"%s\" is disabled", trace_event_get_name(ev));
@ -90,7 +90,7 @@ TraceEventInfoList *qmp_trace_event_get_state(const char *name,
}
/* Get states (all errors checked above) */
trace_event_iter_init(&iter, name);
trace_event_iter_init_pattern(&iter, name);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
TraceEventInfo *value;
bool is_vcpu = trace_event_is_vcpu(ev);
@ -153,7 +153,7 @@ void qmp_trace_event_set_state(const char *name, bool enable,
}
/* Apply changes (all errors checked above) */
trace_event_iter_init(&iter, name);
trace_event_iter_init_pattern(&iter, name);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
if (!trace_event_get_state_static(ev) ||
(has_vcpu && !trace_event_is_vcpu(ev))) {

View File

@ -280,14 +280,12 @@ void trace_record_finish(TraceBufferRecord *rec)
}
}
static int st_write_event_mapping(void)
static int st_write_event_mapping(TraceEventIter *iter)
{
uint64_t type = TRACE_RECORD_TYPE_MAPPING;
TraceEventIter iter;
TraceEvent *ev;
trace_event_iter_init(&iter, NULL);
while ((ev = trace_event_iter_next(&iter)) != NULL) {
while ((ev = trace_event_iter_next(iter)) != NULL) {
uint64_t id = trace_event_get_id(ev);
const char *name = trace_event_get_name(ev);
uint32_t len = strlen(name);
@ -309,6 +307,7 @@ static int st_write_event_mapping(void)
*/
bool st_set_trace_file_enabled(bool enable)
{
TraceEventIter iter;
bool was_enabled = trace_fp;
if (enable == !!trace_fp) {
@ -333,8 +332,9 @@ bool st_set_trace_file_enabled(bool enable)
return was_enabled;
}
trace_event_iter_init_all(&iter);
if (fwrite(&header, sizeof header, 1, trace_fp) != 1 ||
st_write_event_mapping() < 0) {
st_write_event_mapping(&iter) < 0) {
fclose(trace_fp);
trace_fp = NULL;
return was_enabled;
@ -422,3 +422,15 @@ bool st_init(void)
atexit(st_flush_trace_buffer);
return true;
}
void st_init_group(size_t group)
{
TraceEventIter iter;
if (!trace_writeout_enabled) {
return;
}
trace_event_iter_init_group(&iter, group);
st_write_event_mapping(&iter);
}

View File

@ -15,6 +15,7 @@ void st_print_trace_file_status(void);
bool st_set_trace_file_enabled(bool enable);
void st_set_trace_file(const char *file);
bool st_init(void);
void st_init_group(size_t group);
void st_flush_trace_buffer(void);
typedef struct {