Jump to content

zak100

Senior Members
  • Content Count

    34
  • Joined

  • Last visited

Community Reputation

0 Neutral

About zak100

  • Rank
    Quark

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hi, I want to create a graph from the following data. Please provide me the steps. Garph1 BS CPU Percentage 12 Memory Usage 15773696 sdiskusage total 9.82901E+11 sdiskusage used 1.41429E+11 sdisk usage free 7.91472E+11 sdisk usage percentage 15.2 virtual Memory 10234679296 rss 15773696 Time 1.026669979 Graph2 SS CPU Percentage 2 Memory Usage 15769600 sdiskusage total 9.82901E+11 sdiskusage used 1.41429E+11 sdisk usage free 7.91472E+11 sdisk usage percentage 15.2 virtual Memory 10545913856 rss 15769600 Time 1.026956081 Graph3 BSBS CPU Percentage 12 Memory Usage 15773696 sdiskusage total 9.82901E+11 sdiskusage used 1.41429E+11 sdisk usage free 7.91472E+11 sdisk usage percentage 15.2 virtual Memory 10234679296 rss 15773696 Time 1.071877241 Problem with the attached graph is that its creating the same graph for all the 3 data. How can I create variation using decimal values?Also it is not considering time? Somebody please guide me.
  2. Hi, I have a text file created on notepad. I want to convert it into GIF. I found the following link: Converting text to gif But the problem is that I can't specify the image resolution in the above link. It works great. I tried paint but it does not accept text file. My visio is very old and I am not satisfied with the quality of gif created by this 2003 version. So I am thinking to write my own converter. Is it possible? Not really, its my personal task. But I want to prefer Python at this point as I am studying this right now. Zulfi.
  3. Hi, I want to create a GIF file from a text file of 500 x 500 dimensions. I got some help to create the following program which works fine but I have not tried it for text file. Also how I can add the 500 x 500 dimension. My code is: import imageio images = [] filenames = ["one.jpeg", "two.png", "three.png"] for filename in filenames: images.append(imageio.imread(f'./images/{filename}')) #imageio. imageio.mimsave('./images/movie.gif', images) Somebody please guide me. Zulfi.
  4. Hi, Thanks for your useful suggestion and links. Sorry, I could not understand the code provided at: Instead I used a simple solution which i discussed earlier and I found the link also: https://www.bogotobogo.com/python/Multithread/python_multithreading_Identify_Naming_Logging_threads.php My output is this: Though the output is still garbled but not I know which thread is printing what. God bless you guys. My problem is solved now. Zulfi.
  5. Hi, while th1.is_alive(): print("CPU usage:" + str(psutil.Process(pid).cpu_percent(interval=1))) print("thread1 ended") while th2.is_alive(): print("CPU usage:" + str(psutil.Process(pid).cpu_percent(interval=1))) Thanks for your response. Right now its showing CPU usage for only one thread, I have to modify the above code to see for which code its printing CPU usage. Yes, its possible to add the values of two CPU_percent(..) values. Good idea, but first I want to see using large values whether its printing two cpu usage percentages or just one. I would try and then get back to you people. Zulfi.
  6. Hi, Thanks for your response. Okay let's suppose we want to work on two case: 1) Concurrent Execution, may produce jumbled output 2) Running two threads accessing the data at the same time but their output is separate, i.e. we can avoid the jumbled output which I am seeing right now Also for the both the above cases how can I get a combined CPU Usage ? <Have you tried some other online sources or books? . > Not in this case but for CPU usage I did a search. But I would do it now. Thanks. Zulfi.
  7. Hi, My code for selection sort, It prints 3 CPU usage statements: 2 after display random numbers and one after sorting. import random import psutil import os import threading class SSSort: arr = [] # class var access by className.arr def __init__(self, n): self.n = n def generate1000_5digit_RandomNum(self): for i in range(self.n): num = random.randint(10000, 99999) SSSort.arr.append(num) for j in range(self.n): print("random {0}".format(SSSort.arr[j])) def cpu_util_info(self):#make sure different than posted k= self.n arr2 = SSSort.arr[:] def find_the_min_element(k, i, arr2): min = i for j in range(i+1, k): if (arr2[j] < arr2[min]): min = j return min def selectionSort(k, arr2): for i in range(self.n): min = find_the_min_element(k, i, arr2) # swap min and ith element of array temp = arr2[min] arr2[min]= arr2[i] arr2[i] =temp for i in enumerate(arr2): print(i) pid = os.getpid() # current process print("start thread") psutil.Process(pid).cpu_percent(interval=0) th = threading.Thread(target=selectionSort, args=(k, arr2)) th.start() while th.is_alive(): print("CPU usage:" + str(psutil.Process(pid).cpu_percent(interval=1))) print("all done") def main(self): self.generate1000_5digit_RandomNum() self.cpu_util_info() print("memory usage= ", psutil.Process(os.getpid()).memory_info()[0]) print("disk usage= ", psutil.disk_usage('/')) print("virtual mem= ", psutil.virtual_memory().available) print("rss= ", psutil.Process(os.getpid()).memory_info().rss) if __name__ == "__main__": objSSSort = SSSort(10000) objSSSort.main() The output is: Note for 5000, I am getting 2 spu percentages one after random and one after sorting. The above is for 10000 numbers. Thanks for your cooperation. Zulfi.
  8. Hi, I have two sorting programs. I want to concurrently execute them. I have written the following code using help from this forum: pid = os.getpid() # current process print("start thread") psutil.Process(pid).cpu_percent(interval=0) th1 = threading.Thread(target=BubbleSort, args=(k, arr2)) th2 = threading.Thread(target=selectionSort, args=(k, arr2)) th1.start() th2.start() while th1.is_alive(): print("CPU usage:" + str(psutil.Process(pid).cpu_percent(interval=1))) print("thread1 ended") while th2.is_alive(): print("CPU usage:" + str(psutil.Process(pid).cpu_percent(interval=1))) print("thread2 ended") print("all done") Following is the output. This clearly shows that the execution of two threads is overlapping . Initially thread 1 starts prints the sorted list and then control goes to thread2 which prints first 4 numbers and then the control again goes to thread1 which prints the message " thread 1 ended". I want to run the thread 1 to completion and then to start the thread2. In Java we have "synchronize" command. Please guide me how to achieve mutual exclusion in Python. The complete code is: import random import psutil import os import threading class SSSort: arr = [] # class var access by className.arr def __init__(self, n): self.n = n def generate1000_5digit_RandomNum(self): for i in range(self.n): num = random.randint(10000, 99999) SSSort.arr.append(num) for j in range(self.n): print("random {0}".format(SSSort.arr[j])) def cpu_util_info(self): # make sure different than posted k = self.n arr2 = SSSort.arr[:] def find_the_min_element(k, i, arr2): min = i for j in range(i + 1, k): if (arr2[j] < arr2[min]): min = j return min def BubbleSort(k, arr2): for i in arr2: for j in range(len(arr2) - 1): if (arr2[j] > arr2[j + 1]): temp = arr2[j] arr2[j] = arr2[j + 1] arr2[j + 1] = temp for i in enumerate(arr2): print(i) def find_the_min_element(k, i, arr2): min = i for j in range(i+1, k): if (arr2[j] < arr2[min]): min = j return min def selectionSort(k, arr2): for i in range(self.n): min = find_the_min_element(k, i, arr2) # swap min and ith element of array temp = arr2[min] arr2[min]= arr2[i] arr2[i] =temp for i in enumerate(arr2): print(i) pid = os.getpid() # current process print("start thread") psutil.Process(pid).cpu_percent(interval=0) th1 = threading.Thread(target=BubbleSort, args=(k, arr2)) th2 = threading.Thread(target=selectionSort, args=(k, arr2)) th1.start() th2.start() while th1.is_alive(): print("CPU usage:" + str(psutil.Process(pid).cpu_percent(interval=1))) print("thread1 ended") while th2.is_alive(): print("CPU usage:" + str(psutil.Process(pid).cpu_percent(interval=1))) print("thread2 ended") print("all done") def main(self): self.generate1000_5digit_RandomNum() self.cpu_util_info() if __name__ == "__main__": objSSSort = SSSort(10) objSSSort.main() Zulfi. Somebody please guide me, how to solve this problem. Zulfi.
  9. Hi, Thanks for your reply. I am thinking of using the 2nd approach also. But right now I want to correct the cpu usage message problem with the first approach. Please guide me. I want to understand what is my error? I ran the code for 5000 values but still I got multiple values for cpu usages: Though at the end it printed me the single value: Thanks for your cooperation. Zulfi.
  10. Hi, Thanks for your interest in solving my problem. Through your guidance, I am able to print cpu_percent. Of course I have to use 10,000 integer numbers. Now the problem is w.r.t printing of cpu_percent twice as I discussed in post#24. Please guide me why the code is printing cpu_percent() message twice. May God bless you with great success. Zulfi.
  11. Hi, Thanks a lot for correcting my code. God bless you. I want to now focus why I am getting several CPU usage messages. I just want two messages. One message at the start i.e. when I start the measuring of CPU utilization and one at the end i.e. message stating that the sorting completed and for the entire completed process, the total CPU utilization is this much. This is what you were doing. Right now my code is working in the following way: i.e. it is printing the CPU usage after generating random numbers. This happens when the task is assigned to the thread and "th.start()" is executed and the thread enters the while loop. It might be possible that this line: print("CPU usage:" + str(psutil.Process(pid).cpu_percent(interval=1))) is being executed by both the main thread and the new thread. Please guide me. You have pointed out some very good issues. I surely want to focus on them but right now my objective is to make my program behave in the same way as yours is working. But at this point I want to focus on cpu utilization. Kindly guide me. Zulfi.
  12. Hi, Thanks, your trick succeeded. I have to make changes in the code. I have used inner function. Sorting code got disturbed. Its showing multiple output for cpu utlization. Somebody please correct my code. import random import psutil import os import threading class SSSort: arr = [] # class var access by className.arr def __init__(self, n): self.n = n def generate1000_5digit_RandomNum(self): for i in range(self.n): num = random.randint(10000, 99999) SSSort.arr.append(num) for j in range(self.n): print("random {0}".format(SSSort.arr[j])) def cpu_util_info(self): k= self.n arr2 = SSSort.arr[:] def find_the_min_element(k, i, arr2): min = i for j in range(i+1, k): if (arr2[j] < arr2[min]): min = j return min def selectionSort(k, arr2): for i in range(self.n): min = find_the_min_element(k, i, arr2) # swap min and ith element of array temp = arr2[min] arr2[min]= arr2[i] arr2[i] =temp for i in enumerate(SSSort.arr): print(i) pid = os.getpid() # current process print("start thread") psutil.Process(pid).cpu_percent(interval=0) th = threading.Thread(target=selectionSort, args=(k, arr2)) th.start() while th.is_alive(): print("CPU usage:" + str(psutil.Process(pid).cpu_percent(interval=1))) print("all done") def main(self): self.generate1000_5digit_RandomNum() self.cpu_util_info() if __name__ == "__main__": objSSSort = SSSort(20) objSSSort.main() I have two problems: 1) Multiple out for CPU Utilization statement 2) Sorting is not correct. Somebody please correct my code. Its showing multiple cpu utlization and sorting is not correct. Zulfi.
  13. Hi, Thanks for your program. It looks that the key is creating another thread. I also tried with large values but did not create a separate thread. (interval=0) not important. They wait for input. Do you mean that the blocking call stops the execution of all processes and then returns the cpu time for a particular process? Zulfi.
  14. Hi, Thanks for your interest in my problem. I have not explicitly created any thread. I have used the cpu-percent before and after psutil but I am getting zero in both the cases. Somebody please guide me. Zulfi. Hi, I am trying the selection with 1 million integers but my system hangs up. I am using following following command: if __name__ == "__main__": objSSSort = SSSort(1000000) objSSSort.main() In the above code, I am trying to run my selection sort program with 1000000 integers How to solve this problem in Python? Is there any size limitation with integers in python? Zulfi.
  15. Hi and Good Morning, CPU utilization information is still zero. I tried with the sorting code: def systeminfo(self): print("memory usage=", psutil.Process(os.getpid()).memory_info()[0]) print(psutil.disk_usage('/')) print(psutil.Process(os.getpid()).cpu_percent(interval=1)) print("virtual mem= ", psutil.virtual_memory().available) # print(psutil.Process(os.getpid()).memory_info().pfaults) print("rss=", psutil.Process(os.getpid()).memory_info().rss) self.selectionSort() print(psutil.Process(os.getpid()).cpu_percent(interval=1)) def main(self): self.generate1000_5digit_RandomNum() self.systeminfo() if __name__ == "__main__": objSSSort = SSSort(1000) objSSSort.main() I tried sorting with 1000 elements. and at other place: Somebody please guide me. Zulfi.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.