linux - native task api 测试

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>

#include <native/task.h>
#include <native/timer.h>

RT_TASK demo_task;

/* NOTE: error handling omitted. */

void demo(void *arg)
{
    RTIME now, previous;

/*
     * Arguments: &task (NULL=self),
     *            start time,
     *            period (here: 1 ms)
     */
    rt_task_set_periodic(NULL, TM_NOW, 1000000);
    previous = rt_timer_read();

while (1) {
        rt_task_wait_period(NULL);
        now = rt_timer_read();

/*
         * NOTE: printf may have unexpected impact on the timing of
         *       your program. It is used here in the critical loop
         *       only for demonstration purposes.
         */
        printf("Time since last turn: %ld.%06ld ms\n",
               (long)(now - previous) / 1000000,
               (long)(now - previous) % 1000000);
               previous = now;
    }
}

void catch_signal(int sig)
{
}

int main(int argc, char* argv[])
{
    signal(SIGTERM, catch_signal);
    signal(SIGINT, catch_signal);

/* Avoids memory swapping for this program */
    mlockall(MCL_CURRENT|MCL_FUTURE);

/*
     * Arguments: &task,
     *            name,
     *            stack size (0=default),
     *            priority,
     *            mode (FPU, start suspended, ...)
     */
    rt_task_create(&demo_task, "trivial", 0, 99, 0);

/*
     * Arguments: &task,
     *            task function,
     *            function argument
     */
    rt_task_start(&demo_task, &demo, NULL);

pause();

rt_task_delete(&demo_task);

return 0;
}

2 测试结果:

Time since last turn: 0.997940 ms                                               
Time since last turn: 1.001939 ms                                               
Time since last turn: 0.996909 ms                                               
Time since last turn: 1.000727 ms                                               
Time since last turn: 1.003576 ms                                               
Time since last turn: 1.000606 ms                                               
Time since last turn: 0.998909 ms                                               
Time since last turn: 0.998243 ms                                               
Time since last turn: 1.001333 ms                                               
Time since last turn: 0.997636 ms                                               
Time since last turn: 1.003152 ms                                               
Time since last turn: 0.996788 ms                                               
Time since last turn: 1.000060 ms                                               
Time since last turn: 0.998667 ms                                               
Time since last turn: 1.005030 ms                                               
Time since last turn: 0.995031 ms                                               
Time since last turn: 1.002545 ms                                               
Time since last turn: 1.002303 ms                                               
Time since last turn: 0.995515 ms                                               
Time since last turn: 1.002849 ms                                               
Time since last turn: 0.997878 ms                                               
Time since last turn: 1.002000 ms                                               
Time since last turn: 0.998546 ms                                               
Time since last turn: 0.999576 ms                                               
Time since last turn: 1.002363 ms                                               
Time since last turn: 0.998425 ms                                               
Time since last turn: 0.998969 ms                                               
Time since last turn: 1.000061 ms                                               
Time since last turn: 1.002788 ms                                               
Time since last turn: 0.996848 ms                                               
Time since last turn: 1.002182 ms                                               
Time since last turn: 0.999212 ms                                               
Time since last turn: 1.001455 ms                                               
Time since last turn: 0.997636 ms                                               
Time since last turn: 1.004546 ms                                               
Time since last turn: 0.995757 ms                                               
Time since last turn: 1.000788 ms                                               
Time since last turn: 0.998485 ms                                               
Time since last turn: 1.001333 ms                                               
Time since last turn: 0.998485 ms                                               
Time since last turn: 1.001152 ms                                               
Time since last turn: 0.999878 ms                                               
Time since last turn: 0.999334 ms                                               
Time since last turn: 1.002121 ms                                               
Time since last turn: 0.999697 ms                                               
Time since last turn: 1.000242 ms                                               
Time since last turn: 0.997697 ms                                               
Time since last turn: 1.000303 ms                                               
Time since last turn: 0.999879 ms                                               
Time since last turn: 1.000788 ms                                               
Time since last turn: 1.000061 ms                                               
Time since last turn: 0.999636 ms                                               
Time since last turn: 1.001454 ms                                               
Time since last turn: 0.997334 ms                                               
Time since last turn: 1.004666 ms                                               
Time since last turn: 0.996910 ms                                               
Time since last turn: 1.002545 ms                                               
Time since last turn: 0.996485 ms                                               
Time since last turn: 1.001273 ms                                               
Time since last turn: 0.998666 ms                                               
Time since last turn: 1.000788 ms                                               
Time since last turn: 0.999758 ms                                               
Time since last turn: 1.000242 ms                                               
Time since last turn: 0.999091 ms                                               
Time since last turn: 1.002909 ms                                               
Time since last turn: 1.000485 ms                                               
Time since last turn: 0.996424 ms                                               
Time since last turn: 1.001818 ms

时间: 2024-11-01 00:48:21

linux - native task api 测试的相关文章

ubuntu12.04+kafka2.9.2+zookeeper3.4.5的分布式集群安装和demo(java api)测试

