Permalink
Browse files

console, feat: add console.timeElapse() (#433)

  • Loading branch information...
gmxyb authored and xicilion committed Jun 11, 2018
1 parent 27b5f17 commit 312df05c582b602a3377bf38c6cf7e1d933aeb1d
Showing with 49 additions and 2 deletions.
  1. +17 −0 fibjs/include/ifs/console.h
  2. +18 −0 fibjs/src/console/console.cpp
  3. +7 −1 idl/us-en/console.idl
  4. +7 −1 idl/zh-cn/console.idl
@@ -61,6 +61,7 @@ class console_base : public object_base {
static result_t alert(OptArgs args);
static result_t dir(v8::Local<v8::Value> obj);
static result_t time(exlib::string label);
static result_t timeElapse(exlib::string label);
static result_t timeEnd(exlib::string label);
static result_t trace(exlib::string label);
static result_t _assert(v8::Local<v8::Value> value, exlib::string msg);
@@ -111,6 +112,7 @@ class console_base : public object_base {
static void s_alert(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_dir(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_time(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_timeElapse(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_timeEnd(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_trace(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_assert(const v8::FunctionCallbackInfo<v8::Value>& args);
@@ -150,6 +152,7 @@ inline ClassInfo& console_base::class_info()
{ "alert", s_alert, true },
{ "dir", s_dir, true },
{ "time", s_time, true },
{ "timeElapse", s_timeElapse, true },
{ "timeEnd", s_timeEnd, true },
{ "trace", s_trace, true },
{ "assert", s_assert, true },
@@ -480,6 +483,20 @@ inline void console_base::s_time(const v8::FunctionCallbackInfo<v8::Value>& args
METHOD_VOID();
}
inline void console_base::s_timeElapse(const v8::FunctionCallbackInfo<v8::Value>& args)
{
METHOD_NAME("console.timeElapse");
METHOD_ENTER();
METHOD_OVER(1, 0);
OPT_ARG(exlib::string, 0, "time");
hr = timeElapse(v0);
METHOD_VOID();
}
inline void console_base::s_timeEnd(const v8::FunctionCallbackInfo<v8::Value>& args)
{
METHOD_NAME("console.timeEnd");
@@ -252,6 +252,24 @@ result_t console_base::time(exlib::string label)
return 0;
}
result_t console_base::timeElapse(exlib::string label)
{
int64_t t = Ticks() - s_timers[label];
exlib::string strBuffer;
char numStr[64];
sprintf(numStr, "%.10g", t / 1000.0);
strBuffer.append(label);
strBuffer.append(": ", 2);
strBuffer.append(numStr);
strBuffer.append("ms", 2);
asyncLog(_INFO, strBuffer);
return 0;
}
result_t console_base::timeEnd(exlib::string label)
{
int64_t t = Ticks() - s_timers[label];
View
@@ -243,7 +243,13 @@ module console
*/
static time(String label = "time");
/*! @brief Value of specified timer
/*! @brief Print elapse of specified timer
@param label Title, default is an empty string.
*/
static timeElapse(String label = "time");
/*! @brief Stop the specified timer, and print last value.
@param label Title, default is an empty string.
*/
View
@@ -272,7 +272,13 @@ module console
*/
static time(String label = "time");
/*! @brief 统计指定计时器的数值
/*! @brief 输出指定计时器当前计时值
@param label 标题,缺省为空字符串。
*/
static timeElapse(String label = "time");
/*! @brief 结束指定计时器,并输出最后计时值
@param label 标题,缺省为空字符串。
*/

0 comments on commit 312df05

Please sign in to comment.