Эх сурвалжийг харах

refactor: time.sleep() add: TIME:info

micha 1 жил өмнө
parent
commit
b993b2b614
4 өөрчлөгдсөн 89 нэмэгдсэн , 43 устгасан
  1. 19 6
      _LibreLightDesk.py
  2. 62 32
      _console.py
  3. 5 5
      lib/zchat.py
  4. 3 0
      tksdl/midi.py

+ 19 - 6
_LibreLightDesk.py

@@ -187,7 +187,7 @@ def showwarning(msg="<ERROR>",title="<TITLE>"):
     geo ="{}x{}".format(20,20)
     _main.geometry(geo)
     def _quit():
-        time.sleep(.02)
+        time.sleep(1/10)
         _main.quit()
     thread.start_new_thread(_main.mainloop,())
     #_main.quit()
@@ -376,7 +376,7 @@ r1_server = chat.Server(port=30002)
 def server1_loop():
     while 1:
         r1_server.poll(cb=JCB)
-        time.sleep(0.01)
+        #time.sleep(1/90)
 thread.start_new_thread(server1_loop,()) # SERVER
 # remote input - end
 #chat.dbg=1
@@ -441,7 +441,15 @@ def JSCB(x,sock=None):
                                     exec_nr = int(msg["EXEC"])
                                 if val >= 0 and exec_nr > 0:
                                     print("PRESET_GOOO",exec_nr,val)
+                                    s = time.time()
                                     master.preset_go(exec_nr-1,xfade=None,val=val)
+                                    e = time.time()
+                                    #print("time:",e-s,e)
+                                    #print("TIME:",int((e-s)*1000),int(e*10)-1_703_800_000)
+                                    #print("TIME:",int((e-s)*1000),int(e*10)/10)
+                                    print("EXE TIME:","{:0.02f}".format(e-s),int(e*100)/100)
+                                    print()
+
                             except Exception as e:
                                 print("EXEC ERR:",e)
             #bounce msg
@@ -461,6 +469,7 @@ def JSCB(x,sock=None):
             msg = bytes(msg,"utf8")
             chat._send(sock,msg)
 
+    #time.sleep(1/60)
 
 
 # external GUI
@@ -468,7 +477,7 @@ r_server = chat.Server(port=30003,cb=JSCB)
 def server_loop():
     while 1:
         r_server.poll(cb=JSCB)
-        time.sleep(0.001)
+        #time.sleep(1/90)
 thread.start_new_thread(server_loop,()) # SERVER
 
 # read memcachd
@@ -599,7 +608,7 @@ class MC():
                             traceback.print_exc()
                             pass
 
-                time.sleep(0.01)
+                time.sleep(1/10)
             except Exception as e:
                 cprint("exc", e)
                 time.sleep(1)
@@ -2902,6 +2911,7 @@ class MASTER():
                 #elem["bg"] = "yellow"
 
     def preset_go(self,nr,val=None,xfade=None,event=None,button="",ptfade=None):
+        s=time.time()
         t_start = time.time()
         if xfade is None and FADE._is():
             xfade = FADE.val()
@@ -2948,9 +2958,12 @@ class MASTER():
             self._preset_go(rdata,cfg,fcmd,value,xfade=0,xFLASH=xFLASH)
         elif button == "go" or ( modes.val("GO") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["go","GO"])): 
             fcmd  = FIXTURES.update_raw(rdata)
+            e=time.time()
+            print("_GO TIME:","{:0.02f}".format(e-s),int(e*10)/10)
             self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,ptfade=ptfade,nr=nr)
