mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-07 05:15:09 +00:00
58786e1ea7
This patch makes the following changes to the macros. - Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was mostly misused. - Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is universally available now anyway. - Combines the first two string literal arguments of PROFILER_LABEL and PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for them to be separate, and it forced a '::' in the label, which isn't always appropriate. Also, the meaning of the "name_space" argument was interpreted in an interesting variety of ways. - Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make it clearer they construct RAII objects rather than just being function calls. (I myself have screwed up the scoping because of this in the past.) - Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so the caller doesn't need to. This makes a *lot* more of the uses fit onto a single line. The patch also makes the following changes to the macro uses (beyond those required by the changes described above). - Fixes a bunch of labels that had gotten out of sync with the name of the class and/or function that encloses them. - Removes a useless PROFILER_LABEL use within a trivial scope in EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving any useful purpose. It also serves as extra evidence that the AUTO_ prefix is a good idea. - Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is done within them, instead of at their callsites, because that's a more standard way of doing things. --HG-- extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
76 lines
2.0 KiB
C++
76 lines
2.0 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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/. */
|
|
|
|
#include "FileUtilsWin.h"
|
|
|
|
#include <windows.h>
|
|
#include <psapi.h>
|
|
|
|
#include "mozilla/Unused.h"
|
|
#include "nsWindowsHelpers.h"
|
|
#include "GeckoProfiler.h"
|
|
|
|
namespace {
|
|
|
|
// Scoped type used by HandleToFilename
|
|
struct ScopedMappedViewTraits
|
|
{
|
|
typedef void* type;
|
|
static void* empty()
|
|
{
|
|
return nullptr;
|
|
}
|
|
static void release(void* aPtr)
|
|
{
|
|
if (aPtr) {
|
|
mozilla::Unused << UnmapViewOfFile(aPtr);
|
|
}
|
|
}
|
|
};
|
|
typedef mozilla::Scoped<ScopedMappedViewTraits> ScopedMappedView;
|
|
|
|
} // namespace
|
|
|
|
namespace mozilla {
|
|
|
|
bool
|
|
HandleToFilename(HANDLE aHandle, const LARGE_INTEGER& aOffset,
|
|
nsAString& aFilename)
|
|
{
|
|
AUTO_PROFILER_LABEL("HandletoFilename", NETWORK);
|
|
|
|
aFilename.Truncate();
|
|
// This implementation is nice because it uses fully documented APIs that
|
|
// are available on all Windows versions that we support.
|
|
nsAutoHandle fileMapping(CreateFileMapping(aHandle, nullptr, PAGE_READONLY,
|
|
0, 1, nullptr));
|
|
if (!fileMapping) {
|
|
return false;
|
|
}
|
|
ScopedMappedView view(MapViewOfFile(fileMapping, FILE_MAP_READ,
|
|
aOffset.HighPart, aOffset.LowPart, 1));
|
|
if (!view) {
|
|
return false;
|
|
}
|
|
nsAutoString mappedFilename;
|
|
DWORD len = 0;
|
|
SetLastError(ERROR_SUCCESS);
|
|
do {
|
|
mappedFilename.SetLength(mappedFilename.Length() + MAX_PATH);
|
|
len = GetMappedFileNameW(GetCurrentProcess(), view,
|
|
mappedFilename.get(),
|
|
mappedFilename.Length());
|
|
} while (!len && GetLastError() == ERROR_INSUFFICIENT_BUFFER);
|
|
if (!len) {
|
|
return false;
|
|
}
|
|
mappedFilename.Truncate(len);
|
|
return NtPathToDosPath(mappedFilename, aFilename);
|
|
}
|
|
|
|
} // namespace mozilla
|
|
|