Comments (2)
Hi! This would be nice to add as an option to drgn's get_dmesg()
helper (maybe as a keyword-only boolean parameter named ctime
or human_readable_time
or something like that), but only if we can avoid the need to pass in the boot time explicitly. I'd assume that information is in the kernel somewhere, right?
from drgn.
I'd assume that information (boot time) is in the kernel somewhere, right?
Well, yes and no - it's not there directly, but can be derived as current time - jiffies
. However it is version specific w.r.t kernel's timekeeper structures. Which is why I originally decided to let the caller specify the boot time.
To give you some idea, this is how we get boot time in the project I'm collaborating on:
def get_timekeeper(ctx: Context):
if ctx.symbol_exists("tk_core"):
timekeeper = ctx.prog["tk_core"].timekeeper
elif ctx.symbol_exists("timekeeper"):
timekeeper = ctx.prog["timekeeper"]
else:
raise NotImplementedError("Timekeeping structure is not supported")
return timekeeper
def get_uptime_ns(ctx: Context):
timekeeper = get_timekeeper(ctx)
if not contains(timekeeper, "tkr_mono"):
jiffies = ctx.prog["jiffies"].value_()
wrapped = jiffies & 0xFFFFFFFF00000000
if wrapped:
wrapped -= 0x100000000
jiffies &= 0x00000000FFFFFFFF
jiffies |= wrapped
jiffies += 300 * ctx.config_hz
uptime_ns = jiffies * (1_000 // ctx.config_hz) * 1_000_000
elif not contains(timekeeper.tkr_mono.base, "tv64"):
uptime_ns = (timekeeper.tkr_mono.base + timekeeper.offs_boot).value_()
else:
uptime_ns = (timekeeper.tkr_mono.base.tv64 + timekeeper.offs_boot.tv64).value_()
return uptime_ns
def main():
timekeeper = get_timekeeper(cmd.ctx)
uptime_ns = get_uptime_ns(cmd.ctx)
uptime_s = uptime_ns // 1_000_000_000
boot_time_s = timekeeper.xtime_sec.value_() - uptime_s
print(get_dmesg_human_ts(boot_time_s)) # shared in initial comment
from drgn.
Related Issues (20)
- Support C++ nested classes HOT 1
- Allow overriding / providing vmcoreinfo data HOT 9
- Python API for PRSTATUS HOT 4
- Handle private APIs removed in Python 3.13 HOT 1
- Nearly 3-hour CI runs HOT 26
- Support searching for kernel modules without modules.dep.bin
- Can't access user address HOT 5
- Smoke testing on other architectures HOT 3
- Unknown DW_AT_const_value form HOT 2
- Stop generating drgn.h HOT 2
- More convenient API for reading an array
- Remove scalar restriction on reinterpret HOT 1
- Unable to debug core dump HOT 4
- Update _PyLong_AsByteArray usage for Python 3.13
- C struct bitfield formatting depends on order of construction HOT 2
- Suggestion: pull extended LTS 4.14 from OpenELA HOT 2
- Throwing generic exceptions HOT 7
- Enable RHEL 9 Packit builds
- Backtrace from wrong CPU in kernel core dump HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drgn.