[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-18 Thread Jonas Devlieghere via lldb-commits

JDevlieghere wrote:

Can we get (a subset) of this information on Darwin? I understand it's only 
necessary for ELF core files, and from the discussion that there's no standard 
POSIX way to get this, but it still feels a bit unfortunate to implement all 
these methods but only implement this for one specific platform. 

https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-18 Thread Fred Grim via lldb-commits

https://github.com/feg208 closed https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-17 Thread Fred Grim via lldb-commits

feg208 wrote:

> Yes, you'd have to put this test into a host test for a system that doesn't 
> support this, like use the Posix one or make one for the Windows or Darwin 
> Hosts.

Done!

https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-17 Thread Fred Grim via lldb-commits

https://github.com/feg208 updated 
https://github.com/llvm/llvm-project/pull/88995

>From 9b8ec4d0c31ad1b228add56bc27cd79457e515c7 Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Tue, 16 Apr 2024 14:46:37 -0700
Subject: [PATCH 1/3] adds additional information to the ProcessInfo object for
 elf processes

---
 lldb/include/lldb/Utility/ProcessInfo.h |  71 ++
 lldb/source/Host/linux/Host.cpp | 125 
 lldb/unittests/Host/linux/HostTest.cpp  |   6 ++
 3 files changed, 182 insertions(+), 20 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 7fb5b37be0f48f..e9fe71e1b851d1 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -139,6 +139,11 @@ class ProcessInfo {
 // to that process.
 class ProcessInstanceInfo : public ProcessInfo {
 public:
+  struct timespec {
+time_t tv_sec = 0;
+long int tv_usec = 0;
+  };
+
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
@@ -172,6 +177,66 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_parent_pid != LLDB_INVALID_PROCESS_ID;
   }
 
+  lldb::pid_t GetProcessGroupID() const { return m_process_group_id; }
+
+  void SetProcessGroupID(lldb::pid_t pgrp) { m_process_group_id = pgrp; }
+
+  bool ProcessGroupIDIsValid() const {
+return m_process_group_id != LLDB_INVALID_PROCESS_ID;
+  }
+
+  lldb::pid_t GetProcessSessionID() const { return m_process_session_id; }
+
+  void SetProcessSessionID(lldb::pid_t session) {
+m_process_session_id = session;
+  }
+
+  bool ProcessSessionIDIsValid() const {
+return m_process_session_id != LLDB_INVALID_PROCESS_ID;
+  }
+
+  struct timespec GetUserTime() const { return m_user_time; }
+
+  void SetUserTime(struct timespec utime) { m_user_time = utime; }
+
+  bool UserTimeIsValid() const {
+return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+  }
+
+  struct timespec GetSystemTime() const { return m_system_time; }
+
+  void SetSystemTime(struct timespec stime) { m_system_time = stime; }
+
+  bool SystemTimeIsValid() const {
+return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+  }
+
+  struct timespec GetCumulativeUserTime() const {
+return m_cumulative_user_time;
+  }
+
+  void SetCumulativeUserTime(struct timespec cutime) {
+m_cumulative_user_time = cutime;
+  }
+
+  bool CumulativeUserTimeIsValid() const {
+return m_cumulative_user_time.tv_sec > 0 ||
+   m_cumulative_user_time.tv_usec > 0;
+  }
+
+  struct timespec GetCumulativeSystemTime() const {
+return m_cumulative_system_time;
+  }
+
+  void SetCumulativeSystemTime(struct timespec cstime) {
+m_cumulative_system_time = cstime;
+  }
+
+  bool CumulativeSystemTimeIsValid() const {
+return m_cumulative_system_time.tv_sec > 0 ||
+   m_cumulative_system_time.tv_sec > 0;
+  }
+
   void Dump(Stream , UserIDResolver ) const;
 
   static void DumpTableHeader(Stream , bool show_args, bool verbose);
@@ -183,6 +248,12 @@ class ProcessInstanceInfo : public ProcessInfo {
   uint32_t m_euid = UINT32_MAX;
   uint32_t m_egid = UINT32_MAX;
   lldb::pid_t m_parent_pid = LLDB_INVALID_PROCESS_ID;
+  lldb::pid_t m_process_group_id = LLDB_INVALID_PROCESS_ID;
+  lldb::pid_t m_process_session_id = LLDB_INVALID_PROCESS_ID;
+  struct timespec m_user_time {};
+  struct timespec m_system_time {};
+  struct timespec m_cumulative_user_time {};
+  struct timespec m_cumulative_system_time {};
 };
 
 typedef std::vector ProcessInstanceInfoList;
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 6c57384aa38a13..c6490f2fc9e2f5 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -49,6 +49,29 @@ enum class ProcessState {
   TracedOrStopped,
   Zombie,
 };
+
+constexpr int task_comm_len = 16;
+
+struct StatFields {
+  ::pid_t pid = LLDB_INVALID_PROCESS_ID;
+  char comm[task_comm_len];
+  char state;
+  ::pid_t ppid = LLDB_INVALID_PROCESS_ID;
+  ::pid_t pgrp = LLDB_INVALID_PROCESS_ID;
+  ::pid_t session = LLDB_INVALID_PROCESS_ID;
+  int tty_nr;
+  int tpgid;
+  unsigned flags;
+  long unsigned minflt;
+  long unsigned cminflt;
+  long unsigned majflt;
+  long unsigned cmajflt;
+  long unsigned utime;
+  long unsigned stime;
+  long cutime;
+  long cstime;
+  //  other things. We don't need them below
+};
 }
 
 namespace lldb_private {
@@ -60,11 +83,92 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   ::pid_t ) {
   Log *log = GetLog(LLDBLog::Host);
 
-  auto BufferOrError = getProcFile(Pid, "status");
+  auto BufferOrError = getProcFile(Pid, "stat");
   if (!BufferOrError)
 return false;
 
   llvm::StringRef Rest = BufferOrError.get()->getBuffer();
+  if (Rest.empty())
+return false;
+  StatFields stat_fields;
+  if (sscanf(Rest.data(),
+ "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu 

[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-17 Thread via lldb-commits

jimingham wrote:

Yes, you'd have to put this test into a host test for a system that doesn't 
support this, like use the Posix one or make one for the Windows or Darwin 
Hosts.

Jim


> On Apr 17, 2024, at 10:43 AM, Fred Grim ***@***.***> wrote:
> 
> 
> That test looks good. It seems unlikely that you would buggily always produce 
> monotonically increasing times...
> 
> Not to be a pest, but since this info is only provided on Linux, we should 
> maybe add a test to make sure that asking for this information on systems 
> that don't provide it fails gracefully?
> 
> Actually looking at lldb/unittest/Host/CMakeLists.txt I see:
> 
> if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
> list(APPEND FILES
>   linux/HostTest.cpp
>   linux/SupportTest.cpp
>  )
> endif()
> which should ensure the test is never built nor executed outside of linux
> 
> —
> Reply to this email directly, view it on GitHub 
> , or 
> unsubscribe 
> .
> You are receiving this because you are on a team that was mentioned.
> 



https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-17 Thread Fred Grim via lldb-commits

feg208 wrote:

> It should never decrease, however. If you were just getting garbage values, 
> then there should be a roughly even chance the second value will be less than 
> the first. So this still gives some confidence this isn't totally bogus...

For sure. My concern is that it wouldn't increase either. The granularity is 
microseconds but with a call like getpid() for example the kernel might just 
return a cached value which, I assume after enough loops, would increase the 
timer but what is enough? And enough will change I think as build environments 
get faster machines faster kernels and so on.


https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-17 Thread Fred Grim via lldb-commits

feg208 wrote:

> That test looks good. It seems unlikely that you would buggily always produce 
> monotonically increasing times...
> 
> Not to be a pest, but since this info is only provided on Linux, we should 
> maybe add a test to make sure that asking for this information on systems 
> that don't provide it fails gracefully?

Actually looking at lldb/unittest/Host/CMakeLists.txt I see:
```
if (CMAKE_SYSTEM_NAME MATCHES "Linux|Android")
list(APPEND FILES
  linux/HostTest.cpp
  linux/SupportTest.cpp
 )
endif()
``` 

which should ensure the test is never built nor executed outside of linux

https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-17 Thread Fred Grim via lldb-commits

feg208 wrote:

> That test looks good. It seems unlikely that you would buggily always produce 
> monotonically increasing times...
> 
> Not to be a pest, but since this info is only provided on Linux, we should 
> maybe add a test to make sure that asking for this information on systems 
> that don't provide it fails gracefully?

Not at all. I'll add it

https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-17 Thread Fred Grim via lldb-commits

https://github.com/feg208 updated 
https://github.com/llvm/llvm-project/pull/88995

>From 9b8ec4d0c31ad1b228add56bc27cd79457e515c7 Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Tue, 16 Apr 2024 14:46:37 -0700
Subject: [PATCH 1/2] adds additional information to the ProcessInfo object for
 elf processes

---
 lldb/include/lldb/Utility/ProcessInfo.h |  71 ++
 lldb/source/Host/linux/Host.cpp | 125 
 lldb/unittests/Host/linux/HostTest.cpp  |   6 ++
 3 files changed, 182 insertions(+), 20 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 7fb5b37be0f48f..e9fe71e1b851d1 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -139,6 +139,11 @@ class ProcessInfo {
 // to that process.
 class ProcessInstanceInfo : public ProcessInfo {
 public:
+  struct timespec {
+time_t tv_sec = 0;
+long int tv_usec = 0;
+  };
+
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
@@ -172,6 +177,66 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_parent_pid != LLDB_INVALID_PROCESS_ID;
   }
 
+  lldb::pid_t GetProcessGroupID() const { return m_process_group_id; }
+
+  void SetProcessGroupID(lldb::pid_t pgrp) { m_process_group_id = pgrp; }
+
+  bool ProcessGroupIDIsValid() const {
+return m_process_group_id != LLDB_INVALID_PROCESS_ID;
+  }
+
+  lldb::pid_t GetProcessSessionID() const { return m_process_session_id; }
+
+  void SetProcessSessionID(lldb::pid_t session) {
+m_process_session_id = session;
+  }
+
+  bool ProcessSessionIDIsValid() const {
+return m_process_session_id != LLDB_INVALID_PROCESS_ID;
+  }
+
+  struct timespec GetUserTime() const { return m_user_time; }
+
+  void SetUserTime(struct timespec utime) { m_user_time = utime; }
+
+  bool UserTimeIsValid() const {
+return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+  }
+
+  struct timespec GetSystemTime() const { return m_system_time; }
+
+  void SetSystemTime(struct timespec stime) { m_system_time = stime; }
+
+  bool SystemTimeIsValid() const {
+return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+  }
+
+  struct timespec GetCumulativeUserTime() const {
+return m_cumulative_user_time;
+  }
+
+  void SetCumulativeUserTime(struct timespec cutime) {
+m_cumulative_user_time = cutime;
+  }
+
+  bool CumulativeUserTimeIsValid() const {
+return m_cumulative_user_time.tv_sec > 0 ||
+   m_cumulative_user_time.tv_usec > 0;
+  }
+
+  struct timespec GetCumulativeSystemTime() const {
+return m_cumulative_system_time;
+  }
+
+  void SetCumulativeSystemTime(struct timespec cstime) {
+m_cumulative_system_time = cstime;
+  }
+
+  bool CumulativeSystemTimeIsValid() const {
+return m_cumulative_system_time.tv_sec > 0 ||
+   m_cumulative_system_time.tv_sec > 0;
+  }
+
   void Dump(Stream , UserIDResolver ) const;
 
   static void DumpTableHeader(Stream , bool show_args, bool verbose);
@@ -183,6 +248,12 @@ class ProcessInstanceInfo : public ProcessInfo {
   uint32_t m_euid = UINT32_MAX;
   uint32_t m_egid = UINT32_MAX;
   lldb::pid_t m_parent_pid = LLDB_INVALID_PROCESS_ID;
+  lldb::pid_t m_process_group_id = LLDB_INVALID_PROCESS_ID;
+  lldb::pid_t m_process_session_id = LLDB_INVALID_PROCESS_ID;
+  struct timespec m_user_time {};
+  struct timespec m_system_time {};
+  struct timespec m_cumulative_user_time {};
+  struct timespec m_cumulative_system_time {};
 };
 
 typedef std::vector ProcessInstanceInfoList;
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 6c57384aa38a13..c6490f2fc9e2f5 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -49,6 +49,29 @@ enum class ProcessState {
   TracedOrStopped,
   Zombie,
 };
+
+constexpr int task_comm_len = 16;
+
+struct StatFields {
+  ::pid_t pid = LLDB_INVALID_PROCESS_ID;
+  char comm[task_comm_len];
+  char state;
+  ::pid_t ppid = LLDB_INVALID_PROCESS_ID;
+  ::pid_t pgrp = LLDB_INVALID_PROCESS_ID;
+  ::pid_t session = LLDB_INVALID_PROCESS_ID;
+  int tty_nr;
+  int tpgid;
+  unsigned flags;
+  long unsigned minflt;
+  long unsigned cminflt;
+  long unsigned majflt;
+  long unsigned cmajflt;
+  long unsigned utime;
+  long unsigned stime;
+  long cutime;
+  long cstime;
+  //  other things. We don't need them below
+};
 }
 
 namespace lldb_private {
@@ -60,11 +83,92 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   ::pid_t ) {
   Log *log = GetLog(LLDBLog::Host);
 
-  auto BufferOrError = getProcFile(Pid, "status");
+  auto BufferOrError = getProcFile(Pid, "stat");
   if (!BufferOrError)
 return false;
 
   llvm::StringRef Rest = BufferOrError.get()->getBuffer();
+  if (Rest.empty())
+return false;
+  StatFields stat_fields;
+  if (sscanf(Rest.data(),
+ "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu 

[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-17 Thread via lldb-commits

jimingham wrote:

> > The user and system times should be monotonically increasing. So you could 
> > stop at a breakpoint, fetch the times, then run your program through a 
> > little spin loop to burn some CPU before hitting a second breakpoint. Then 
> > get the times again and assert that they are > the first set. You could 
> > also set a timer in the test between the first and second stop and assert 
> > that the difference in system and user time is less than or equal to the 
> > timer difference. A single threaded program can only run on one core at a 
> > time, so that should always be true.
> 
> I added a test for user time. System time seems really likely to be flaky in 
> the unittest. It'll increase with kernel time. However if I use side-effect 
> free system calls like getpid() to try and increase that counter it seems 
> like that'll move around a lot from different kernels on different machines

It should never decrease, however.  If you were just getting garbage values, 
then there should be a roughly even chance the second value will be less than 
the first.  So this still gives some confidence this isn't totally bogus...

https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-17 Thread via lldb-commits

jimingham wrote:

That test looks good.  It seems unlikely that you would buggily always produce 
monotonically increasing times...

Not to be a pest, but since this info is only provided on Linux, we should 
maybe add a test to make sure that asking for this information on systems that 
don't provide it fails gracefully?

https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-17 Thread Fred Grim via lldb-commits

feg208 wrote:

> The user and system times should be monotonically increasing. So you could 
> stop at a breakpoint, fetch the times, then run your program through a little 
> spin loop to burn some CPU before hitting a second breakpoint. Then get the 
> times again and assert that they are > the first set. You could also set a 
> timer in the test between the first and second stop and assert that the 
> difference in system and user time is less than or equal to the timer 
> difference. A single threaded program can only run on one core at a time, so 
> that should always be true.

I added a test for user time. System time seems really likely to be flaky in 
the unittest. It'll increase with kernel time. However if I use side-effect 
free system calls like getpid() to try and increase that counter it seems like 
that'll move around a lot from different kernels on different machines

https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-17 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff c6e01627acf8591830ee1d211cff4d5388095f3d 
9871016e5cae2d07455cd7857d49dd424066ca41 -- 
lldb/include/lldb/Utility/ProcessInfo.h lldb/source/Host/linux/Host.cpp 
lldb/unittests/Host/linux/HostTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/unittests/Host/linux/HostTest.cpp 
b/lldb/unittests/Host/linux/HostTest.cpp
index 481686e08b..045f2ba884 100644
--- a/lldb/unittests/Host/linux/HostTest.cpp
+++ b/lldb/unittests/Host/linux/HostTest.cpp
@@ -65,7 +65,7 @@ TEST_F(HostTest, GetProcessInfo) {
   ASSERT_TRUE(Host::GetProcessInfo(getpid(), Info));
   ProcessInstanceInfo::timespec user_time = Info.GetUserTime();
   for (unsigned i = 0; i < 10'000'000; i++) {
-__asm__ __volatile__ ("" : "+g" (i) : :);
+__asm__ __volatile__("" : "+g"(i) : :);
   }
   ASSERT_TRUE(Host::GetProcessInfo(getpid(), Info));
   ProcessInstanceInfo::timespec next_user_time = Info.GetUserTime();

``




https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-17 Thread Fred Grim via lldb-commits

https://github.com/feg208 updated 
https://github.com/llvm/llvm-project/pull/88995

>From 9b8ec4d0c31ad1b228add56bc27cd79457e515c7 Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Tue, 16 Apr 2024 14:46:37 -0700
Subject: [PATCH 1/2] adds additional information to the ProcessInfo object for
 elf processes

---
 lldb/include/lldb/Utility/ProcessInfo.h |  71 ++
 lldb/source/Host/linux/Host.cpp | 125 
 lldb/unittests/Host/linux/HostTest.cpp  |   6 ++
 3 files changed, 182 insertions(+), 20 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 7fb5b37be0f48f..e9fe71e1b851d1 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -139,6 +139,11 @@ class ProcessInfo {
 // to that process.
 class ProcessInstanceInfo : public ProcessInfo {
 public:
+  struct timespec {
+time_t tv_sec = 0;
+long int tv_usec = 0;
+  };
+
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
@@ -172,6 +177,66 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_parent_pid != LLDB_INVALID_PROCESS_ID;
   }
 
+  lldb::pid_t GetProcessGroupID() const { return m_process_group_id; }
+
+  void SetProcessGroupID(lldb::pid_t pgrp) { m_process_group_id = pgrp; }
+
+  bool ProcessGroupIDIsValid() const {
+return m_process_group_id != LLDB_INVALID_PROCESS_ID;
+  }
+
+  lldb::pid_t GetProcessSessionID() const { return m_process_session_id; }
+
+  void SetProcessSessionID(lldb::pid_t session) {
+m_process_session_id = session;
+  }
+
+  bool ProcessSessionIDIsValid() const {
+return m_process_session_id != LLDB_INVALID_PROCESS_ID;
+  }
+
+  struct timespec GetUserTime() const { return m_user_time; }
+
+  void SetUserTime(struct timespec utime) { m_user_time = utime; }
+
+  bool UserTimeIsValid() const {
+return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+  }
+
+  struct timespec GetSystemTime() const { return m_system_time; }
+
+  void SetSystemTime(struct timespec stime) { m_system_time = stime; }
+
+  bool SystemTimeIsValid() const {
+return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+  }
+
+  struct timespec GetCumulativeUserTime() const {
+return m_cumulative_user_time;
+  }
+
+  void SetCumulativeUserTime(struct timespec cutime) {
+m_cumulative_user_time = cutime;
+  }
+
+  bool CumulativeUserTimeIsValid() const {
+return m_cumulative_user_time.tv_sec > 0 ||
+   m_cumulative_user_time.tv_usec > 0;
+  }
+
+  struct timespec GetCumulativeSystemTime() const {
+return m_cumulative_system_time;
+  }
+
+  void SetCumulativeSystemTime(struct timespec cstime) {
+m_cumulative_system_time = cstime;
+  }
+
+  bool CumulativeSystemTimeIsValid() const {
+return m_cumulative_system_time.tv_sec > 0 ||
+   m_cumulative_system_time.tv_sec > 0;
+  }
+
   void Dump(Stream , UserIDResolver ) const;
 
   static void DumpTableHeader(Stream , bool show_args, bool verbose);
@@ -183,6 +248,12 @@ class ProcessInstanceInfo : public ProcessInfo {
   uint32_t m_euid = UINT32_MAX;
   uint32_t m_egid = UINT32_MAX;
   lldb::pid_t m_parent_pid = LLDB_INVALID_PROCESS_ID;
+  lldb::pid_t m_process_group_id = LLDB_INVALID_PROCESS_ID;
+  lldb::pid_t m_process_session_id = LLDB_INVALID_PROCESS_ID;
+  struct timespec m_user_time {};
+  struct timespec m_system_time {};
+  struct timespec m_cumulative_user_time {};
+  struct timespec m_cumulative_system_time {};
 };
 
 typedef std::vector ProcessInstanceInfoList;
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 6c57384aa38a13..c6490f2fc9e2f5 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -49,6 +49,29 @@ enum class ProcessState {
   TracedOrStopped,
   Zombie,
 };
+
+constexpr int task_comm_len = 16;
+
+struct StatFields {
+  ::pid_t pid = LLDB_INVALID_PROCESS_ID;
+  char comm[task_comm_len];
+  char state;
+  ::pid_t ppid = LLDB_INVALID_PROCESS_ID;
+  ::pid_t pgrp = LLDB_INVALID_PROCESS_ID;
+  ::pid_t session = LLDB_INVALID_PROCESS_ID;
+  int tty_nr;
+  int tpgid;
+  unsigned flags;
+  long unsigned minflt;
+  long unsigned cminflt;
+  long unsigned majflt;
+  long unsigned cmajflt;
+  long unsigned utime;
+  long unsigned stime;
+  long cutime;
+  long cstime;
+  //  other things. We don't need them below
+};
 }
 
 namespace lldb_private {
@@ -60,11 +83,92 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   ::pid_t ) {
   Log *log = GetLog(LLDBLog::Host);
 
-  auto BufferOrError = getProcFile(Pid, "status");
+  auto BufferOrError = getProcFile(Pid, "stat");
   if (!BufferOrError)
 return false;
 
   llvm::StringRef Rest = BufferOrError.get()->getBuffer();
+  if (Rest.empty())
+return false;
+  StatFields stat_fields;
+  if (sscanf(Rest.data(),
+ "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu 

[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-17 Thread Fred Grim via lldb-commits

feg208 wrote:

> The user and system times should be monotonically increasing. So you could 
> stop at a breakpoint, fetch the times, then run your program through a little 
> spin loop to burn some CPU before hitting a second breakpoint. Then get the 
> times again and assert that they are > the first set. You could also set a 
> timer in the test between the first and second stop and assert that the 
> difference in system and user time is less than or equal to the timer 
> difference. A single threaded program can only run on one core at a time, so 
> that should always be true. 


Ok let me add a test along these lines. I'll run the test a bunch locally and 
in this pr to make sure I don't make a mess

https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-16 Thread Ed Maste via lldb-commits

emaste wrote:

> is there not a Posix way to get these

Not really. On FreeBSD these generally come from sysctl(s).

Of the ones added in this pull request SetParentProcessID is already handled on 
FreeBSD, while SetProcessGroupID, SetProcessSessionID, SetUserTime, 
SetSystemTime, SetCumulativeUserTime, SetCumulativeSystemTime are not

https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-16 Thread via lldb-commits

jimingham wrote:


> On Apr 16, 2024, at 5:17 PM, Fred Grim ***@***.***> wrote:
> 
> 
> These seem like fairly POSIX-y bits of data, is there not a Posix way to get 
> these (so other posix systems will also get this info?)
> 
> Not that I know of for arbitrary processes in linux. fwiw the original code 
> without these values got similar bits out of the proc filesystem
> 
That's sad, but not your doing...

> Also, it looks like you added user time and system time information, but you 
> didn't test that those get valid values.
> 
> I did not. My concern here is that this would make for flaky tests. The issue 
> is that these times are going to be very dependent on the cpus they are 
> scheduled to, what else is running on that same machine and so on. I guess we 
> could do a bunch of stuff to pin the unit test process in place and make it 
> more controllable but that tends to imply permissions for the host executing 
> the unit test. Or maybe you were thinking of another way? I am all ears if so.
> 

The user and system times should be monotonically increasing.  So you could 
stop at a breakpoint, fetch the times, then run your program through a little 
spin loop to burn some CPU before hitting a second breakpoint.   Then get the 
times again and assert that they are > the first set. You could also set a 
timer in the test between the first and second stop and assert that the 
difference in system and user time is less than or equal to the timer 
difference.  A single threaded program can only run on one core at a time, so 
that should always be true.

Jim


> —
> Reply to this email directly, view it on GitHub 
> , or 
> unsubscribe 
> .
> You are receiving this because you are on a team that was mentioned.
> 



https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-16 Thread Fred Grim via lldb-commits

feg208 wrote:

> These seem like fairly POSIX-y bits of data, is there not a Posix way to get 
> these (so other posix systems will also get this info?)

Not that I know of for arbitrary processes in linux. fwiw the original code 
without these values got similar bits out of the proc filesystem

> 
> Also, it looks like you added user time and system time information, but you 
> didn't test that those get valid values.

I did not. My concern here is that this would make for flaky tests. The issue 
is that these times are going to be very dependent on the cpus they are 
scheduled to, what else is running on that same machine and so on. I guess we 
could do a bunch of stuff to pin the unit test process in place and make it 
more controllable but that tends to imply permissions for the host executing 
the unit test. Or maybe you were thinking of another way? I am all ears if so.  

https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-16 Thread via lldb-commits

jimingham wrote:

These seem like fairly POSIX-y bits of data, is there not a Posix way to get 
these (so other posix systems will also get this info?)

Also, it looks like you added user time and system time information, but you 
didn't test that those get valid values.

https://github.com/llvm/llvm-project/pull/88995
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-16 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Fred Grim (feg208)


Changes

This adds some additional bits into a ProcessInfo structure that will be of use 
in filling structs in an elf core file. This is a demand for implementing 
process save-core

---
Full diff: https://github.com/llvm/llvm-project/pull/88995.diff


3 Files Affected:

- (modified) lldb/include/lldb/Utility/ProcessInfo.h (+71) 
- (modified) lldb/source/Host/linux/Host.cpp (+105-20) 
- (modified) lldb/unittests/Host/linux/HostTest.cpp (+6) 


``diff
diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 7fb5b37be0f48f..e9fe71e1b851d1 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -139,6 +139,11 @@ class ProcessInfo {
 // to that process.
 class ProcessInstanceInfo : public ProcessInfo {
 public:
+  struct timespec {
+time_t tv_sec = 0;
+long int tv_usec = 0;
+  };
+
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
@@ -172,6 +177,66 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_parent_pid != LLDB_INVALID_PROCESS_ID;
   }
 
+  lldb::pid_t GetProcessGroupID() const { return m_process_group_id; }
+
+  void SetProcessGroupID(lldb::pid_t pgrp) { m_process_group_id = pgrp; }
+
+  bool ProcessGroupIDIsValid() const {
+return m_process_group_id != LLDB_INVALID_PROCESS_ID;
+  }
+
+  lldb::pid_t GetProcessSessionID() const { return m_process_session_id; }
+
+  void SetProcessSessionID(lldb::pid_t session) {
+m_process_session_id = session;
+  }
+
+  bool ProcessSessionIDIsValid() const {
+return m_process_session_id != LLDB_INVALID_PROCESS_ID;
+  }
+
+  struct timespec GetUserTime() const { return m_user_time; }
+
+  void SetUserTime(struct timespec utime) { m_user_time = utime; }
+
+  bool UserTimeIsValid() const {
+return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+  }
+
+  struct timespec GetSystemTime() const { return m_system_time; }
+
+  void SetSystemTime(struct timespec stime) { m_system_time = stime; }
+
+  bool SystemTimeIsValid() const {
+return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+  }
+
+  struct timespec GetCumulativeUserTime() const {
+return m_cumulative_user_time;
+  }
+
+  void SetCumulativeUserTime(struct timespec cutime) {
+m_cumulative_user_time = cutime;
+  }
+
+  bool CumulativeUserTimeIsValid() const {
+return m_cumulative_user_time.tv_sec > 0 ||
+   m_cumulative_user_time.tv_usec > 0;
+  }
+
+  struct timespec GetCumulativeSystemTime() const {
+return m_cumulative_system_time;
+  }
+
+  void SetCumulativeSystemTime(struct timespec cstime) {
+m_cumulative_system_time = cstime;
+  }
+
+  bool CumulativeSystemTimeIsValid() const {
+return m_cumulative_system_time.tv_sec > 0 ||
+   m_cumulative_system_time.tv_sec > 0;
+  }
+
   void Dump(Stream , UserIDResolver ) const;
 
   static void DumpTableHeader(Stream , bool show_args, bool verbose);
@@ -183,6 +248,12 @@ class ProcessInstanceInfo : public ProcessInfo {
   uint32_t m_euid = UINT32_MAX;
   uint32_t m_egid = UINT32_MAX;
   lldb::pid_t m_parent_pid = LLDB_INVALID_PROCESS_ID;
+  lldb::pid_t m_process_group_id = LLDB_INVALID_PROCESS_ID;
+  lldb::pid_t m_process_session_id = LLDB_INVALID_PROCESS_ID;
+  struct timespec m_user_time {};
+  struct timespec m_system_time {};
+  struct timespec m_cumulative_user_time {};
+  struct timespec m_cumulative_system_time {};
 };
 
 typedef std::vector ProcessInstanceInfoList;
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 6c57384aa38a13..c6490f2fc9e2f5 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -49,6 +49,29 @@ enum class ProcessState {
   TracedOrStopped,
   Zombie,
 };
+
+constexpr int task_comm_len = 16;
+
+struct StatFields {
+  ::pid_t pid = LLDB_INVALID_PROCESS_ID;
+  char comm[task_comm_len];
+  char state;
+  ::pid_t ppid = LLDB_INVALID_PROCESS_ID;
+  ::pid_t pgrp = LLDB_INVALID_PROCESS_ID;
+  ::pid_t session = LLDB_INVALID_PROCESS_ID;
+  int tty_nr;
+  int tpgid;
+  unsigned flags;
+  long unsigned minflt;
+  long unsigned cminflt;
+  long unsigned majflt;
+  long unsigned cmajflt;
+  long unsigned utime;
+  long unsigned stime;
+  long cutime;
+  long cstime;
+  //  other things. We don't need them below
+};
 }
 
 namespace lldb_private {
@@ -60,11 +83,92 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   ::pid_t ) {
   Log *log = GetLog(LLDBLog::Host);
 
-  auto BufferOrError = getProcFile(Pid, "status");
+  auto BufferOrError = getProcFile(Pid, "stat");
   if (!BufferOrError)
 return false;
 
   llvm::StringRef Rest = BufferOrError.get()->getBuffer();
+  if (Rest.empty())
+return false;
+  StatFields stat_fields;
+  if (sscanf(Rest.data(),
+ "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu 

[Lldb-commits] [lldb] adds additional information to the ProcessInfo object for elf processes (PR #88995)

2024-04-16 Thread Fred Grim via lldb-commits

https://github.com/feg208 created 
https://github.com/llvm/llvm-project/pull/88995

This adds some additional bits into a ProcessInfo structure that will be of use 
in filling structs in an elf core file. This is a demand for implementing 
process save-core

>From 9b8ec4d0c31ad1b228add56bc27cd79457e515c7 Mon Sep 17 00:00:00 2001
From: Fred Grim 
Date: Tue, 16 Apr 2024 14:46:37 -0700
Subject: [PATCH] adds additional information to the ProcessInfo object for elf
 processes

---
 lldb/include/lldb/Utility/ProcessInfo.h |  71 ++
 lldb/source/Host/linux/Host.cpp | 125 
 lldb/unittests/Host/linux/HostTest.cpp  |   6 ++
 3 files changed, 182 insertions(+), 20 deletions(-)

diff --git a/lldb/include/lldb/Utility/ProcessInfo.h 
b/lldb/include/lldb/Utility/ProcessInfo.h
index 7fb5b37be0f48f..e9fe71e1b851d1 100644
--- a/lldb/include/lldb/Utility/ProcessInfo.h
+++ b/lldb/include/lldb/Utility/ProcessInfo.h
@@ -139,6 +139,11 @@ class ProcessInfo {
 // to that process.
 class ProcessInstanceInfo : public ProcessInfo {
 public:
+  struct timespec {
+time_t tv_sec = 0;
+long int tv_usec = 0;
+  };
+
   ProcessInstanceInfo() = default;
 
   ProcessInstanceInfo(const char *name, const ArchSpec , lldb::pid_t pid)
@@ -172,6 +177,66 @@ class ProcessInstanceInfo : public ProcessInfo {
 return m_parent_pid != LLDB_INVALID_PROCESS_ID;
   }
 
+  lldb::pid_t GetProcessGroupID() const { return m_process_group_id; }
+
+  void SetProcessGroupID(lldb::pid_t pgrp) { m_process_group_id = pgrp; }
+
+  bool ProcessGroupIDIsValid() const {
+return m_process_group_id != LLDB_INVALID_PROCESS_ID;
+  }
+
+  lldb::pid_t GetProcessSessionID() const { return m_process_session_id; }
+
+  void SetProcessSessionID(lldb::pid_t session) {
+m_process_session_id = session;
+  }
+
+  bool ProcessSessionIDIsValid() const {
+return m_process_session_id != LLDB_INVALID_PROCESS_ID;
+  }
+
+  struct timespec GetUserTime() const { return m_user_time; }
+
+  void SetUserTime(struct timespec utime) { m_user_time = utime; }
+
+  bool UserTimeIsValid() const {
+return m_user_time.tv_sec > 0 || m_user_time.tv_usec > 0;
+  }
+
+  struct timespec GetSystemTime() const { return m_system_time; }
+
+  void SetSystemTime(struct timespec stime) { m_system_time = stime; }
+
+  bool SystemTimeIsValid() const {
+return m_system_time.tv_sec > 0 || m_system_time.tv_usec > 0;
+  }
+
+  struct timespec GetCumulativeUserTime() const {
+return m_cumulative_user_time;
+  }
+
+  void SetCumulativeUserTime(struct timespec cutime) {
+m_cumulative_user_time = cutime;
+  }
+
+  bool CumulativeUserTimeIsValid() const {
+return m_cumulative_user_time.tv_sec > 0 ||
+   m_cumulative_user_time.tv_usec > 0;
+  }
+
+  struct timespec GetCumulativeSystemTime() const {
+return m_cumulative_system_time;
+  }
+
+  void SetCumulativeSystemTime(struct timespec cstime) {
+m_cumulative_system_time = cstime;
+  }
+
+  bool CumulativeSystemTimeIsValid() const {
+return m_cumulative_system_time.tv_sec > 0 ||
+   m_cumulative_system_time.tv_sec > 0;
+  }
+
   void Dump(Stream , UserIDResolver ) const;
 
   static void DumpTableHeader(Stream , bool show_args, bool verbose);
@@ -183,6 +248,12 @@ class ProcessInstanceInfo : public ProcessInfo {
   uint32_t m_euid = UINT32_MAX;
   uint32_t m_egid = UINT32_MAX;
   lldb::pid_t m_parent_pid = LLDB_INVALID_PROCESS_ID;
+  lldb::pid_t m_process_group_id = LLDB_INVALID_PROCESS_ID;
+  lldb::pid_t m_process_session_id = LLDB_INVALID_PROCESS_ID;
+  struct timespec m_user_time {};
+  struct timespec m_system_time {};
+  struct timespec m_cumulative_user_time {};
+  struct timespec m_cumulative_system_time {};
 };
 
 typedef std::vector ProcessInstanceInfoList;
diff --git a/lldb/source/Host/linux/Host.cpp b/lldb/source/Host/linux/Host.cpp
index 6c57384aa38a13..c6490f2fc9e2f5 100644
--- a/lldb/source/Host/linux/Host.cpp
+++ b/lldb/source/Host/linux/Host.cpp
@@ -49,6 +49,29 @@ enum class ProcessState {
   TracedOrStopped,
   Zombie,
 };
+
+constexpr int task_comm_len = 16;
+
+struct StatFields {
+  ::pid_t pid = LLDB_INVALID_PROCESS_ID;
+  char comm[task_comm_len];
+  char state;
+  ::pid_t ppid = LLDB_INVALID_PROCESS_ID;
+  ::pid_t pgrp = LLDB_INVALID_PROCESS_ID;
+  ::pid_t session = LLDB_INVALID_PROCESS_ID;
+  int tty_nr;
+  int tpgid;
+  unsigned flags;
+  long unsigned minflt;
+  long unsigned cminflt;
+  long unsigned majflt;
+  long unsigned cmajflt;
+  long unsigned utime;
+  long unsigned stime;
+  long cutime;
+  long cstime;
+  //  other things. We don't need them below
+};
 }
 
 namespace lldb_private {
@@ -60,11 +83,92 @@ static bool GetStatusInfo(::pid_t Pid, ProcessInstanceInfo 
,
   ::pid_t ) {
   Log *log = GetLog(LLDBLog::Host);
 
-  auto BufferOrError = getProcFile(Pid, "status");
+  auto BufferOrError = getProcFile(Pid, "stat");
   if (!BufferOrError)
 return false;
 
   llvm::StringRef Rest =