From bb42aca24df169ef0ffe3be40d53013cef630f10 Mon Sep 17 00:00:00 2001
From: Felip Moll <felip.moll@schedmd.com>
Date: Mon, 20 Aug 2018 16:14:40 -0600
Subject: [PATCH] Fix negative values when profiling.

Bug 5072
---
 NEWS                                           |  1 +
 src/plugins/jobacct_gather/common/common_jag.c | 10 ++++++++++
 2 files changed, 11 insertions(+)

diff --git a/NEWS b/NEWS
index c123e9bf35c..045e5ab25cb 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,7 @@ documents those changes that are of interest to users and administrators.
     (i.e. gres=gpu/tesla) it would get a count of 0.
  -- Allow sstat to talk to slurmd's that are new in protocol version.
  -- Permit database names over 33 characters in accounting_storage/mysql.
+ -- Fix negative values when profiling.
 
 * Changes in Slurm 17.11.9-2
 ============================
diff --git a/src/plugins/jobacct_gather/common/common_jag.c b/src/plugins/jobacct_gather/common/common_jag.c
index d545d1de3b5..69859f512aa 100644
--- a/src/plugins/jobacct_gather/common/common_jag.c
+++ b/src/plugins/jobacct_gather/common/common_jag.c
@@ -728,6 +728,10 @@ static void _record_profile(struct jobacctinfo *jobacct)
 	} else {
 		data[FIELD_CPUTIME].d =
 			jobacct->tot_cpu - jobacct->last_total_cputime;
+
+		if (data[FIELD_CPUTIME].d < 0)
+			data[FIELD_CPUTIME].d = jobacct->tot_cpu;
+
 		et = (jobacct->cur_time - jobacct->last_time);
 		if (!et)
 			data[FIELD_CPUUTIL].d = 0.0;
@@ -739,8 +743,14 @@ static void _record_profile(struct jobacctinfo *jobacct)
 		data[FIELD_READ].d = jobacct->tot_disk_read -
 			jobacct->last_tot_disk_read;
 
+		if (data[FIELD_READ].d < 0)
+			data[FIELD_READ].d = jobacct->tot_disk_read;
+
 		data[FIELD_WRITE].d = jobacct->tot_disk_write -
 			jobacct->last_tot_disk_write;
+
+		if (data[FIELD_WRITE].d < 0)
+			data[FIELD_WRITE].d = jobacct->tot_disk_write;
 	}
 
 	if (debug_flags & DEBUG_FLAG_PROFILE) {
-- 
GitLab