-
-
+            e=time.time()
+            print("GO TIME:","{:0.02f}".format(e-s),int(e*10)/10)
+        return
 
         if not (modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL")): #FLASH
             self.refresh_exec()

+ 62 - 32
_console.py

@@ -107,7 +107,7 @@ def artnet_loop():
     while 1:
         #artnet._test_frame()
         artnet.next()
-        time.sleep(0.01)
+        time.sleep(0.001)
 
 
 class CLOCK():
@@ -135,7 +135,7 @@ class CLOCK_REAL():
     def __init__(self):
         self.__time = 0
         self.__start = time.time() # only for debugging
-        self.__tick = 0.01 # incremental timer drift's on highe cpu load ?
+        self.__tick = 0.001 # incremental timer drift's on highe cpu load ?
     def time(self):
         self.__time = time.time()
         return self.__time
@@ -947,14 +947,17 @@ class Main():
             except:pass
             self.lock.release_lock()
             #self.lock.acquire_lock()
-            time.sleep(0.01)
+            #time.sleep(1/35)
             fps += 1
-            if fps >= 100:
+            stop_fps = 50
+            time.sleep(1/60)
+            if fps >= stop_fps:
                 fps_t = time.time()
                 #print(int((fps_t-fps_start)*1000),"ms") 
-                print(round(100/(fps_t-fps_start),2),"core/fps") 
+                print(round(stop_fps/(fps_t-fps_start),2),"core/fps") 
                 fps = 0
                 fps_start = time.time()
+                time.sleep(1/60)
 
 main = Main()
 if __run_main:
@@ -1011,30 +1014,8 @@ def set_dmx_fine_ch(Admx,dmx_fine_nr):
         cprint(x,color="red")
         cprint("except 3455",e,color="red")
 
-def JCB(data,sock=None): #json client input
-    t_start = time.time()
-    #print("-->-",data)
-    jdatas = []
-    l2 = 0
-    for line in data:
-        data2 = json.loads(line)
-        l2 += len(data2)
-        #print("line:",line)
-        jdatas.append(data2) #["CMD"])
-
-    print("INPUT JCB =>",len(data),":",l2)
-    c = clock.time() 
-    c = float(c)
-    ftime = 0
-    delay = 0
-
-    for cmds in jdatas:
-
-        master_fx = MASTER_FX()
-        if not cmds:
-            continue
-
-        try:
+def parse_cmds(cmds,clock=0,master_fx=None):
+            c=clock
             out = {}
             for x in cmds:
                 Admx = DMXCH() #dummy
@@ -1057,7 +1038,7 @@ def JCB(data,sock=None): #json client input
                         size_master.val(x["NR"],x["VALUE"])
 
                 else:
-                    print(x)
+                    #print("x",x)
                     
                     if "DMX" in x:
                         DMX = int(x["DMX"])
@@ -1208,10 +1189,52 @@ def JCB(data,sock=None): #json client input
                             CB({"cmd":"fxf"+ccm})
                         else:
                             CB({"cmd":"fx"+ccm})
+            return out
+import hashlib
+JCB_GLOB_BUF = {}
+def JCB(data,sock=None): #json client input
+    t_start = time.time()
+    s = time.time()
+    e = time.time()
+    print("JCB TIME:","{:0.02f}".format(e-s),int(e*100)/100)
+    #print("-->-",data)
+    jdatas = []
+    l2 = 0
+    for line in data:
+        
+        data2 = json.loads(line)
+        l2 += len(data2)
+        #print("line:",line)
+        jdatas.append(data2) #["CMD"])
+
+    print("INPUT JCB =>",len(data),":",l2)
+    c = clock.time() 
+    c = float(c)
+    ftime = 0
+    delay = 0
+
+    for cmds in jdatas:
+        line = json.dumps(cmds)
+        #md5 = hashlib.md5.hexdigest(line)
+
+        master_fx = MASTER_FX()
+        if not cmds:
+            continue
+
+        try:
+            out = parse_cmds(cmds,clock=c,master_fx=master_fx)
 
 
             #cprint("-","{:0.04} sec.".format(time.time()-t_start),color="yellow")
             # ------- ---------------------------------------------------- 
+
+        except Exception as e:
+            cprint("EXCEPTION JCB",e,color="red")
+            cprint("----",str(cmds)[:150],"...",color="red")
+            cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
+            raise e
+    if out:
+        try:
             try: # second loop to sync-start all dmxch's
                 main.lock.acquire_lock()
                 for _id in out:
@@ -1228,16 +1251,23 @@ def JCB(data,sock=None): #json client input
                                 #print("SET V_MASTER",row)
                             
                     _init_action(row)
+                e = time.time()
+                print(" sub-JCB TIME:","{:0.02f}".format(e-s),int(e*100)/100)
 
             finally:
                 main.lock.release_lock()
+            #time.sleep(1/30)
 
         except Exception as e:
             cprint("EXCEPTION JCB",e,color="red")
             cprint("----",str(cmds)[:150],"...",color="red")
             cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
             raise e
-    #cprint(" ","{:0.04} sec.".format(time.time()-t_start),color="yellow")
+
+        #cprint(" ","{:0.04} sec.".format(time.time()-t_start),color="yellow")
+        e = time.time()
+        print("JCB TIME:","{:0.02f}".format(e-s),int(e*100)/100)
+        time.sleep(1/60)
             
 def CB(data): # raw/text client input 
     #print("CB",data)
@@ -1346,7 +1376,7 @@ if __run_main:
     s = chat.Server(cb=JCB)
     while 1:
         s.poll()
-        time.sleep(0.01)
+        time.sleep(0.001)
 
 
 

+ 5 - 5
lib/zchat.py

@@ -128,7 +128,7 @@ class Poll():
                     print("Exception self.cb",e)
                     print(traceback.format_exc())
             else:
-                time.sleep(0.02)
+                time.sleep(0.002)
 
     def _rloop(self):
         msg = b""
@@ -145,7 +145,7 @@ class Poll():
                 finally:
                     self.lock.release()
             else:
-                time.sleep(0.1)
+                time.sleep(0.001)
 
 # CORE CLASSES ---
 
@@ -203,7 +203,7 @@ class Server():
                 print("+++ Client %s open" % addr[0],client)
             finally:
                 self.client_lock.release()
-                time.sleep(0.2)
+                time.sleep(0.02)
 
     def rem_client(self,client):
         self.client_lock.acquire()
@@ -238,7 +238,7 @@ class Server():
     def poll(self,cb=None):
         self.check_client()
         idle = 1
-        time.sleep(0.1)
+        time.sleep(0.001)
         return
 
         for sock in self.get_clients():
@@ -256,7 +256,7 @@ class Server():
                 self.cb(msg)
 
         if idle:
-            time.sleep(0.02)
+            time.sleep(0.002)
         
 
 

+ 3 - 0
tksdl/midi.py

@@ -196,6 +196,7 @@ while 1:
 
     try:
         if apc_main.buf:
+            s = time.time()
             buf = apc_main.buf[:]
             apc_main.buf = []
             buf2=[]
@@ -213,6 +214,8 @@ while 1:
             if msgs:
                 msgs = json.dumps(msgs).encode("utf-8")
                 cmd_client.send(msgs)
+                e = time.time()
+                print("TIME:",int((e-s)*10000),int(e*100)/100)
                     
     except Exception as e:
         print("midi",e)