]> git.plutz.net Git - rigidfind/commitdiff
calculate request run time
authorPaul Hänsch <paul@plutz.net>
Wed, 13 Mar 2024 23:36:35 +0000 (00:36 +0100)
committerPaul Hänsch <paul@plutz.net>
Wed, 13 Mar 2024 23:36:35 +0000 (00:36 +0100)
index.cgi

index 532a323c5294957b8be47b7f647e3a6578ab4004..94c397041e73483d0db5bedaa5b88ab903070934 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -1,11 +1,13 @@
 #!/bin/sh
 
+read _DATE _date_n <<-EOF
+       $(date +"%s     %N")
+       EOF
+
 . "${_EXEC:-${0%/*}}/cgilite/cgilite.sh"
 . "${_EXEC:-${0%/*}}/cgilite/storage.sh"
 . "${_EXEC:-${0%/*}}/cgilite/json.sh"
 
-[ "$_DATE" ] || _DATE="$(date +%s)"
-
 debug "$REQUEST_METHOD $REQUEST_URI    $SERVER_PROTOCOL        $_DATE"
 
 ingest() {
@@ -234,14 +236,14 @@ elif [ "$REQUEST_METHOD" = "POST" ]; then
   )"
   results="${results%  }"
 
-  times >&2
+  t="$(( ${_DATE}${_date_n} - $(date +%s%N) ))"
 
   cat <<-EOF
        Status: 200 OK\r
        X-elastic-product: Elasticsearch\r
        Content-Type: application/vnd.elasticsearch+json;compatible-with=8\r
        \r
-       { "took":0,
+       { "took":$((t / 1000)),
          "timed_out":false,
          "hits": {
            "total":{"value": $(DB2 "$results" count @) ,"relation":"eq"},