Skip to content

Commit 1ab1b86

Browse files
committed
Added performance trace inside ml-modules/(services|transforms)
1 parent 8e649dd commit 1ab1b86

File tree

10 files changed

+198
-114
lines changed

10 files changed

+198
-114
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
(:
2+
Copyright 2012-2016 MarkLogic Corporation
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
:)
16+
xquery version "1.0-ml";
17+
18+
module namespace perflog = "http://marklogic.com/data-hub/perflog-lib";
19+
20+
(:~
21+
: determine if a module exists or not
22+
:
23+
: @param $uri - the uri of the module to check
24+
: @return - true if exists, false otherwise
25+
:)
26+
declare function perflog:logit($what-is-it, $x)
27+
{
28+
let $before := xdmp:elapsed-time()
29+
let $resp := $x()
30+
let $time := xdmp:elapsed-time() - $before
31+
let $_ := xdmp:log($what-is-it || " took " || $time || " ms" )
32+
return $resp
33+
};

marklogic-data-hub/src/main/resources/ml-modules/services/collector.xqy

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import module namespace debug = "http://marklogic.com/data-hub/debug-lib"
2323
import module namespace flow = "http://marklogic.com/data-hub/flow-lib"
2424
at "/com.marklogic.hub/lib/flow-lib.xqy";
2525

26+
import module namespace perflog = "http://marklogic.com/data-hub/perflog-lib"
27+
at "/com.marklogic.hub/lib/perflog-lib.xqy";
28+
2629
declare option xdmp:mapping "false";
2730

