Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE.md → LICENSE2.md
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,4 @@ specific requirements.
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.
aaaaa
189 changes: 0 additions & 189 deletions README.md

This file was deleted.

6 changes: 6 additions & 0 deletions blah
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fjkljflkdjf
fjkljflkdjf
fjkljflkdjf
fjkljflkdjf
fjkljflkdjf
fjkljflkdjf
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ black==21.5b2
mypy==0.901
isort==5.8.0
types-requests==0.1.9
types-dataclasses==0.1.5;python_version < '3.7'
20 changes: 17 additions & 3 deletions gprofiler/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
import gzip
import json
from io import BytesIO
from typing import Dict, List, Optional, Tuple
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple

import requests
from requests import Session

from gprofiler import __version__
from gprofiler.exceptions import APIError
from gprofiler.log import get_logger_adapter
from gprofiler.utils import get_iso8601_format_time
from gprofiler.utils import get_iso8601_format_time, get_iso8601_format_time_from_epoch_time

if TYPE_CHECKING:
from gprofiler.system_metrics import Metrics

logger = get_logger_adapter(__name__)

Expand Down Expand Up @@ -78,7 +81,13 @@ def _send_request(
opts["headers"]["Content-type"] = "application/json"
buffer = BytesIO()
with gzip.open(buffer, mode="wt", encoding="utf-8") as gzip_file:
json.dump(data, gzip_file, ensure_ascii=False) # type: ignore
try:
json.dump(data, gzip_file, ensure_ascii=False) # type: ignore
except TypeError:
# This should only happen while in development, and is used to get a more indicative error.
bad_json = str(data)
logger.exception("Given data is not a valid JSON!", bad_json=bad_json)
raise
opts["data"] = buffer.getvalue()

opts["params"] = self._get_query_params() + [(k, v) for k, v in params.items()]
Expand Down Expand Up @@ -119,6 +128,8 @@ def submit_profile(
profile: str,
total_samples: int,
profile_api_version: Optional[str],
spawn_time: float,
metrics: 'Metrics',
) -> Dict:
return self.post(
"profiles",
Expand All @@ -127,6 +138,9 @@ def submit_profile(
"end_time": get_iso8601_format_time(end_time),
"hostname": self._hostname,
"profile": profile,
"cpu_avg": metrics.cpu_avg,
"mem_avg": metrics.mem_avg,
"spawn_time": get_iso8601_format_time_from_epoch_time(spawn_time),
},
timeout=self._upload_timeout,
api_version="v2" if profile_api_version is None else profile_api_version,
Expand Down
9 changes: 9 additions & 0 deletions gprofiler/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ class UninitializedStateException(Exception):

class StateAlreadyInitializedException(Exception):
pass


class BadResponseCode(Exception):
def __init__(self, response_code: int):
super().__init__(f"Got a bad HTTP response code {response_code}")


class ThreadStopTimeoutError(Exception):
pass
Loading