Skip to content

Commit c54f043

Browse files
committed
Fix rule timing calculation
1 parent aa402ff commit c54f043

File tree

1 file changed

+73
-73
lines changed

1 file changed

+73
-73
lines changed

src/rules/rules.cpp

+73-73
Original file line numberDiff line numberDiff line change
@@ -9298,13 +9298,6 @@ int8_t rule_initialize(struct pbuf *input, struct rules_t ***rules, uint8_t *nrr
92989298
return -1;
92999299
}
93009300

9301-
#ifdef ESP8266
9302-
if((nrbytes % 4) != 0) {
9303-
Serial.println("Rules AST not 4 byte aligned!");
9304-
exit(-1);
9305-
}
9306-
#endif
9307-
93089301
/*LCOV_EXCL_START*/
93099302
#ifdef ESP8266
93109303
obj->timestamp->second = micros();
@@ -9319,14 +9312,12 @@ int8_t rule_initialize(struct pbuf *input, struct rules_t ***rules, uint8_t *nrr
93199312
#endif
93209313
/*LCOV_EXCL_STOP*/
93219314

9322-
9323-
/*LCOV_EXCL_START*/
93249315
#ifdef ESP8266
9325-
obj->timestamp->first = micros();
9326-
#else
9327-
clock_gettime(CLOCK_MONOTONIC, &obj->timestamp->first);
9316+
if((nrbytes % 4) != 0) {
9317+
Serial.println("Rules AST not 4 byte aligned!");
9318+
exit(-1);
9319+
}
93289320
#endif
9329-
/*LCOV_EXCL_STOP*/
93309321

93319322
{
93329323
{
@@ -9376,6 +9367,14 @@ int8_t rule_initialize(struct pbuf *input, struct rules_t ***rules, uint8_t *nrr
93769367
mempool->len += nrbytes;
93779368
memset(obj->ast.buffer, 0, nrbytes);
93789369

9370+
/*LCOV_EXCL_START*/
9371+
#ifdef ESP8266
9372+
obj->timestamp->first = micros();
9373+
#else
9374+
clock_gettime(CLOCK_MONOTONIC, &obj->timestamp->first);
9375+
#endif
9376+
/*LCOV_EXCL_STOP*/
9377+
93799378
if(rule_parse((char **)&input->payload, obj) == -1) {
93809379
vm_cache_gc();
93819380
FREE((*rules)[*nrrules-1]->timestamp);
@@ -9387,27 +9386,6 @@ int8_t rule_initialize(struct pbuf *input, struct rules_t ***rules, uint8_t *nrr
93879386
return -1;
93889387
}
93899388

9390-
#if (!defined(NON32XFER_HANDLER) && defined(MMU_SEC_HEAP)) || defined(COVERALLS)
9391-
if(is_mmu_input == 1) {
9392-
mmu_set_uint16(&input->len, mmu_get_uint16(&input->len) + newlen);
9393-
if(mmu_get_uint8(&((char *)input->payload)[newlen]) == 0) {
9394-
mmu_set_uint16(&input->len, mmu_get_uint16(&input->len) + 1);
9395-
}
9396-
mmu_set_uint16(&input->tot_len, mmu_get_uint16(&input->tot_len) - newlen);
9397-
} else {
9398-
#endif
9399-
input->len += newlen;
9400-
if(newlen < input->tot_len) {
9401-
if(((unsigned char *)input->payload)[newlen] == 0) {
9402-
input->len += 1;
9403-
}
9404-
}
9405-
input->tot_len -= newlen;
9406-
}
9407-
#if (!defined(NON32XFER_HANDLER) && defined(MMU_SEC_HEAP)) || defined(COVERALLS)
9408-
}
9409-
#endif
9410-
94119389
/*LCOV_EXCL_START*/
94129390
#ifdef ESP8266
94139391
obj->timestamp->second = micros();
@@ -9434,6 +9412,28 @@ int8_t rule_initialize(struct pbuf *input, struct rules_t ***rules, uint8_t *nrr
94349412
#endif
94359413
/*LCOV_EXCL_STOP*/
94369414

9415+
#if (!defined(NON32XFER_HANDLER) && defined(MMU_SEC_HEAP)) || defined(COVERALLS)
9416+
if(is_mmu_input == 1) {
9417+
mmu_set_uint16(&input->len, mmu_get_uint16(&input->len) + newlen);
9418+
if(mmu_get_uint8(&((char *)input->payload)[newlen]) == 0) {
9419+
mmu_set_uint16(&input->len, mmu_get_uint16(&input->len) + 1);
9420+
}
9421+
mmu_set_uint16(&input->tot_len, mmu_get_uint16(&input->tot_len) - newlen);
9422+
} else {
9423+
#endif
9424+
input->len += newlen;
9425+
if(newlen < input->tot_len) {
9426+
if(((unsigned char *)input->payload)[newlen] == 0) {
9427+
input->len += 1;
9428+
}
9429+
}
9430+
input->tot_len -= newlen;
9431+
}
9432+
#if (!defined(NON32XFER_HANDLER) && defined(MMU_SEC_HEAP)) || defined(COVERALLS)
9433+
}
9434+
#endif
9435+
9436+
94379437
/*LCOV_EXCL_START*/
94389438
#ifdef DEBUG
94399439
#ifndef ESP8266
@@ -9443,14 +9443,6 @@ int8_t rule_initialize(struct pbuf *input, struct rules_t ***rules, uint8_t *nrr
94439443
print_tree(obj);
94449444
#endif
94459445
#endif
9446-
/*LCOV_EXCL_STOP*/
9447-
9448-
/*LCOV_EXCL_START*/
9449-
#ifdef ESP8266
9450-
obj->timestamp->first = micros();
9451-
#else
9452-
clock_gettime(CLOCK_MONOTONIC, &obj->timestamp->first);
9453-
#endif
94549446
/*LCOV_EXCL_STOP*/
94559447

94569448
/*
@@ -9551,6 +9543,14 @@ int8_t rule_initialize(struct pbuf *input, struct rules_t ***rules, uint8_t *nrr
95519543

95529544
memset(obj->varstack->buffer, 0, suggested_varstack_size);
95539545

9546+
/*LCOV_EXCL_START*/
9547+
#ifdef ESP8266
9548+
obj->timestamp->first = micros();
9549+
#else
9550+
clock_gettime(CLOCK_MONOTONIC, &obj->timestamp->first);
9551+
#endif
9552+
/*LCOV_EXCL_STOP*/
9553+
95549554
/*
95559555
* The rule_run function will return -2
95569556
* if the varstack is too small
@@ -9568,6 +9568,37 @@ int8_t rule_initialize(struct pbuf *input, struct rules_t ***rules, uint8_t *nrr
95689568
}
95699569
}
95709570

9571+
/*LCOV_EXCL_START*/
9572+
#ifdef ESP8266
9573+
obj->timestamp->second = micros();
9574+
9575+
#if (!defined(NON32XFER_HANDLER) && defined(MMU_SEC_HEAP)) || defined(COVERALLS)
9576+
if(obj >= (void *)MMU_SEC_HEAP) {
9577+
logprintf_P(F("rule #%d was executed in %d microseconds"), mmu_get_uint8(&obj->nr), obj->timestamp->second - obj->timestamp->first);
9578+
} else {
9579+
#endif
9580+
logprintf_P(F("rule #%d was executed in %d microseconds"), obj->nr, obj->timestamp->second - obj->timestamp->first);
9581+
#if (!defined(NON32XFER_HANDLER) && defined(MMU_SEC_HEAP)) || defined(COVERALLS)
9582+
}
9583+
if(&obj->ast >= (void *)MMU_SEC_HEAP) {
9584+
logprintf_P(F("bytecode is %d bytes"), mmu_get_uint16(&obj->ast.nrbytes));
9585+
} else {
9586+
#endif
9587+
logprintf_P(F("bytecode is %d bytes"), obj->ast.nrbytes);
9588+
#if (!defined(NON32XFER_HANDLER) && defined(MMU_SEC_HEAP)) || defined(COVERALLS)
9589+
}
9590+
#endif
9591+
#else
9592+
clock_gettime(CLOCK_MONOTONIC, &obj->timestamp->second);
9593+
9594+
printf("rule #%d was executed in %.6f seconds\n", obj->nr,
9595+
((double)obj->timestamp->second.tv_sec + 1.0e-9*obj->timestamp->second.tv_nsec) -
9596+
((double)obj->timestamp->first.tv_sec + 1.0e-9*obj->timestamp->first.tv_nsec));
9597+
9598+
printf("bytecode is %d bytes\n", obj->ast.nrbytes);
9599+
#endif
9600+
/*LCOV_EXCL_STOP*/
9601+
95719602
/*
95729603
* If a previous varstack was bigger than the current
95739604
* varstack, use the previous varstack size. This will
@@ -9608,37 +9639,6 @@ int8_t rule_initialize(struct pbuf *input, struct rules_t ***rules, uint8_t *nrr
96089639
}
96099640
#endif
96109641

9611-
/*LCOV_EXCL_START*/
9612-
#ifdef ESP8266
9613-
obj->timestamp->second = micros();
9614-
9615-
#if (!defined(NON32XFER_HANDLER) && defined(MMU_SEC_HEAP)) || defined(COVERALLS)
9616-
if(obj >= (void *)MMU_SEC_HEAP) {
9617-
logprintf_P(F("rule #%d was executed in %d microseconds"), mmu_get_uint8(&obj->nr), obj->timestamp->second - obj->timestamp->first);
9618-
} else {
9619-
#endif
9620-
logprintf_P(F("rule #%d was executed in %d microseconds"), obj->nr, obj->timestamp->second - obj->timestamp->first);
9621-
#if (!defined(NON32XFER_HANDLER) && defined(MMU_SEC_HEAP)) || defined(COVERALLS)
9622-
}
9623-
if(&obj->ast >= (void *)MMU_SEC_HEAP) {
9624-
logprintf_P(F("bytecode is %d bytes"), mmu_get_uint16(&obj->ast.nrbytes));
9625-
} else {
9626-
#endif
9627-
logprintf_P(F("bytecode is %d bytes"), obj->ast.nrbytes);
9628-
#if (!defined(NON32XFER_HANDLER) && defined(MMU_SEC_HEAP)) || defined(COVERALLS)
9629-
}
9630-
#endif
9631-
#else
9632-
clock_gettime(CLOCK_MONOTONIC, &obj->timestamp->second);
9633-
9634-
printf("rule #%d was executed in %.6f seconds\n", obj->nr,
9635-
((double)obj->timestamp->second.tv_sec + 1.0e-9*obj->timestamp->second.tv_nsec) -
9636-
((double)obj->timestamp->first.tv_sec + 1.0e-9*obj->timestamp->first.tv_nsec));
9637-
9638-
printf("bytecode is %d bytes\n", obj->ast.nrbytes);
9639-
#endif
9640-
/*LCOV_EXCL_STOP*/
9641-
96429642
assert(nrcache == 0);
96439643

96449644
return 0;

0 commit comments

Comments
 (0)