博文作者:迦壹 博客地址:http://idoall.org/home.php?mod=space&uid=1&do=blog&id=547 转载声明:可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明,谢谢合作! --------------------------------------- 目录: 一.什么是kafka? 二.kafka的官方网站在哪里? 三.在哪里下载?需要哪些组件的支持? 四.如何安装? 五.FAQ 六.扩展阅读 一.什么是kafka? ka

kafka2.9.2的分布式集群安装和demo(java api)测试

目录: 一.什么是kafka? 二.kafka的官方网站在哪里? 三.在哪里下载?需要哪些组件的支持? 四.如何安装? 五.FAQ 六.扩展阅读   一.什么是kafka? kafka是LinkedIn开发并开源的一个分布式MQ系统,现在是Apache的一个孵化项目.在它的主页描述kafka为一个高吞吐量的分布式(能将消息分散到不同的节点上)MQ.Kafka仅仅由7000行Scala编写,据了解,Kafka每秒可以生产约25万消息(50 MB),每秒处理55万消息(110 MB). kafka目

Java JVM、JNI、Native Function Interface、Create New Process Native Function API Analysis

目录 1. JAVA JVM 2. Java JNI: Java Native Interface 3. Java Create New Process Native Function API Analysis In Linux 4. Java Create New Process Native Function API Analysis In Windows 1. JAVA JVM 0x1: JVM架构简介 JVM是Java Virtual Machine(Java虚拟机)的缩写,JVM是一种

Linux Native Aio 异步AIO的研究

Linux Native Aio 异步AIO的研究 http://rango.swoole.com/archives/282 首先声明一下epoll+nonblock从宏观角度可以叫做全异步,但从微观的角度来看还是同步的IO.只是在数据到达后得到系统通知,然后同步执行recv取回数据,没有iowait. 真正的异步IO(下面会统一叫做AIO)应该像Windows IOCP一样,传入文件句柄,缓存区,尺寸等参数和一个函数指针,当操作系统真正完成了IO操作,再执行对应的函数. 实际上对于socket

初学者的API测试技巧

API(应用程序编程接口)测试是一种直接在API级别执行验证的软件测试.它是集成测试的一部分,它确认API是否满足测试人员对功能.可靠性.性能和安全性的期望.与UI测试不同,API测试是在没有GUI层执行操作的. API测试技巧 Web API有两大类Web服务:SOAP和REST.SOAP(简单对象访问协议)是W3C标准定义的一种标准协议,用于发送和接收Web服务请求和响应.REST(表示状态传输)是使用HTTP的基于Web标准的体系结构.与基于SOAP的Web服务不同,没有针对RESTful

微信公众号API测试——接口调用频率限制

接口频率限制[1] 公众号调用接口并不是无限制的.为了防止公众号的程序错误而引发微信服务器负载异常,默认情况下,每个公众号调用接口都不能超过一定限制,当超过一定限制时,调用对应接口会收到如下错误返回码: {"errcode":45009,"errmsg":"api freq out of limit"} 各接口调用频率限制如下: 接口 每日限额 获取access_token 2000 自定义菜单创建 1000 自定义菜单查询 10000 自定义菜

API测试利器postMan 使用教程

自从开始做API开发之后,我就在寻找合适的API测试工具.一开始不是很想用Chrome扩展,用的 WizTools 的工具,后来试过一次 Postman 之后就停不下来了,还买了付费的Jetpacks.推出Team Sync Beta之后我又把这个工具推广给团队,作为API文档使用.看到中文网络上关于这个工具的文章并不多,于是决定写一篇小文介绍一下. 一.基本功能 Postman的功能在 文档 中有介绍.不过文档略啰嗦,这里简单介绍一下主界面,入门功能就都提到了. Collections:在Po

微信公众平台API测试——接收文本消息

一.简介 当普通微信用户向公众账号发消息时,微信服务器将用户发送的消息封装成XML数据包,通过POST消息发送到开发者的URL上.      微信服务器在五秒内收不到服务器的响应会断掉连接,并且重新发起请求,总共重试三次.关于重试的消息排重,推荐使用msgid排重.      假如服务器无法保证在五秒内处理并回复,可以直接回复空串,微信服务器不会对此作任何处理,并且不会发起重试. 当前支持如下的普通消息: 1 文本消息 2 图片消息 3 语音消息 4 视频消息 5 地理位置消息 6 链接消息 二

微信公众平台API测试——接收链接消息

一.简介 当普通微信用户向公众账号发消息时,微信服务器将用户发送的消息封装成XML数据包,通过POST消息发送到开发者的URL上.      微信服务器在五秒内收不到服务器的响应会断掉连接,并且重新发起请求,总共重试三次.关于重试的消息排重,推荐使用msgid排重.      假如服务器无法保证在五秒内处理并回复,可以直接回复空串,微信服务器不会对此作任何处理,并且不会发起重试. 当前支持如下的普通消息: 1 文本消息 2 图片消息 3 语音消息 4 视频消息 5 地理位置消息 6 链接消息 二