Skip to content

G-UTILS-GPROFILER REWORK (1): Add original files #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

granulatedekel
Copy link

@granulatedekel granulatedekel commented Sep 23, 2024

Part of the G-UTILS-GPROFILER REWORK saga - which aims to move away shared code from gprofiler to the g-utils project:
#263 #261 intel/gprofiler#925 intel/gprofiler#926 intel/gprofiler#926

This PR is responsible for simply adding the files from gprofiler as-is (besides import changes), however it's broken as not all dependencies are added - those altered files will be handled in the subsequent PR

@granulatedekel granulatedekel changed the title add unedited gprofiler files in GPROFILER REWORK (1): Add original files Sep 23, 2024
@granulatedekel granulatedekel changed the title GPROFILER REWORK (1): Add original files G-UTILS-GPROFILER REWORK (1): Add original files Sep 23, 2024
@granulatedekel granulatedekel added the g-utils-gprofiler-rework PRs related to the G-UTILS-GPROFILER saga label Sep 23, 2024
@granulatedekel granulatedekel marked this pull request as ready for review September 23, 2024 22:51
@YoniKF YoniKF requested a review from roi-granulate October 1, 2024 10:15
return wrapper


def start_process(
Copy link
Contributor

@roi-granulate roi-granulate Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a reminder to update this function before merging

@roi-granulate
Copy link
Contributor

@granulatedekel We should refrain from any mention of gprofiler (or any specific product) in any utility module.
while I have no problem with this PR having such granulate_utils/gprofiler hierarchy as a provisional step, one of your PR’s (#261 or another, new one) should take care of that.

Copy link
Contributor

@roi-granulate roi-granulate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Comment on lines +1 to +109
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import signal
import subprocess
from typing import List, Union


class PerfNoSupportedEvent(Exception):
pass


class StopEventSetException(Exception):
pass


class ProcessStoppedException(Exception):
pass


class CalledProcessError(subprocess.CalledProcessError):
# Enough characters for 200 long lines
MAX_STDIO_LENGTH = 120 * 200

def __init__(
self,
returncode: int,
cmd: Union[str, List[str]],
output: str,
stderr: str,
):
assert isinstance(returncode, int), returncode
assert isinstance(cmd, str) or all(isinstance(s, str) for s in cmd), cmd
assert output is None or isinstance(output, str), output
assert stderr is None or isinstance(stderr, str), stderr
super().__init__(returncode, cmd, output, stderr)

def _truncate_stdio(self, stdio: str) -> str:
if len(stdio) > self.MAX_STDIO_LENGTH:
stdio = stdio[: self.MAX_STDIO_LENGTH - 3] + "..."
return stdio

def __str__(self) -> str:
if self.returncode and self.returncode < 0:
try:
base = f"Command {self.cmd!r} died with {signal.Signals(-self.returncode)!r}."
except ValueError:
base = f"Command {self.cmd!r} died with unknown signal {-self.returncode}."
else:
base = f"Command {self.cmd!r} returned non-zero exit status {self.returncode}."
return f"{base}\nstdout: {self._truncate_stdio(self.stdout)}\nstderr: {self._truncate_stdio(self.stderr)}"


class CalledProcessTimeoutError(CalledProcessError):
def __init__(
self,
timeout: float,
returncode: int,
cmd: Union[str, List[str]],
output: str,
stderr: str,
):
super().__init__(returncode, cmd, output, stderr)
self.timeout = timeout

def __str__(self) -> str:
return f"Timed out after {self.timeout} seconds\n" + super().__str__()


class ProgramMissingException(Exception):
def __init__(self, program: str):
super().__init__(f"The program {program!r} is missing! Please install it")


class APIError(Exception):
def __init__(self, message: str, full_data: dict = None):
self.message = message
self.full_data = full_data

def __str__(self) -> str:
return self.message


class ThreadStopTimeoutError(Exception):
pass


class SystemProfilerStartFailure(Exception):
pass


class NoProfilersEnabledError(Exception):
pass


class NoRwExecDirectoryFoundError(Exception):
pass
Copy link
Contributor

@roi-granulate roi-granulate Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll comment here because there's no changes in this file in the other PR.
note two things:

  1. iiuc, we don't need all the exceptions here (we won't utilize PerfNoSupportedEvent for example, or am I wrong?)
  2. we have exceptions.py in granulate-utils here, we can copy those exceptions to there. of course - this should be taken care of in a different PR (G-UTILS-GPROFILER REWORK (2): Rework complex files #261 or a new one).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
g-utils-gprofiler-rework PRs related to the G-UTILS-GPROFILER saga
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants