widget/ProcInfo.h
author Doug Thayer <dothayer@mozilla.com>
Fri, 01 Mar 2019 18:29:09 +0000
changeset 520116 8b3fe0426ffc1b3a2ad044ef6cdde6c4f736f8e2
parent 519477 3a00ca524ad127725835b3629f00cf2861f977cb
permissions -rw-r--r--
Bug 1442694 - Fix failures due to removing selected tab r=Gijs This adds test which reproduce the failure as well as the fix. Essentially, if we hit the edited case in SessionStore with `tab` equal to `tabbrowser.tabs[t]`, we remove the tab and then try to pin it, which obviously blows up. Note: the additional method in SessionStore.jsm was largely to get around complexity requirements inside restoreWindow. Cleaner solutions welcome. Differential Revision: https://phabricator.services.mozilla.com/D21383

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef __mozilla_ProcInfo_h
#define __mozilla_ProcInfo_h

#include <base/process.h>
#include <stdint.h>
#include "mozilla/dom/ipc/IdType.h"

namespace mozilla {

// Process types
enum class ProcType {
  // These must match the ones in ContentParent.h and E10SUtils.jsm
  Web,
  File,
  Extension,
  Privileged,
  WebLargeAllocation,
  // GPU process (only on Windows)
  Gpu,
  // RDD process (Windows and macOS)
  Rdd,
  // Socket process
  Socket,
  // Main process
  Browser,
  // Unknown type of process
  Unknown
};

struct ThreadInfo {
  // Thread Id.
  base::ProcessId tid = 0;
  // Thread name, if any.
  nsString name;
  // User time in ns.
  uint64_t cpuUser = 0;
  // System time in ns.
  uint64_t cpuKernel = 0;
};

struct ProcInfo {
  // Process Id
  base::ProcessId pid = 0;
  // Child Id as defined by Firefox when a child process is created.
  dom::ContentParentId childId;
  // Process type
  ProcType type;
  // Process filename (without the path name).
  nsString filename;
  // VMS in bytes.
  uint64_t virtualMemorySize = 0;
  // RSS in bytes.
  int64_t residentSetSize = 0;
  // User time in ns.
  uint64_t cpuUser = 0;
  // System time in ns.
  uint64_t cpuKernel = 0;
  // Threads owned by this process.
  nsTArray<ThreadInfo> threads;
};

typedef MozPromise<ProcInfo, nsresult, true> ProcInfoPromise;

/*
 * GetProcInfo() uses a background thread to perform system calls.
 *
 * Depending on the platform, this call can be quite expensive and the
 * promise may return after several ms.
 */
RefPtr<ProcInfoPromise> GetProcInfo(base::ProcessId pid, int32_t childId,
                                    const ProcType& type);

}  // namespace mozilla
#endif  // ProcInfo_h