| 56 | |
| 57 | |
| 58 | class PyTransaction(object): |
| 59 | |
| 60 | def __init__(self, mtype, mname): |
| 61 | self._mtype = mtype |
| 62 | self._mname = mname |
| 63 | self._status = CAT_SUCCESS |
| 64 | self._data = "" |
| 65 | self._duration = None |
| 66 | self._time = int(time.time() * 1000) |
| 67 | self._start = self._time |
| 68 | |
| 69 | def setStatus(self, t, status): |
| 70 | self._status = status |
| 71 | |
| 72 | def setTimestamp(self, t, timestamp): |
| 73 | self._time = timestamp |
| 74 | |
| 75 | def setDurationInMillis(self, t, duration): |
| 76 | self._duration = duration |
| 77 | |
| 78 | def setDurationStart(self, t, durationStart): |
| 79 | self._start = durationStart |
| 80 | |
| 81 | def addData(self, t, data): |
| 82 | if self._data == "": |
| 83 | self._data = data |
| 84 | else: |
| 85 | self._data += "&" + data |
| 86 | |
| 87 | def addKV(self, t, key, val): |
| 88 | if self._data == "": |
| 89 | self._data = "{}={}".format(key, val) |
| 90 | else: |
| 91 | self._data += "&{}={}".format(key, val) |
| 92 | |
| 93 | def complete(self, t): |
| 94 | t = ccat.newTransaction(_(self._mtype), _(self._mname)) |
| 95 | try: |
| 96 | t.setStatus(t, _(self._status)) |
| 97 | t.setTimestamp(t, self._time) |
| 98 | t.setDurationInMillis(t, self._duration_ms) |
| 99 | t.addData(t, _(self._data)) |
| 100 | finally: |
| 101 | t.complete(t) |
| 102 | |
| 103 | @property |
| 104 | def _duration_ms(self): |
| 105 | if self._duration is None: |
| 106 | return int(time.time() * 1000 - self._start) |
| 107 | return self._duration |
| 108 | |
| 109 | |
| 110 | class catSdk(object): |