使用する変更されたコードをデバッグしようとするとunsafe
、自分のコードが astrics で正しいかどうかわからないエラーが生成されます (したがって、それらを正しく配置しているかどうかを確認してください) 。 Windowsアプリ
とは対照的に、安全でないオプションを使用するオプションをチェック/チェック解除する適切な場所はありません。
そして、それに関する情報を得ることができる限り、Web.Configを「手動で」処理する必要があります
だから私はそれをやっていて、にコードを追加しましたWeb.Config
.2つのバージョンのユーザーが、コードを構成セクション内または同じ範囲内に配置することを提案していますdebug=true
...
だから私はそれを両方に入れました(同時にではありませんが、両方を試しました(:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.codedom>
<compilers>
<compiler language="C#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</compilers>
</system.codedom>
<connectionStrings>....my secret connection here...
then rest of configs..
.....
struct IO_COUNTERS
{
public ulong ReadOperationCount;
public ulong WriteOperationCount;
public ulong OtherOperationCount;
public ulong ReadTransferCount;
public ulong WriteTransferCount;
public ulong OtherTransferCount;
}
[DllImport("kernel32.dll")]
unsafe static extern bool GetProcessIoCounters(IntPtr* ProcessHandle, out IO_COUNTERS* IoCounters);
private struct PROCESS_MEMORY_COUNTERS
{
public uint cb;
public uint PageFaultCount;
public uint PeakWorkingSetSize;
public uint WorkingSetSize;
public uint QuotaPeakPagedPoolUsage;
public uint QuotaPagedPoolUsage;
public uint QuotaPeakNonPagedPoolUsage;
public uint QuotaNonPagedPoolUsage;
public uint PagefileUsage;
public uint PeakPagefileUsage;
}
[StructLayout(LayoutKind.Sequential, Size = 40)]
[DllImport("psapi.dll", SetLastError = true)]
unsafe static extern bool GetProcessMemoryInfo(IntPtr* hProcess, out PROCESS_MEMORY_COUNTERS* Memcounters, int size);
これは、ネイティブ pinvok コードを実装する calss です。
(最初は、ネイティブ vs マネージド / .net アプローチをテストしようとしていました)しかし、pinvoke vs .net を試す前に、pinvoke *unsafe vs .net間のパフォーマンスをチェックするために海峡に潜りました
したがって、この部分はまだ「セーフモード」にあり、アトリクスでも処理する必要がありますか?
static class Nat
{
public static class IO
{
public static Dictionary<string, ulong> GetALLIO(Process procToRtrivIO)
{
IO_COUNTERS counters;
Dictionary<string, ulong> retCountIoDict = new Dictionary<string, ulong>();
GetProcessIoCounters(System.Diagnostics.Process.GetCurrentProcess().Handle, out counters);
retCountIoDict.Add("ReadOperationCount", counters.ReadOperationCount);
retCountIoDict.Add("WriteOperationCount", counters.WriteOperationCount);
retCountIoDict.Add("OtherOperationCount", counters.OtherOperationCount);
retCountIoDict.Add("ReadTransferCount", counters.ReadTransferCount);
retCountIoDict.Add("WriteTransferCount", counters.WriteTransferCount);
retCountIoDict.Add("OtherTransferCount", counters.OtherTransferCount);
return retCountIoDict;
//return "This process has read " + ((counters.ReadTransferCount/1024)/1024).ToString("N0") +
// " Mb of data.";
}
}
public static class Mem
{
public static Dictionary<string, uint> GetAllMem(Process procToRtrivMem)
{
PROCESS_MEMORY_COUNTERS MemCounters;
Dictionary<string, uint> retCountMemDict = new Dictionary<string, uint>();
GetProcessMemoryInfo(System.Diagnostics.Process.GetCurrentProcess().Handle, out MemCounters, Marshal.SizeOf(typeof(PROCESS_MEMORY_COUNTERS))); //MemCounters.cb);
retCountMemDict.Add("cb", MemCounters.cb);
retCountMemDict.Add("PageFaultCount", MemCounters.PageFaultCount);
retCountMemDict.Add("PeakWorkingSetSize", MemCounters.PeakWorkingSetSize);
retCountMemDict.Add("WorkingSetSize", MemCounters.WorkingSetSize);
retCountMemDict.Add("QuotaPeakPagedPoolUsage", MemCounters.QuotaPeakPagedPoolUsage);
retCountMemDict.Add("QuotaPagedPoolUsage", MemCounters.QuotaPagedPoolUsage);
retCountMemDict.Add("QuotaPeakNonPagedPoolUsage", MemCounters.QuotaPeakNonPagedPoolUsage);
retCountMemDict.Add("QuotaNonPagedPoolUsage", MemCounters.QuotaNonPagedPoolUsage);
retCountMemDict.Add("PagefileUsage", MemCounters.PagefileUsage);
retCountMemDict.Add("PeakPagefileUsage", MemCounters.PeakPagefileUsage);
return retCountMemDict;
//return "This process has read " + ((counters.ReadTransferCount/1024)/1024).ToString("N0") +
// " Mb of data.";
}
}
}
申し訳ありませんが、更新は次の部分を見逃していました : コンパイラ オプション
compilerOptions="/unsafe" // <<-- you can add this to the compiler config line.
まだです。私の問題は始まったばかりで、エラーは1つだけではありません:
Unsafe code may only appear if compiling with /unsafe
しかし、いたるところにエラーがあります!
たとえば最初のもの:
public static Dictionary<string, ulong> GetALLIO(Process procToRtrivIO)
{
IO_COUNTERS counters;
Dictionary<string, ulong> retCountIoDict = new Dictionary<string, ulong>();
--->> GetProcessIoCounters(System.Diagnostics.Process.GetCurrentProcess().Handle, out counters);
retCountIoDict.Add("ReadOperationCount", counters.ReadOperationCount);
retCountIoDict.Add("WriteOperationCount", counters.WriteOperationCount);
エラーは GetProcesIoCounters() を呼び出しているその行のものです
エラー 3 引数 1: 'System.IntPtr' から 'System.IntPtr*' に変換できません g:\RobDevI5-Raid-0\Documents\Visual Studio 2010\WebSites\WebSite2\App_Code\CsExtensions.cs 416 42 g:.. .\WebSite2\
UPDAT - unsafe を適切に使用していることを確認できませんでしたが、機能しているように見えるコード
安全でない署名
[DllImport("psapi.dll", SetLastError = true)]
unsafe static extern bool GetProcessMemoryInfo(IntPtr* hProcess, out PROCESS_MEMORY_COUNTERS Memcounters, int size);
私の「安全でない」コード
public static class IO
{
public static unsafe Dictionary<string, ulong> GetALLIO(Process procToRtrivIO)
{
IO_COUNTERS counters;
Dictionary<string, ulong> retCountIoDict = new Dictionary<string, ulong>();
IntPtr* Hw = (IntPtr*)System.Diagnostics.Process.GetCurrentProcess().Handle;
GetProcessIoCounters(Hw, out counters);
retCountIoDict.Add("ReadOperationCount", counters.ReadOperationCount);
retCountIoDict.Add("WriteOperationCount", counters.WriteOperationCount);
retCountIoDict.Add("OtherOperationCount", counters.OtherOperationCount);
retCountIoDict.Add("ReadTransferCount", counters.ReadTransferCount);
retCountIoDict.Add("WriteTransferCount", counters.WriteTransferCount);
retCountIoDict.Add("OtherTransferCount", counters.OtherTransferCount);
return retCountIoDict;
//return "This process has read " + ((counters.ReadTransferCount/1024)/1024).ToString("N0") +
// " Mb of data.";
}
}