From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: "Steven Rostedt (Google)" <rostedt@goodmis.org>
Subject: [PATCH 3/4] trace-cmd: Move find_tasks() into add_guest()
Date: Thu, 28 Apr 2022 11:06:34 -0400 [thread overview]
Message-ID: <20220428150635.789051-4-rostedt@goodmis.org> (raw)
In-Reply-To: <20220428150635.789051-1-rostedt@goodmis.org>
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
In order to simplify the logic a bit, move the find_tasks() code (to find
the PIDs on the host that map to the guest) into the add_guest() function
where the guest is first added.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
tracecmd/trace-record.c | 35 -----------------------------------
tracecmd/trace-vm.c | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index d4b5d4d6490f..a4a0d63d907d 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -3215,38 +3215,6 @@ static int do_accept(int sd)
return -1;
}
-/* Find all the tasks associated with the guest pid */
-static void find_tasks(struct trace_guest *guest)
-{
- struct dirent *dent;
- char *path;
- DIR *dir;
- int ret;
- int tasks = 0;
-
- ret = asprintf(&path, "/proc/%d/task", guest->pid);
- if (ret < 0)
- return;
-
- dir = opendir(path);
- free(path);
- if (!dir)
- return;
-
- while ((dent = readdir(dir))) {
- int *pids;
- if (!(dent->d_type == DT_DIR && is_digits(dent->d_name)))
- continue;
- pids = realloc(guest->task_pids, sizeof(int) * (tasks + 2));
- if (!pids)
- break;
- pids[tasks++] = strtol(dent->d_name, NULL, 0);
- pids[tasks] = -1;
- guest->task_pids = pids;
- }
- closedir(dir);
-}
-
static char *parse_guest_name(char *gname, int *cid, int *port,
struct addrinfo **res)
{
@@ -3287,9 +3255,6 @@ static char *parse_guest_name(char *gname, int *cid, int *port,
guest = trace_get_guest(*cid, gname);
if (guest) {
*cid = guest->cid;
- /* Mapping not found, search for them */
- if (!guest->cpu_pid)
- find_tasks(guest);
return guest->name;
}
diff --git a/tracecmd/trace-vm.c b/tracecmd/trace-vm.c
index f0513950aa26..bf2b0695d09b 100644
--- a/tracecmd/trace-vm.c
+++ b/tracecmd/trace-vm.c
@@ -54,6 +54,38 @@ bool trace_have_guests_pid(void)
return true;
}
+/* Find all the tasks associated with the guest pid */
+static void find_tasks(struct trace_guest *guest)
+{
+ struct dirent *dent;
+ char *path;
+ DIR *dir;
+ int ret;
+ int tasks = 0;
+
+ ret = asprintf(&path, "/proc/%d/task", guest->pid);
+ if (ret < 0)
+ return;
+
+ dir = opendir(path);
+ free(path);
+ if (!dir)
+ return;
+
+ while ((dent = readdir(dir))) {
+ int *pids;
+ if (!(dent->d_type == DT_DIR && is_digits(dent->d_name)))
+ continue;
+ pids = realloc(guest->task_pids, sizeof(int) * (tasks + 2));
+ if (!pids)
+ break;
+ pids[tasks++] = strtol(dent->d_name, NULL, 0);
+ pids[tasks] = -1;
+ guest->task_pids = pids;
+ }
+ closedir(dir);
+}
+
static struct trace_guest *add_guest(unsigned int cid, const char *name)
{
struct trace_guest *guest;
@@ -71,6 +103,8 @@ static struct trace_guest *add_guest(unsigned int cid, const char *name)
guest->cid = cid;
guest->pid = -1;
+ find_tasks(guest);
+
return guest;
}
--
2.35.1
next prev parent reply other threads:[~2022-04-28 15:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-28 15:06 [PATCH 0/4] trace-cmd: Clean ups for agent communications Steven Rostedt
2022-04-28 15:06 ` [PATCH 1/4] trace-cmd: Move add_guest_info() into trace-vm.c Steven Rostedt
2022-04-28 15:06 ` [PATCH 2/4] trace-cmd: Simplify add_guest() Steven Rostedt
2022-04-28 15:06 ` Steven Rostedt [this message]
2022-04-28 15:06 ` [PATCH 4/4] trace-cmd: Move find_pid_by_cid() into add_guest() Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220428150635.789051-4-rostedt@goodmis.org \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).