当前位置: 首页 > news >正文

【linux 获取时间】

linux 获取时间接口

我们在开发调试过程中,可能遇到一些和调用时序相关的问题,为了查看哪个步骤先调用,哪个步骤后调用,我们可以使用函数打印或者主动trace堆栈…但是有的时候我们需要排查2个接口调用的时间间隔,我们可以使用记录接口调用时间点的方式来查看接口见调用的时间间隔(比如网卡的power power 和 power down之间必须要有一定的时间间隔,才能正常的power down成功)。

1、系统时间获取接口

//include/linux/time64.h//将时间按照s和ns记录
struct timespec64 {time64_t tv_sec; /* seconds */long tv_nsec     /* nanoseconds */
}
//kernel/time/timekeeping.c/*** ktime_get_ts64 - get the monotonic clock in timespec64 format* @ts:		pointer to timespec variable** The function calculates the monotonic clock from the realtime* clock and the wall_to_monotonic offset and stores the result* in normalized timespec64 format in the variable pointed to by @ts.*/
void ktime_get_ts64(struct timespec64 *ts)
{struct timekeeper *tk = &tk_core.timekeeper;struct timespec64 tomono;unsigned int seq;u64 nsec;WARN_ON(timekeeping_suspended);do {seq = read_seqcount_begin(&tk_core.seq);ts->tv_sec = tk->xtime_sec;nsec = timekeeping_get_ns(&tk->tkr_mono);tomono = tk->wall_to_monotonic;} while (read_seqcount_retry(&tk_core.seq, seq));ts->tv_sec += tomono.tv_sec;ts->tv_nsec = 0;timespec64_add_ns(ts, nsec + tomono.tv_nsec);
}

2、如何使用

    int main (void{struct timespec64 callTimer = {0};ktime_get_ts64(&callTimer);printf("tv_sec: %llu, tv_nsec: %llu\n", callTimer.tv_sec, callTimer.tv_nsec);return 0;}
http://www.lryc.cn/news/442568.html

相关文章:

  • Dockerfile部署xxljob
  • Conda新建python虚拟环境问题
  • 这几个优秀的工具网站真心值得推荐——搜嗖工具箱
  • ESP32开发 -- VSCODE+PlatformIO环境安装
  • MySQL--导入SQL文件(命令行导入)
  • 【C#基础】函数传参大总结
  • 初学51单片机之IO口上下拉电阻相关
  • Resnet50网络——口腔癌病变识别
  • Python 中自动打开网页并点击[自动化脚本],Selenium
  • Spring Boot-自动配置问题
  • CS61B学习 part1
  • 我Github的问题解决了!
  • Pytorch构建神经网络多元线性回归模型
  • 如何基于Flink CDC与OceanBase构建实时数仓,实现简化链路,高效排查
  • ActiveMQ、RabbitMQ 和 Kafka 在 Spring Boot 中的实战
  • 火语言RPA流程组件介绍--获取关联元素
  • 【2024研赛】【华为杯E题】2024 年研究生数学建模比赛思路、代码、论文助攻
  • Linux——K8s集群部署过程
  • 二.Unity中使用虚拟摇杆来控制角色移动
  • 基于SpringBoot的旅游管理系统
  • Linux套接字
  • 软件测试面试题(5)——二面(游戏测试)
  • C#基于SkiaSharp实现印章管理(8)
  • 信通院发布首个《大模型媒体生产与处理》标准,阿里云智能媒体服务作为业界首家“卓越级”通过
  • AI学习指南深度学习篇-Adam的Python实践
  • 08_React redux
  • 2024华为杯研究生数学建模竞赛(研赛)选题建议+初步分析
  • 001.从0开始实现线性回归(pytorch)
  • Relations Prediction for Knowledge Graph Completion using Large Language Models
  • 2024年中国研究生数学建模竞赛D题思路代码分析——大数据驱动的地理综合问题