Giter VIP home page Giter VIP logo

Comments (2)

osandov avatar osandov commented on June 14, 2024

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.

vbendel avatar vbendel commented on June 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.