2831
(:~
@@ -31,9 +34,11 @@ declare option xdmp:mapping "false";
3134
declare function service:build-response($items as item()*)
3235
as document-node()
3336
{
34-
document {
35-
json:to-array($items) ! xdmp:to-json(.)
36-
}
37+
perflog:logit('Collector.buildResponse',function() {
38+
document {
39+
json:to-array($items) ! xdmp:to-json(.)
40+
}
41+
})
3742
};
3843

3944
(:
@@ -46,12 +51,14 @@ declare function post(
4651
$input as document-node()*
4752
) as document-node()*
4853
{
49-
debug:dump-env(),
54+
perflog:logit('Collector.post',function() {
55+
debug:dump-env(),
5056

51-
(:let $options := $input/node():)
52-
let $module-uri as xs:string := map:get($params, "module-uri")
53-
return
54-
service:build-response(flow:run-collector($module-uri, map:map()))
57+
(:let $options := $input/node():)
58+
let $module-uri as xs:string := map:get($params, "module-uri")
59+
return
60+
service:build-response(flow:run-collector($module-uri, map:map()))
61+
})
5562
};
5663

5764
(:
@@ -62,9 +69,11 @@ declare function get(
6269
$params as map:map
6370
) as document-node()*
6471
{
65-
debug:dump-env(),
72+
perflog:logit('Collector.get',function() {
73+
debug:dump-env(),
6674

67-
let $module-uri as xs:string := map:get($params, "module-uri")
68-
return
69-
service:build-response(flow:run-collector($module-uri, map:map()))
75+
let $module-uri as xs:string := map:get($params, "module-uri")
76+
return
77+
service:build-response(flow:run-collector($module-uri, map:map()))
78+
})
7079
};

marklogic-data-hub/src/main/resources/ml-modules/services/debug.xqy

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ module namespace service = "http://marklogic.com/rest-api/resource/debug";
1919

2020
import module namespace debug = "http://marklogic.com/data-hub/debug-lib"
2121
at "/com.marklogic.hub/lib/debug-lib.xqy";
22+
23+
import module namespace perflog = "http://marklogic.com/data-hub/perflog-lib"
24+
at "/com.marklogic.hub/lib/perflog-lib.xqy";
2225

2326
declare namespace rapi = "http://marklogic.com/rest-api";
2427

@@ -29,9 +32,11 @@ declare function get(
2932
$params as map:map
3033
) as document-node()*
3134
{
32-
debug:dump-env(),
35+
perflog:logit('Debug.get',function() {
36+
debug:dump-env(),
3337

34-
document { debug:on() }
38+
document { debug:on() }
39+
})
3540
};
3641

3742
declare %rapi:transaction-mode("update") function post(
@@ -40,11 +45,13 @@ declare %rapi:transaction-mode("update") function post(
4045
$input as document-node()*
4146
) as document-node()*
4247
{
43-
debug:dump-env(),
44-
45-
let $enable := map:get($params, "enable") = ("true", "yes")
46-
let $_ := debug:enable($enable)
47-
return
48-
(),
49-
document { () }
48+
perflog:logit('Debug.post',function() {
49+
debug:dump-env(),
50+
51+
let $enable := map:get($params, "enable") = ("true", "yes")
52+
let $_ := debug:enable($enable)
53+
return
54+
(),
55+
document { () }
56+
})
5057
};

marklogic-data-hub/src/main/resources/ml-modules/services/entity.xqy

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import module namespace debug = "http://marklogic.com/data-hub/debug-lib"
2323
import module namespace flow = "http://marklogic.com/data-hub/flow-lib"
2424
at "/com.marklogic.hub/lib/flow-lib.xqy";
2525

26+
import module namespace perflog = "http://marklogic.com/data-hub/perflog-lib"
27+
at "/com.marklogic.hub/lib/perflog-lib.xqy";
28+
2629
declare namespace rapi = "http://marklogic.com/rest-api";
2730

2831
declare namespace hub = "http://marklogic.com/data-hub";
@@ -41,16 +44,18 @@ declare function get(
4144
$params as map:map
4245
) as document-node()*
4346
{
44-
debug:dump-env("GET ENTITY(s)"),
45-
46-
document {
47-
let $entity-name := map:get($params, "entity-name")
48-
let $resp :=
49-
if ($entity-name) then
50-
flow:get-entity($entity-name)
51-
else
52-
flow:get-entities()
53-
return
54-
$resp
55-
}
47+
perflog:logit('Entity.get',function() {
48+
debug:dump-env("GET ENTITY(s)"),
49+
50+
document {
51+
let $entity-name := map:get($params, "entity-name")
52+
let $resp :=
53+
if ($entity-name) then
54+
flow:get-entity($entity-name)
55+
else
56+
flow:get-entities()
57+
return
58+
$resp
59+
}
60+
})
5661
};

marklogic-data-hub/src/main/resources/ml-modules/services/flow.xqy

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import module namespace debug = "http://marklogic.com/data-hub/debug-lib"
2323
import module namespace flow = "http://marklogic.com/data-hub/flow-lib"
2424
at "/com.marklogic.hub/lib/flow-lib.xqy";
2525

26+
import module namespace perflog = "http://marklogic.com/data-hub/perflog-lib"
27+
at "/com.marklogic.hub/lib/perflog-lib.xqy";
28+
2629
declare namespace rapi = "http://marklogic.com/rest-api";
2730

2831
declare namespace hub = "http://marklogic.com/data-hub";
@@ -41,20 +44,22 @@ declare function get(
4144
$params as map:map
4245
) as document-node()*
4346
{
44-
debug:dump-env("GET FLOW"),
47+
perflog:logit('Flow.get',function() {
48+
debug:dump-env("GET FLOW"),
4549

46-
document {
47-
let $entity-name := map:get($params, "entity-name")
48-
let $flow-name := map:get($params, "flow-name")
49-
let $flow-type := map:get($params, "flow-type")
50-
let $resp :=
51-
if ($flow-name) then
52-
flow:get-flow($entity-name, $flow-name, $flow-type)
53-
else
54-
flow:get-flows($entity-name)
55-
return
56-
$resp
57-
}
50+
document {
51+
let $entity-name := map:get($params, "entity-name")
52+
let $flow-name := map:get($params, "flow-name")
53+
let $flow-type := map:get($params, "flow-type")
54+
let $resp :=
55+
if ($flow-name) then
56+
flow:get-flow($entity-name, $flow-name, $flow-type)
57+
else
58+
flow:get-flows($entity-name)
59+
return
60+
$resp
61+
}
62+
})
5863
};
5964

6065
(:~
@@ -68,11 +73,13 @@ declare %rapi:transaction-mode("update") function post(
6873
$input as document-node()*
6974
) as document-node()*
7075
{
71-
debug:dump-env("RUN FLOW"),
76+
perflog:logit('Flow.post',function() {
77+
debug:dump-env("RUN FLOW"),
7278

73-
let $flow as element(hub:flow) := $input/hub:flow
74-
let $identifier := map:get($params, "identifier")
75-
let $_ := flow:run-flow($flow, $identifier, map:map())
76-
return
77-
document { () }
79+
let $flow as element(hub:flow) := $input/hub:flow
80+
let $identifier := map:get($params, "identifier")
81+
let $_ := flow:run-flow($flow, $identifier, map:map())
82+
return
83+
document { () }
84+
})
7885
};

marklogic-data-hub/src/main/resources/ml-modules/services/tracing.xqy

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import module namespace debug = "http://marklogic.com/data-hub/debug-lib"
2323
import module namespace trace = "http://marklogic.com/data-hub/trace"
2424
at "/com.marklogic.hub/lib/trace-lib.xqy";
2525

26+
import module namespace perflog = "http://marklogic.com/data-hub/perflog-lib"
27+
at "/com.marklogic.hub/lib/perflog-lib.xqy";
28+
2629
declare namespace rapi = "http://marklogic.com/rest-api";
2730

2831
declare option xdmp:mapping "false";
@@ -32,9 +35,11 @@ declare function get(
3235
$params as map:map
3336
) as document-node()*
3437
{
35-
debug:dump-env(),
38+
perflog:logit('Tracing.get',function() {
39+
debug:dump-env(),
3640

37-
document { trace:enabled() }
41+
document { trace:enabled() }
42+
})
3843
};
3944

4045
declare %rapi:transaction-mode("update") function post(
@@ -43,11 +48,13 @@ declare %rapi:transaction-mode("update") function post(
4348
$input as document-node()*
4449
) as document-node()*
4550
{
46-
debug:dump-env(),
47-
48-
let $enable := map:get($params, "enable") = ("true", "yes")
49-
let $_ := trace:enable-tracing($enable)
50-
return
51-
(),
52-
document { () }
51+
perflog:logit('Tracing.post',function() {
52+
debug:dump-env(),
53+
54+
let $enable := map:get($params, "enable") = ("true", "yes")
55+
let $_ := trace:enable-tracing($enable)
56+
return
57+
(),
58+
document { () }
59+
})
5360
};

marklogic-data-hub/src/main/resources/ml-modules/services/validate.xqy

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import module namespace debug = "http://marklogic.com/data-hub/debug-lib"
2323
import module namespace flow = "http://marklogic.com/data-hub/flow-lib"
2424
at "/com.marklogic.hub/lib/flow-lib.xqy";
2525

26+
import module namespace perflog = "http://marklogic.com/data-hub/perflog-lib"
27+
at "/com.marklogic.hub/lib/perflog-lib.xqy";
28+
2629
declare option xdmp:mapping "false";
2730

2831
(:~
@@ -37,9 +40,11 @@ declare function get(
3740
$params as map:map
3841
) as document-node()*
3942
{
40-
debug:dump-env(),
41-
xdmp:set-response-content-type("application/json"),
42-
document {
43-
xdmp:to-json(flow:validate-entities())
44-
}
43+
perflog:logit('Validate.get',function() {
44+
debug:dump-env(),
45+
xdmp:set-response-content-type("application/json"),
46+
document {
47+
xdmp:to-json(flow:validate-entities())
48+
}
49+
})
4550
};

marklogic-data-hub/src/main/resources/ml-modules/services/writer.xqy

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import module namespace debug = "http://marklogic.com/data-hub/debug-lib"
2323
import module namespace flow = "http://marklogic.com/data-hub/flow-lib"
2424
at "/com.marklogic.hub/lib/flow-lib.xqy";
2525

26+
import module namespace perflog = "http://marklogic.com/data-hub/perflog-lib"
27+
at "/com.marklogic.hub/lib/perflog-lib.xqy";
28+
2629
declare namespace rapi = "http://marklogic.com/rest-api";
2730

2831
declare option xdmp:mapping "false";
@@ -32,11 +35,13 @@ declare %rapi:transaction-mode("update") function get(
3235
$params as map:map
3336
) as document-node()*
3437
{
35-
debug:dump-env(),
36-
37-
let $module-uri := map:get($params, "module-uri")
38-
let $identifier := map:get($params, "identifier")
39-
return
40-
(),
41-
document { () }
38+
perflog:logit('Writer.get',function() {
39+
debug:dump-env(),
40+
41+
let $module-uri := map:get($params, "module-uri")
42+
let $identifier := map:get($params, "identifier")
43+
return
44+
(),
45+
document { () }
46+
})
4247
};

marklogic-data-hub/src/main/resources/ml-modules/transforms/get-content.xqy

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ xquery version "1.0-ml";
22

33
module namespace transform = "http://marklogic.com/rest-api/transform/get-content";
44

5+
import module namespace perflog = "http://marklogic.com/data-hub/perflog-lib"
6+
at "/com.marklogic.hub/lib/perflog-lib.xqy";
7+
58
declare namespace envelope = "http://marklogic.com/data-hub/envelope";
69

710
declare function transform(
@@ -10,16 +13,18 @@ declare function transform(
1013
$content as document-node()
1114
) as document-node()
1215
{
13-
document {
14-
if ($content/envelope:envelope) then
15-
(
16-
map:put($context, "output-type", "application/xml"),
17-
$content/envelope:envelope/envelope:content/node()
18-
)
19-
else
20-
(
21-
map:put($context, "output-type", "application/json"),
22-
$content/content
23-
)
24-
}
16+
perflog:logit('GetContent.transform',function() {
17+
document {
18+
if ($content/envelope:envelope) then
19+
(
20+
map:put($context, "output-type", "application/xml"),
21+
$content/envelope:envelope/envelope:content/node()
22+
)
23+
else
24+
(
25+
map:put($context, "output-type", "application/json"),
26+
$content/content
27+
)
28+
}
29+
})
2530
};

0 commit comments

Comments
 (0)