Chinaunix首页 | 论坛 | 博客
  • 博客访问: 243652
  • 博文数量: 34
  • 博客积分: 938
  • 博客等级: 准尉
  • 技术积分: 440
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-18 12:07
文章分类

全部博文(34)

文章存档

2012年(28)

2011年(6)

分类: 嵌入式

2011-12-28 17:42:42

android 中得到1970到现在的时间:
在JAVA中可以通过System.currentTimeMillis()得到:
long start_time = System.currentTimeMillis();
View.draw(canvas);
long end_time = System.currentTimeMillis();
long spend_time = end_time - start_time;
Log.i(TAG,"mView.draw: spend_time = " + spend_time);

android 的C/C++中,下面的例子得到:
#include "time.h"
#include
void main ()
{
    time_t rawtime;
    struct tm * timeinfo;
    time ( &rawtime );得到的是秒,悲剧了,不对称呀
    printf ( "\007The current date/time is: %ld\n", rawtime );
}
得到的是秒,悲剧了,跟JAVA对应不起来,换个方式吧!

找个半天,结果找到了下面的方式:
#include
#include
void main ()
{
    struct timeval time;
    gettimeofday(&time, NULL);
    printf ( "\007The current date/time is:  %lld\n", time.tv_sec * 1000 + time.tv_usec /1000);
}
这样得到的才是毫秒,真折腾。其中timeval的tv_sec是秒,tv_usec微秒。

android 的C/C++中打LOG
得到了时间,如何在C/C++中打LOG呢?有下面的方式。
#include
LOGW("the end of android_view_ViewRoot_showFPS, dur: %d", dur);
__android_log_write(ANDROID_LOG_VERBOSE,"ViewRoot","the end of android_view_ViewRoot_showFPS");
阅读(9447) | 评论(0) | 转发(1) |
0

上一篇:游松山湖

下一篇:android oprofile初步使用

给主人留下些什么吧!~~