ValueError: could not convert string to float:
Traceback (most recent call last):
File "/home/patmy/shell-profiler/profile", line 74, in <module>
profiling_with_timings = map(collect_timings, tokenized_trace, range(len(tokenized_trace)))
File "/home/patmy/shell-profiler/profile", line 31, in collect_timings
timing = float(tokenized_trace[index+1][1]) - float(tokens[1])
ValueError: could not convert string to float:
tokenized_trace[index+1] is ['Usage', '\n', '']
tokenized_trace[index+1][1] is a string consisting of solely a new line character
$ bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
$ python --version
Python 2.7.12
$ bash --version
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
Copyright (C) 2007 Free Software Foundation, Inc.
$ python --version
Python 2.7.15
@PatMyron I'm not sure what's happening there and I can't reproduce with the test script. Perhaps you could provide a small test script that reproduces this error.
Trimmed down example script:
echo >&2 "hi"
Commands and outputs:
$ example.sh hi
$ ~/shell-profiler/profile ~/shell-profiler/example.sh --debug Done executing. --- END OF PROFILING --- tokenized trace is: [['>', '1544648783.N', '/bin/bash', 'line 1', 'echo hi\n'], ['hi\n', ''], ['>', '1544648783.N', '/bin/bash', 'line 2', 'echo --- END OF PROFILING ---\n']] tokens are ['>', '1544648783.N', '/bin/bash', 'line 1', 'echo hi\n'] Traceback (most recent call last): File "./profile", line 72, in
profiling_with_timings = map(collect_timings, tokenized_trace, range(len(tokenized_trace))) File "./profile", line 29, in collect_timings timing = float(tokenized_trace[index+1][1].replace(".N", "")) - float(tokens[1].replace(".N", "")) ValueError: could not convert string to float:
I have similar issue about this.
The main reason of this issue is the variable of script not always single line. Sometimes it contain multiple line. According to the original design of profile. It will read the line that did not contain timeing. causing 'could not convert string to float:' there are somebody has already fix this issue. https://github.com/jon-turney/shell-profiler/commit/096b7b57a941cb88e50013543ae5b8dd93579100 by only collect the line which has '>' begin with.
So, is this problem solved?