working memory attribute on info - #958
Conversation
| factor = UNIT_FACTORS[match[1][-1]] | ||
| mem_value = factor*(match[1][...-1].to_i) |
There was a problem hiding this comment.
By golly that looks ugly. Does this look better? In any case
number, factor = match[1].split(/([KMGTP])/)
UNIT_FACTORS[factor] * number.to_iCan't get match[1].split(/([UNIT_FACTORS.keys.join])/) to work so there's a duplication in keys there.
Either way you don't need the mem_value assignment and there should likely be some safeguard for factor being nil because we can run into a undefined method *' for nil (NoMethodError)` here.
There was a problem hiding this comment.
By golly that looks ugly.
It's the double [][] calls that's getting to me. I think at the very least we can give match[1] a name.
There was a problem hiding this comment.
OK I think I have this figured out in the cleanest way possible. I'll quote the updated method here for convenience.
match = tres.match(/(?:^|,)mem=(\w+)(?:,|$)/)
return unless match
(number, unit) = match[1].scan(/\d+|\D+/)
factor = UNIT_FACTORS[unit]
mem_value = factor.to_i * number.to_i
return mem_value == 0 ? nil : mem_valueThis way we only call match[1] once. We scan to split cleanly into digits and characters (either of which could be nil or blank, depending). No matter what value unit has we are either getting a number or nil from UNIT_FACTORS[unit]. So when we cast both to integers, nil.to_i == 0 and "".to_i == 0. So if the final value is 0 we know something was missing and return nil. Add to that the fact that there should never be a valid '0M' value coming out of slurm, and I think this effectively boils down individual checks on each variable to a single check on the final value. What do you think?
There was a problem hiding this comment.
What do you think?
That'll work for me, though I just thought of changing /(?:^|,)mem=(\w+)(?:,|$)/ to pull both the number and the factor out of it.
But really it's an issue of readability for me and not so much the performance. just having match = match[1] would have worked for me.
There was a problem hiding this comment.
Ok, in that case I made one more update keeping the zero check but opting for plain string indexing over the regex, since that is much more readable to me. I also realized that to_i will ignore the final non-digit character, so we don't even need to bother with the match_str[...-1], since '1234M'.to_i == 1234 and 'M'.to_i == 0.
|
This should be passing tests now. Do we want to query for memory in |
We should implement it separately if at all. Are they different values? |
It should be the same value, just |
What does this PR do?
Reworks #879 to add a field for total memory to the job info object. While inconsistent values from
MinMemoryhalted that effort the last time, this PR fetches memory data from thetres-allocflag, which consistently shows the total for the whole job, as can be seen in the following outputUnfortunately the tres-alloc field does not respect the --noconvert flag, and so we include the unit conversion piece from #879.
After these changes, we will be able to access total memory (in bytes) from the info object, which will allow us to add it to the session card and active jobs in ondemand (OSC/ondemand#1006 and OSC/ondemand#1007)
Related issue
Fixes #878 (if applicable)
Testing
Testing is in progress and will be included soon
Checklist
Anything else?
Screenshots, context, or anything reviewers should pay close attention to.