--- /dev/null
+#####################
+lfParallelCostCapture
+#####################
+
+Parameters
+==========
+
+None.
+
+Usage
+=====
+
+This function is designed to run at the end of a parallel stage that has spun
+up a temporary node. It will pull in the cost data, and stash it in a file
+titled "stack-cost". This can then be picked up by the job-cost.sh script.
+
+.. warning::
+ Calling this function requires that the Lockable Resources Plugin is
+ installed.
+
+An example of the intended implementation:
+
+.. code-block:: groovy
+
+ parallel {
+ stage('1') {
+ node {newNode1} // Only add post stage if a new node is being used
+ stages {<all stages>}
+ post {
+ always {
+ lfParallelCostCapture()
+ }
+ }
+ }
+ stage('2') {
+ node {newNode2}
+ stages {<all stages>}
+ post {
+ always {
+ lfParallelCostCapture()
+ }
+ }
+ }
+ }
+
+The calling pipeline must manually unstash the "stack-cost" file. For LF
+Pipelines, this is handled by the lfInfraShipLogs function.
-Subproject commit e3b47c77a181b5f5bd3a79802a46188adb6173ce
+Subproject commit 53f811d91411bf26a4acf00a9244c6ea0f4510d5
--- /dev/null
+---
+features:
+ - |
+ New global var lfParallelCostCapture. This is a function to be run as a
+ "post" call at the end of each stage within a parallel block, which will
+ gather cost data from dynamically-allocated build nodes. It outputs a file
+ titled "stack-cost" and stashes it. lfInfraShipLogs has been modified to
+ unstash this file, which will automatically be picked up by the job-cost.sh
+ script.
sh(script: libraryResource('shell/python-tools-install.sh'))
echo 'Running shell/sudo-logs.sh'
sh(script: libraryResource('shell/sudo-logs.sh'))
+
+ // Check for stashed "stack-cost" file, used to get cost data from
+ // parallel builds.
+ try {
+ unstash "stack-cost"
+ } catch(Exception e) {}
+
echo 'Running shell/job-cost.sh'
sh(script: libraryResource('shell/job-cost.sh'))
--- /dev/null
+// SPDX-License-Identifier: Apache-2.0
+//
+// Copyright (c) 2019 Intel Corporation
+// Copyright (c) 2020 The Linux Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+def call() {
+ sh(script: libraryResource('shell/job-cost.sh'))
+ cost_str = sh(script: "cat $WORKSPACE/archives/cost.csv | cut -d, -f6", returnStdout: true)
+
+ lock("${BUILD-TAG}-stack-cost") {
+ try {
+ unstash "stack-cost"
+ stack_cost = sh(script: "cat stack-cost | awk '{print \$2}", returnStdout: true)
+ } catch(Exception e) {
+ stack_cost = 0
+ }
+
+ cost = (cost_str as float) + (stack_cost as float)
+ sh("echo total: ${cost} > stack-cost")
+ stash includes: "**/stack-cost", name: "stack-cost"
+ }
+}