/* Copyright (c) Microsoft Corporation All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. */ using System; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Data.Linq; using System.Data.Linq.Mapping; using System.Diagnostics; using System.Threading; using System.Xml; using System.Xml.Serialization; using Microsoft.Research.Dryad; namespace linqtodryadjm_managed { internal class DebugHelper { private static bool brokeInDebugger = false; private static bool loggingInitialized = false; private static object syncRoot = new object(); public static void WaitForDebugger() { if (!brokeInDebugger) { Console.Out.WriteLine("Waiting for debugger..."); while (!Debugger.IsAttached) { Thread.Sleep(1000); } Debugger.Break(); brokeInDebugger = true; } } public static void DebugBreakOnFileExisting(string breakFileName) { if (File.Exists(breakFileName)) { WaitForDebugger(); } } public static void SetLogType() { DrLogging.SetLoggingLevel((DrLogType)DryadLogger.TraceLevel); } public static void InitializeLogging(DateTime startTime) { if (!loggingInitialized) { lock (syncRoot) { if (!loggingInitialized) { // Initialize text-based tracing string traceFile = Path.Combine(Directory.GetCurrentDirectory(), "GraphManagerTrace.txt"); DryadLogger.Start(traceFile); // Initialize Graph Manager's internal logging DrLogging.Initialize(); DebugHelper.SetLogType(); // Report start time to Artemis - must come after // DrLogging is initialized so stdout is redirected DrArtemisLegacyReporter.ReportStart((ulong) startTime.Ticks); loggingInitialized = true; } } } } public static void StopLogging(int retCode) { if (loggingInitialized) { lock (syncRoot) { if (loggingInitialized) { // Report stop time to Artemis DrArtemisLegacyReporter.ReportStop(unchecked((uint)retCode)); // Shutdown Graph Manager's internal logging DrLogging.ShutDown(unchecked((uint)retCode)); // Shutdown text-based tracing DryadLogger.Stop(); loggingInitialized = false; } } } } } public class LinqToDryadJM { internal void FinalizeExecution(Query query, DrGraph graph) { SortedDictionary queryPlan = query.queryPlan; foreach (KeyValuePair kvp in query.queryPlan) { /* used to do CSStream expiration time stuff here */ } } internal bool ConsumeSingleArgument(string arg, ref string[] args) { List temp = new List(); bool found = false; for (int index=0; index internalArgs = new List(); // // add the XmlExecHost args to the internal app arguments // foreach (string xmlExecHostArg in query.xmlExecHostArgs) { if (xmlExecHostArg == "--break") { DebugHelper.WaitForDebugger(); } else { internalArgs.Add(xmlExecHostArg); } } // // combine internal arguments with any additional arguments received on the command line // don't include argv[0] and argv[1] (program name and query XML file name) // int internalArgc = (int)internalArgs.Count; int externalArgc = args.Length - 2; // don't include argv[0] and argv[1] int combinedArgc = internalArgc + externalArgc; string[] combinedArgv = new string[combinedArgc]; string msg = ""; // internal arguments first for (int i=0; i